From 1fbfcc95c1d0504ca4f28a418d9684d4ddf25aed Mon Sep 17 00:00:00 2001 From: chrisduma-ledger Date: Fri, 22 Nov 2024 15:02:18 +0200 Subject: [PATCH] feat: make sure accountId is there --- .../src/wallet-api/Exchange/server.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libs/ledger-live-common/src/wallet-api/Exchange/server.ts b/libs/ledger-live-common/src/wallet-api/Exchange/server.ts index 74f6ec5aa73d..06e3b4d16f9e 100644 --- a/libs/ledger-live-common/src/wallet-api/Exchange/server.ts +++ b/libs/ledger-live-common/src/wallet-api/Exchange/server.ts @@ -72,7 +72,7 @@ type ExchangeStartParamsUiRequest = | { exchangeType: "SELL"; provider: string; - exchange: Partial; + exchange: Partial | undefined; } | { exchangeType: "SWAP"; @@ -371,13 +371,20 @@ function extractSellStartParam( throw new ExchangeError(createWrongSellParams(params)); } - const realFromAccountId = getAccountIdFromWalletAccountId(params.fromAccountId); + if (!params.fromAccountId) { + return { + exchangeType: params.exchangeType, + provider: params.provider, + } as ExchangeStartParamsUiRequest; + } + + const realFromAccountId = getAccountIdFromWalletAccountId(params?.fromAccountId); if (!realFromAccountId) { throw new ExchangeError(createAccounIdNotFound(params.fromAccountId)); } - const fromAccount = accounts.find(acc => acc.id === realFromAccountId); + const fromAccount = accounts?.find(acc => acc.id === realFromAccountId); if (!fromAccount) { throw new ServerError(createAccountNotFound(params.fromAccountId));