Skip to content

Commit 3973d46

Browse files
committed
Fix lint warnings in SwapDetailsCard
1 parent 6cd8d59 commit 3973d46

9 files changed

Lines changed: 72 additions & 27 deletions

eslint.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export default [
160160
'src/components/cards/StakingOptionCard.tsx',
161161
'src/components/cards/StakingReturnsCard.tsx',
162162
'src/components/cards/SupportCard.tsx',
163-
'src/components/cards/SwapDetailsCard.tsx',
163+
164164
'src/components/cards/TappableAccountCard.tsx',
165165
'src/components/cards/TappableCard.tsx',
166166
'src/components/cards/UnderlinedNumInputCard.tsx',
@@ -258,7 +258,7 @@ export default [
258258
'src/components/rows/EdgeRow.tsx',
259259

260260
'src/components/rows/PaymentMethodRow.tsx',
261-
'src/components/rows/SwapProviderRow.tsx',
261+
262262
'src/components/rows/TxCryptoAmountRow.tsx',
263263

264264
'src/components/scenes/ChangeMiningFeeScene.tsx',

src/actions/CategoriesActions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,9 @@ export const getTxActionDisplayInfo = (
382382
? lstrings.transaction_details_swap_to_subcat_1s
383383
: lstrings.transaction_details_swap_from_subcat_1s
384384
const walletName =
385-
account.currencyWallets[action.payoutWalletId]?.name ??
386-
displayName
385+
(action.payoutWalletId != null
386+
? account.currencyWallets[action.payoutWalletId]?.name
387+
: undefined) ?? displayName
387388
edgeCategory = {
388389
category: 'transfer',
389390
subcategory: sprintf(toFromStr, walletName)

src/components/cards/SwapDetailsCard.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const upgradeSwapData = (
5858
return swapData
5959
}
6060

61-
export function SwapDetailsCard(props: Props) {
61+
export const SwapDetailsCard: React.FC<Props> = props => {
6262
const { swapData, transaction, wallet } = props
6363
const theme = useTheme()
6464
const styles = getStyles(theme)
@@ -124,12 +124,12 @@ export function SwapDetailsCard(props: Props) {
124124
return
125125
}
126126

127-
if (error) showError(error)
127+
if (error != null) showError(error)
128128
}
129129
)
130130
})
131131

132-
const handleLink = async () => {
132+
const handleLink = async (): Promise<void> => {
133133
if (formattedOrderUri == null) return
134134

135135
// Replace {{TXID}} with actual transaction ID if present
@@ -140,9 +140,9 @@ export function SwapDetailsCard(props: Props) {
140140
if (available) await SafariView.show({ url: formattedOrderUri })
141141
else await Linking.openURL(formattedOrderUri)
142142
})
143-
.catch(error => {
143+
.catch((error: unknown) => {
144144
showError(error)
145-
Linking.openURL(formattedOrderUri).catch(err => {
145+
Linking.openURL(formattedOrderUri).catch((err: unknown) => {
146146
showError(err)
147147
})
148148
})
@@ -192,7 +192,7 @@ export function SwapDetailsCard(props: Props) {
192192
? walletDefaultDenom.symbol
193193
: transaction.currencyCode
194194

195-
const createExchangeDataString = (newline: string = '\n') => {
195+
const createExchangeDataString = (newline: string = '\n'): string => {
196196
const uniqueIdentifier = memos
197197
.map(
198198
(memo, index) =>

src/components/rows/SwapProviderRow.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ export const SwapProviderRow: React.FC<Props> = (props: Props) => {
1818
const { quote } = props
1919
const { request, toNativeAmount, fromNativeAmount } = quote
2020
const { quoteFor } = request
21-
const { fromWallet, fromTokenId, toWallet, toTokenId } = request
21+
const { fromWallet, fromTokenId, toTokenId } = request
22+
// A wallet-to-wallet swap quote always carries a destination wallet; only a
23+
// swap-to-address request (its own flow) omits it.
24+
const toWallet = request.toWallet
25+
if (toWallet == null) {
26+
throw new Error('Swap quote is missing a destination wallet')
27+
}
2228
const theme = useTheme()
2329
const styles = getStyles(theme)
2430

src/components/scenes/SwapConfirmationScene.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ export const SwapConfirmationScene: React.FC<Props> = (props: Props) => {
127127
const { quoteFor } = request
128128

129129
const priceImpact = React.useMemo(() => {
130-
const { fromWallet, fromTokenId, toWallet, toTokenId } = request
130+
const { fromWallet, fromTokenId, toTokenId } = request
131+
const toWallet = request.toWallet
132+
if (toWallet == null) {
133+
throw new Error('Swap quote is missing a destination wallet')
134+
}
131135

132136
const fromExchangeDenom = getExchangeDenom(
133137
fromWallet.currencyConfig,
@@ -282,7 +286,11 @@ export const SwapConfirmationScene: React.FC<Props> = (props: Props) => {
282286
request
283287
} = selectedQuote
284288
// Both fromCurrencyCode and toCurrencyCode will exist, since we set them:
285-
const { toWallet, toTokenId, fromWallet, fromTokenId } = request
289+
const { toTokenId, fromWallet, fromTokenId } = request
290+
const toWallet = request.toWallet
291+
if (toWallet == null) {
292+
throw new Error('Swap quote is missing a destination wallet')
293+
}
286294

287295
try {
288296
dispatch(logEvent('Exchange_Shift_Start'))
@@ -556,7 +564,11 @@ const getSwapInfo = (
556564
// Currency conversion tools:
557565
// Both fromCurrencyCode and toCurrencyCode will exist, since we set them:
558566
const { request } = quote
559-
const { fromWallet, toWallet, fromTokenId, toTokenId } = request
567+
const { fromWallet, fromTokenId, toTokenId } = request
568+
const toWallet = request.toWallet
569+
if (toWallet == null) {
570+
throw new Error('Swap quote is missing a destination wallet')
571+
}
560572

561573
// Format from amount:
562574
const fromDisplayDenomination = selectDisplayDenom(

src/components/scenes/SwapCreateScene.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ export const SwapCreateScene: React.FC<Props> = props => {
228228
}
229229

230230
const getQuote = (swapRequest: EdgeSwapRequest): void => {
231+
// This scene only builds wallet-to-wallet swap requests, which always carry
232+
// a destination wallet (swap-to-address has its own flow).
233+
const toWallet = swapRequest.toWallet
234+
if (toWallet == null) {
235+
throw new Error('Swap request is missing a destination wallet')
236+
}
231237
if (exchangeInfo != null) {
232238
const disableSrc = checkDisableAsset(
233239
exchangeInfo.swap.disableAssets.source,
@@ -247,15 +253,15 @@ export const SwapCreateScene: React.FC<Props> = props => {
247253

248254
const disableDest = checkDisableAsset(
249255
exchangeInfo.swap.disableAssets.destination,
250-
swapRequest.toWallet.id,
256+
toWallet.id,
251257
toTokenId
252258
)
253259
if (disableDest) {
254260
showToast(
255261
sprintf(
256262
lstrings.swap_token_no_enabled_exchanges_2s,
257263
toCurrencyCode,
258-
swapRequest.toWallet.currencyInfo.displayName
264+
toWallet.currencyInfo.displayName
259265
)
260266
)
261267
return

src/components/scenes/SwapProcessingScene.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,19 @@ export const SwapProcessingScene: React.FC<Props> = (props: Props) => {
4949
swapRequest.fromTokenId
5050
)
5151
const toDenomination = useDisplayDenom(
52-
swapRequest.toWallet.currencyConfig,
52+
// Wallet-to-wallet swaps always have a destination wallet here; fall back to
53+
// the source config only so this hook stays unconditional.
54+
(swapRequest.toWallet ?? swapRequest.fromWallet).currencyConfig,
5355
swapRequest.toTokenId
5456
)
5557

58+
// This scene only processes wallet-to-wallet swap requests, which always
59+
// carry a destination wallet (swap-to-address has its own flow).
60+
const toWallet = swapRequest.toWallet
61+
if (toWallet == null) {
62+
throw new Error('Swap request is missing a destination wallet')
63+
}
64+
5665
const doWork = async (isCancelled: () => boolean): Promise<void> => {
5766
const quotes = await account.fetchSwapQuotes(
5867
swapRequest,
@@ -70,7 +79,7 @@ export const SwapProcessingScene: React.FC<Props> = (props: Props) => {
7079
const fromWallet = swapRequest.fromWallet
7180
const fromAddresses = await fromWallet.getAddresses({ tokenId: null })
7281
const fromAddress = fromAddresses[0]?.publicAddress
73-
const targetPluginId = swapRequest.toWallet.currencyInfo.pluginId
82+
const targetPluginId = toWallet.currencyInfo.pluginId
7483

7584
let matchingWalletId: string | undefined
7685
for (const walletId of Object.keys(account.currencyWallets)) {
@@ -89,8 +98,8 @@ export const SwapProcessingScene: React.FC<Props> = (props: Props) => {
8998
}
9099
}
91100

92-
let finalToWalletId: string = swapRequest.toWallet.id
93-
let finalToWallet = swapRequest.toWallet
101+
let finalToWalletId: string
102+
let finalToWallet: typeof toWallet
94103
let isWalletCreated = false
95104
if (matchingWalletId == null) {
96105
// If not found, split from the source chain wallet to the destination
@@ -165,7 +174,7 @@ export const SwapProcessingScene: React.FC<Props> = (props: Props) => {
165174
params: {
166175
fromWalletId: swapRequest.fromWallet.id,
167176
fromTokenId: swapRequest.fromTokenId,
168-
toWalletId: swapRequest.toWallet.id,
177+
toWalletId: toWallet.id,
169178
toTokenId: swapRequest.toTokenId
170179
}
171180
})
@@ -189,7 +198,7 @@ export const SwapProcessingScene: React.FC<Props> = (props: Props) => {
189198
params: {
190199
fromWalletId: swapRequest.fromWallet.id,
191200
fromTokenId: swapRequest.fromTokenId,
192-
toWalletId: swapRequest.toWallet.id,
201+
toWalletId: toWallet.id,
193202
toTokenId: swapRequest.toTokenId,
194203
errorDisplayInfo
195204
}
@@ -313,7 +322,9 @@ function processSwapQuoteError({
313322
swapRequest.fromTokenId
314323
)
315324
const toCurrencyCode = getCurrencyCode(
316-
swapRequest.toWallet,
325+
// Wallet-to-wallet swaps always have a destination wallet here; the
326+
// fallback only keeps the type honest for swap-to-address requests.
327+
swapRequest.toWallet ?? swapRequest.fromWallet,
317328
swapRequest.toTokenId
318329
)
319330

@@ -362,10 +373,11 @@ function trackSwapError(error: unknown, swapRequest: EdgeSwapRequest): void {
362373
swapRequest.fromTokenId
363374
),
364375
swapToCurrency: getCurrencyCode(
365-
swapRequest.toWallet,
376+
swapRequest.toWallet ?? swapRequest.fromWallet,
366377
swapRequest.toTokenId
367378
),
368-
swapToWalletKind: swapRequest.toWallet.currencyInfo.pluginId,
379+
swapToWalletKind: (swapRequest.toWallet ?? swapRequest.fromWallet)
380+
.currencyInfo.pluginId,
369381
swapDirectionType: swapRequest.quoteFor
370382
})
371383
// Unsearchable context data:

src/components/scenes/TransactionDetailsScene.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,9 @@ const convertActionToSwapData = (
771771
payoutCurrencyCode,
772772
payoutTokenId: toAsset.tokenId,
773773
payoutNativeAmount: action.toAsset.nativeAmount ?? '0',
774-
payoutWalletId,
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 ?? '',
775777
refundAddress
776778
}
777779
return out

src/components/themed/ExchangeQuoteComponent.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ interface Props {
2727
export const ExchangeQuote: React.FC<Props> = props => {
2828
const { fromTo, priceImpact, quote, showFeeWarning } = props
2929
const { request, fromNativeAmount, toNativeAmount, networkFee } = quote
30-
const { fromWallet, fromTokenId, toWallet, toTokenId } = request
30+
const { fromWallet, fromTokenId, toTokenId } = request
31+
// A wallet-to-wallet swap quote always carries a destination wallet; only a
32+
// swap-to-address request (its own flow) omits it.
33+
const toWallet = request.toWallet
34+
if (toWallet == null) {
35+
throw new Error('Swap quote is missing a destination wallet')
36+
}
3137

3238
const theme = useTheme()
3339
const styles = getStyles(theme)

0 commit comments

Comments
 (0)