From 29961485e7412ef1860e9f29b7b4181d0fb04996 Mon Sep 17 00:00:00 2001 From: jjBlockchain Date: Tue, 27 Jun 2023 03:10:19 -0500 Subject: [PATCH] fix(dex): make sure users eth is fetched --- .../src/data/components/dex/sagas.ts | 11 ++++------- .../src/network/api/dex/index.ts | 4 ++-- .../api/dex/requests/getDexUserEligibility.ts | 14 ++++++-------- .../src/network/api/dex/schemas.ts | 10 ++++++++-- .../blockchain-wallet-v4/src/network/api/index.ts | 1 + 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/packages/blockchain-wallet-v4-frontend/src/data/components/dex/sagas.ts b/packages/blockchain-wallet-v4-frontend/src/data/components/dex/sagas.ts index a9ff0bf10c6..e1652841354 100644 --- a/packages/blockchain-wallet-v4-frontend/src/data/components/dex/sagas.ts +++ b/packages/blockchain-wallet-v4-frontend/src/data/components/dex/sagas.ts @@ -11,7 +11,6 @@ import { actions, model, selectors } from 'data' import { Analytics } from 'data/types' import { promptForSecondPassword } from 'services/sagas' -import quoteMock from './mocks/quote.json' import * as S from './selectors' import { actions as A } from './slice' import type { DexSwapForm } from './types' @@ -41,15 +40,13 @@ export default ({ api }: { api: APIType }) => { }) ) - const walletAddress = nonCustodialCoinAccounts[token]?.[0].address - if (!walletAddress) { - yield* put(A.fetchUserEligibilityFailure('No user wallet address')) + if (!nonCustodialCoinAccounts[token]?.length) { + yield put(actions.core.data.eth.fetchData()) + yield put(actions.core.data.eth.fetchErc20Data()) } yield put(A.fetchUserEligibilityLoading()) - const userEligibility = yield* call(api.getDexUserEligibility, { - walletAddress: `${walletAddress}` - }) + const userEligibility = yield* call(api.getDexUserEligibility) yield* put(A.fetchUserEligibilitySuccess(userEligibility)) } catch (e) { yield put( diff --git a/packages/blockchain-wallet-v4/src/network/api/dex/index.ts b/packages/blockchain-wallet-v4/src/network/api/dex/index.ts index cfd32c3ee02..b1a330482b5 100755 --- a/packages/blockchain-wallet-v4/src/network/api/dex/index.ts +++ b/packages/blockchain-wallet-v4/src/network/api/dex/index.ts @@ -10,14 +10,14 @@ import { export type { DexChain, DexSwapQuote, DexToken, DexTokenWithBalance } from './types' -export default ({ apiUrl, authorizedGet, authorizedPost, get, post }) => { +export default ({ apiUrl, authorizedGet, authorizedPost, get, nabuUrl, post }) => { return { buildDexTx: buildDexTx({ apiUrl, authorizedPost }), getDexChainTokens: getDexChainTokens({ apiUrl, get }), // can't get this to work getDexChains: getDexChains({ apiUrl, get }), getDexSwapQuote: getDexSwapQuote({ apiUrl, authorizedPost }), getDexTokenAllowance: getDexTokenAllowance({ apiUrl, post }), - getDexUserEligibility: getDexUserEligibility({ apiUrl, authorizedGet }), + getDexUserEligibility: getDexUserEligibility({ authorizedGet, nabuUrl }), searchDexTokens: searchDexTokens({ apiUrl, get }) } } diff --git a/packages/blockchain-wallet-v4/src/network/api/dex/requests/getDexUserEligibility.ts b/packages/blockchain-wallet-v4/src/network/api/dex/requests/getDexUserEligibility.ts index 339ca8ffc7a..f33c77d6a50 100644 --- a/packages/blockchain-wallet-v4/src/network/api/dex/requests/getDexUserEligibility.ts +++ b/packages/blockchain-wallet-v4/src/network/api/dex/requests/getDexUserEligibility.ts @@ -1,21 +1,19 @@ import type { RequestConfig } from '../../http' -import { DEX_NABU_GATEWAY_PREFIX } from '../constants' import { DexUserEligibilitySchema } from '../schemas' export const getDexUserEligibility = ({ - apiUrl, - authorizedGet + authorizedGet, + nabuUrl }: { - apiUrl: string authorizedGet: (config: RequestConfig) => Promise + nabuUrl: string }) => - ({ walletAddress }: { walletAddress: string }): Promise => + (): Promise => authorizedGet({ contentType: 'application/json', - endPoint: `${DEX_NABU_GATEWAY_PREFIX}/eligible`, - params: { product: 'DEX', walletAddress }, - url: apiUrl + endPoint: `/products`, + url: nabuUrl }).then((data) => { try { return DexUserEligibilitySchema.parse(data) diff --git a/packages/blockchain-wallet-v4/src/network/api/dex/schemas.ts b/packages/blockchain-wallet-v4/src/network/api/dex/schemas.ts index 9f95c2f53a3..bace139ede7 100644 --- a/packages/blockchain-wallet-v4/src/network/api/dex/schemas.ts +++ b/packages/blockchain-wallet-v4/src/network/api/dex/schemas.ts @@ -124,11 +124,17 @@ export const DexSwapQuoteSchema: z.ZodSchema = z + .object({ + enabled: z.boolean() + }) + .transform(({ enabled }) => enabled) + export const DexUserEligibilitySchema: z.ZodSchema = z .object({ - eligible: z.boolean() + dex: DexEnabledSchema }) - .transform(({ eligible }) => eligible) + .transform(({ dex }) => dex) export const DexTokenAllowanceSchema: z.ZodSchema = z.object({ diff --git a/packages/blockchain-wallet-v4/src/network/api/index.ts b/packages/blockchain-wallet-v4/src/network/api/index.ts index 8a30bb7f1f2..cbbf52a6626 100755 --- a/packages/blockchain-wallet-v4/src/network/api/index.ts +++ b/packages/blockchain-wallet-v4/src/network/api/index.ts @@ -65,6 +65,7 @@ const api = ({ apiKey, getAuthCredentials, networks, options, reauthenticate }: apiUrl, authorizedGet: authorizedHttp.get, authorizedPost: authorizedHttp.post, + nabuUrl, ...http }), ...earn({