Skip to content

Commit 25ae577

Browse files
committed
Handle optional swap destination wallet and payout wallet id
edge-core-js swap-to-address makes EdgeSwapRequest.toWallet optional (an address-only toAddressInfo destination replaces it) and makes EdgeTxActionSwap.payoutWalletId and EdgeTxSwap.payoutWalletId optional. Sweep the consumers: wallet-to-wallet swap scenes throw if their destination wallet is missing, savedAction and swap-details readers tolerate a missing payout wallet.
1 parent 3973d46 commit 25ae577

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

src/components/cards/SwapDetailsCard.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,14 @@ export const SwapDetailsCard: React.FC<Props> = props => {
7272
: selectDisplayDenom(state, wallet.currencyConfig, tokenId)
7373
)
7474

75-
// The wallet may have been deleted:
75+
// A swap-to-address payout has no wallet, and the wallet may also have
76+
// been deleted:
7677
const account = useSelector(state => state.core.account)
7778
const currencyWallets = useWatch(account, 'currencyWallets')
78-
const destinationWallet = currencyWallets[swapData.payoutWalletId]
79+
const destinationWallet =
80+
swapData.payoutWalletId == null
81+
? undefined
82+
: currencyWallets[swapData.payoutWalletId]
7983
const destinationWalletName =
8084
destinationWallet == null ? '' : getWalletName(destinationWallet)
8185

@@ -180,7 +184,7 @@ export const SwapDetailsCard: React.FC<Props> = props => {
180184
destinationDenomination.multiplier
181185
)(swapData.payoutNativeAmount)
182186
const destinationAssetName =
183-
payoutTokenId == null
187+
payoutTokenId == null || destinationWallet == null
184188
? payoutCurrencyCode
185189
: `${payoutCurrencyCode} (${
186190
getExchangeDenom(destinationWallet.currencyConfig, null).name

src/components/scenes/TransactionDetailsScene.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,9 +771,8 @@ const convertActionToSwapData = (
771771
payoutCurrencyCode,
772772
payoutTokenId: toAsset.tokenId,
773773
payoutNativeAmount: action.toAsset.nativeAmount ?? '0',
774-
// A swap-to-address (private send) has no payout wallet; EdgeTxSwap still
775-
// types this as required, so fall back to an empty id.
776-
payoutWalletId: payoutWalletId ?? '',
774+
// A swap-to-address (private send) has no payout wallet:
775+
payoutWalletId,
777776
refundAddress
778777
}
779778
return out

0 commit comments

Comments
 (0)