Skip to content

Commit 7845ae4

Browse files
committed
Make SwapDetailsCard sourceWallet optional
In preparation for swapData to be available on receive transactions, we may not have the source wallet to pass to this component.
1 parent 27dfca9 commit 7845ae4

File tree

2 files changed

+46
-30
lines changed

2 files changed

+46
-30
lines changed

src/components/cards/SwapDetailsCard.tsx

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import SafariView from 'react-native-safari-view'
77
import { sprintf } from 'sprintf-js'
88

99
import { useHandler } from '../../hooks/useHandler'
10-
import { useWalletName } from '../../hooks/useWalletName'
1110
import { useWatch } from '../../hooks/useWatch'
1211
import { lstrings } from '../../locales/strings'
1312
import {
@@ -27,22 +26,15 @@ import { EdgeCard } from './EdgeCard'
2726
interface Props {
2827
swapData: EdgeTxSwap
2928
transaction: EdgeTransaction
30-
wallet: EdgeCurrencyWallet
29+
sourceWallet?: EdgeCurrencyWallet
3130
}
3231

3332
const TXID_PLACEHOLDER = '{{TXID}}'
3433

3534
export function SwapDetailsCard(props: Props) {
36-
const { swapData, transaction, wallet } = props
35+
const { swapData, transaction, sourceWallet } = props
3736

3837
const { memos = [], spendTargets = [], tokenId } = transaction
39-
const { currencyInfo } = wallet
40-
const walletName = useWalletName(wallet)
41-
const walletDefaultDenom = useSelector(state =>
42-
currencyInfo.currencyCode === transaction.currencyCode
43-
? getExchangeDenom(wallet.currencyConfig, tokenId)
44-
: selectDisplayDenom(state, wallet.currencyConfig, tokenId)
45-
)
4638

4739
const {
4840
isEstimate,
@@ -139,25 +131,37 @@ export function SwapDetailsCard(props: Props) {
139131
payoutCurrencyCode
140132
)
141133
)
142-
if (destinationDenomination == null) return null
143134

144135
const sourceNativeAmount = sub(
145136
abs(transaction.nativeAmount),
146137
transaction.networkFee
147138
)
148-
const sourceAmount = convertNativeToDisplay(walletDefaultDenom.multiplier)(
149-
sourceNativeAmount
139+
const sourceWalletDenom = useSelector(state =>
140+
sourceWallet?.currencyInfo.currencyCode === transaction.currencyCode
141+
? getExchangeDenom(sourceWallet.currencyConfig, tokenId)
142+
: sourceWallet != null
143+
? selectDisplayDenom(state, sourceWallet.currencyConfig, tokenId)
144+
: undefined
150145
)
146+
const sourceAmount =
147+
sourceWalletDenom == null
148+
? undefined
149+
: convertNativeToDisplay(sourceWalletDenom.multiplier)(sourceNativeAmount)
151150
const sourceAssetName =
152-
tokenId == null
153-
? walletDefaultDenom.name
154-
: `${walletDefaultDenom.name} (${
155-
getExchangeDenom(wallet.currencyConfig, null).name
151+
sourceWalletDenom == null || sourceWallet == null
152+
? undefined
153+
: tokenId == null
154+
? sourceWalletDenom.name
155+
: `${sourceWalletDenom.name} (${
156+
getExchangeDenom(sourceWallet.currencyConfig, null).name
156157
})`
157158

158-
const destinationAmount = convertNativeToDisplay(
159-
destinationDenomination.multiplier
160-
)(swapData.payoutNativeAmount)
159+
const destinationAmount =
160+
destinationDenomination == null
161+
? undefined
162+
: convertNativeToDisplay(destinationDenomination.multiplier)(
163+
swapData.payoutNativeAmount
164+
)
161165
const destinationAssetName =
162166
payoutCurrencyCode ===
163167
getExchangeDenom(destinationWallet.currencyConfig, null).name
@@ -206,14 +210,22 @@ export function SwapDetailsCard(props: Props) {
206210
},
207211
{
208212
rows: [
209-
{
210-
title: lstrings.transaction_details_exchange_source_wallet,
211-
body: walletName
212-
},
213-
{
214-
title: lstrings.string_send_amount,
215-
body: `${sourceAmount} ${sourceAssetName}`
216-
}
213+
...(sourceWallet?.name == null
214+
? []
215+
: [
216+
{
217+
title: lstrings.transaction_details_exchange_source_wallet,
218+
body: sourceWallet.name
219+
}
220+
]),
221+
...(sourceAmount == null || sourceAssetName == null
222+
? []
223+
: [
224+
{
225+
title: lstrings.string_send_amount,
226+
body: `${sourceAmount} ${sourceAssetName}`
227+
}
228+
])
217229
]
218230
},
219231
{
@@ -260,6 +272,10 @@ export function SwapDetailsCard(props: Props) {
260272
]
261273
}
262274

275+
if (destinationAmount == null) {
276+
return null
277+
}
278+
263279
return (
264280
<EdgeCard sections>
265281
<EdgeRow
@@ -268,7 +284,7 @@ export function SwapDetailsCard(props: Props) {
268284
onPress={handleExchangeDetails}
269285
>
270286
<EdgeText>
271-
{`${sourceAmount} ${sourceAssetName}` +
287+
{(sourceAmount == null ? '' : `${sourceAmount} ${sourceAssetName}`) +
272288
' → ' +
273289
`${destinationAmount} ${destinationAssetName}`}
274290
</EdgeText>

src/components/scenes/TransactionDetailsScene.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ const TransactionDetailsComponent = (props: Props) => {
546546
<SwapDetailsCard
547547
swapData={swapData}
548548
transaction={transaction}
549-
wallet={wallet}
549+
sourceWallet={wallet}
550550
/>
551551
)}
552552
</EdgeAnim>

0 commit comments

Comments
 (0)