@reown/appkit-core-react-native 0.0.0-feat-multi-social-20250710162403 → 0.0.0-feat-multi-social-20250714194032
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/controllers/ConnectionsController.js +3 -1
- package/lib/commonjs/controllers/ConnectionsController.js.map +1 -1
- package/lib/commonjs/controllers/RouterController.js +1 -22
- package/lib/commonjs/controllers/RouterController.js.map +1 -1
- package/lib/commonjs/controllers/SendController.js +4 -8
- package/lib/commonjs/controllers/SendController.js.map +1 -1
- package/lib/commonjs/controllers/SwapController.js +44 -47
- package/lib/commonjs/controllers/SwapController.js.map +1 -1
- package/lib/commonjs/utils/SwapApiUtil.js +1 -1
- package/lib/commonjs/utils/SwapApiUtil.js.map +1 -1
- package/lib/module/controllers/ConnectionsController.js +3 -1
- package/lib/module/controllers/ConnectionsController.js.map +1 -1
- package/lib/module/controllers/RouterController.js +1 -22
- package/lib/module/controllers/RouterController.js.map +1 -1
- package/lib/module/controllers/SendController.js +4 -8
- package/lib/module/controllers/SendController.js.map +1 -1
- package/lib/module/controllers/SwapController.js +44 -47
- package/lib/module/controllers/SwapController.js.map +1 -1
- package/lib/module/utils/SwapApiUtil.js +1 -1
- package/lib/module/utils/SwapApiUtil.js.map +1 -1
- package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -1
- package/lib/typescript/controllers/RouterController.d.ts +2 -15
- package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
- package/lib/typescript/controllers/SendController.d.ts.map +1 -1
- package/lib/typescript/controllers/SwapController.d.ts +2 -4
- package/lib/typescript/controllers/SwapController.d.ts.map +1 -1
- package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/controllers/ConnectionsController.ts +6 -1
- package/src/controllers/RouterController.ts +2 -44
- package/src/controllers/SendController.ts +4 -8
- package/src/controllers/SwapController.ts +49 -57
- package/src/utils/SwapApiUtil.ts +12 -10
|
@@ -11,8 +11,7 @@ type TransactionParams = {
|
|
|
11
11
|
toAmount: string;
|
|
12
12
|
};
|
|
13
13
|
export interface SwapControllerState {
|
|
14
|
-
|
|
15
|
-
initialized: boolean;
|
|
14
|
+
loadingTokens: boolean;
|
|
16
15
|
loadingPrices: boolean;
|
|
17
16
|
loadingQuote?: boolean;
|
|
18
17
|
loadingApprovalTransaction?: boolean;
|
|
@@ -68,10 +67,9 @@ export declare const SwapController: {
|
|
|
68
67
|
fetchTokens(): Promise<void>;
|
|
69
68
|
getTokenList(): Promise<void>;
|
|
70
69
|
getMyTokensWithBalance(forceUpdate?: CaipAddress[]): Promise<void>;
|
|
71
|
-
getFilteredPopularTokens(): SwapTokenWithBalance[] | undefined;
|
|
70
|
+
getFilteredPopularTokens(balances?: SwapTokenWithBalance[]): SwapTokenWithBalance[] | undefined;
|
|
72
71
|
setSourceToken(sourceToken: SwapTokenWithBalance | undefined): void;
|
|
73
72
|
setSourceTokenAmount(amount: string): void;
|
|
74
|
-
initializeState(): Promise<void>;
|
|
75
73
|
getAddressPrice(address: string): Promise<number>;
|
|
76
74
|
getNetworkTokenPrice(): Promise<void>;
|
|
77
75
|
getInitialGasPrice(): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwapController.d.ts","sourceRoot":"","sources":["../../../src/controllers/SwapController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,mCAAmC,CAAC;AASjF,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAO/E,eAAO,MAAM,iBAAiB,SAAS,CAAC;AACxC,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAGpC,KAAK,iBAAiB,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC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oB,EAAE,MAAM,YAAY,CAAC;AAI1F,eAAO,MAAM,WAAW;;;2BAgCD,MAAM;6BACJ,MAAM;;uCAqBM,OAAO,EAAE;;
|
|
1
|
+
{"version":3,"file":"SwapApiUtil.d.ts","sourceRoot":"","sources":["../../../src/utils/SwapApiUtil.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAiB,MAAM,mCAAmC,CAAC;AAGhF,OAAO,KAAK,EAAE,iCAAiC,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAI1F,eAAO,MAAM,WAAW;;;2BAgCD,MAAM;6BACJ,MAAM;;uCAqBM,OAAO,EAAE;;CAmC7C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reown/appkit-core-react-native",
|
|
3
|
-
"version": "0.0.0-feat-multi-social-
|
|
3
|
+
"version": "0.0.0-feat-multi-social-20250714194032",
|
|
4
4
|
"main": "lib/commonjs/index.js",
|
|
5
5
|
"types": "lib/typescript/index.d.ts",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@reown/appkit-common-react-native": "0.0.0-feat-multi-social-
|
|
41
|
+
"@reown/appkit-common-react-native": "0.0.0-feat-multi-social-20250714194032",
|
|
42
42
|
"countries-and-timezones": "3.7.2",
|
|
43
43
|
"valtio": "1.11.2"
|
|
44
44
|
},
|
|
@@ -192,7 +192,12 @@ const derivedState = derive(
|
|
|
192
192
|
|
|
193
193
|
if (!_activeAddress) return [];
|
|
194
194
|
|
|
195
|
-
return
|
|
195
|
+
return (
|
|
196
|
+
_connection?.balances
|
|
197
|
+
.get(_activeAddress)
|
|
198
|
+
// Filter out tokens with no quantity
|
|
199
|
+
?.filter(balance => balance?.quantity?.numeric)
|
|
200
|
+
);
|
|
196
201
|
},
|
|
197
202
|
walletInfo: (get): WalletInfo | undefined => {
|
|
198
203
|
const snap = get(baseState);
|
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
import { proxy } from 'valtio';
|
|
2
2
|
import type { CaipNetwork, SocialProvider } from '@reown/appkit-common-react-native';
|
|
3
3
|
|
|
4
|
-
import type {
|
|
5
|
-
WcWallet,
|
|
6
|
-
Connector,
|
|
7
|
-
SwapInputTarget,
|
|
8
|
-
OnRampTransactionResult
|
|
9
|
-
} from '../utils/TypeUtil';
|
|
4
|
+
import type { WcWallet, Connector, OnRampTransactionResult } from '../utils/TypeUtil';
|
|
10
5
|
|
|
11
6
|
// -- Types --------------------------------------------- //
|
|
12
|
-
type TransactionAction = {
|
|
13
|
-
goBack: boolean;
|
|
14
|
-
view: RouterControllerState['view'] | null;
|
|
15
|
-
close?: boolean;
|
|
16
|
-
replace?: boolean;
|
|
17
|
-
onSuccess?: () => void;
|
|
18
|
-
onCancel?: () => void;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
7
|
export interface RouterControllerState {
|
|
22
8
|
view:
|
|
23
9
|
| 'Account'
|
|
@@ -38,7 +24,6 @@ export interface RouterControllerState {
|
|
|
38
24
|
| 'OnRampTransaction'
|
|
39
25
|
| 'SwitchNetwork'
|
|
40
26
|
| 'Swap'
|
|
41
|
-
| 'SwapSelectToken'
|
|
42
27
|
| 'SwapPreview'
|
|
43
28
|
| 'Transactions'
|
|
44
29
|
| 'UnsupportedChain'
|
|
@@ -57,18 +42,15 @@ export interface RouterControllerState {
|
|
|
57
42
|
network?: CaipNetwork;
|
|
58
43
|
email?: string;
|
|
59
44
|
newEmail?: string;
|
|
60
|
-
swapTarget?: SwapInputTarget;
|
|
61
45
|
onrampResult?: OnRampTransactionResult;
|
|
62
46
|
socialProvider?: SocialProvider;
|
|
63
47
|
};
|
|
64
|
-
transactionStack: TransactionAction[];
|
|
65
48
|
}
|
|
66
49
|
|
|
67
50
|
// -- State --------------------------------------------- //
|
|
68
51
|
const state = proxy<RouterControllerState>({
|
|
69
52
|
view: 'Connect',
|
|
70
|
-
history: ['Connect']
|
|
71
|
-
transactionStack: []
|
|
53
|
+
history: ['Connect']
|
|
72
54
|
});
|
|
73
55
|
|
|
74
56
|
// -- Controller ---------------------------------------- //
|
|
@@ -83,30 +65,6 @@ export const RouterController = {
|
|
|
83
65
|
}
|
|
84
66
|
},
|
|
85
67
|
|
|
86
|
-
pushTransactionStack(action: TransactionAction) {
|
|
87
|
-
state.transactionStack = [...state.transactionStack, action];
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
popTransactionStack(cancel?: boolean) {
|
|
91
|
-
const action = state.transactionStack.pop();
|
|
92
|
-
|
|
93
|
-
if (!action) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (cancel) {
|
|
98
|
-
this.goBack();
|
|
99
|
-
action?.onCancel?.();
|
|
100
|
-
} else {
|
|
101
|
-
if (action.goBack) {
|
|
102
|
-
this.goBack();
|
|
103
|
-
} else if (action.view) {
|
|
104
|
-
this.reset(action.view);
|
|
105
|
-
}
|
|
106
|
-
action?.onSuccess?.();
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
|
|
110
68
|
reset(view: RouterControllerState['view'], data?: RouterControllerState['data']) {
|
|
111
69
|
state.view = view;
|
|
112
70
|
state.history = [view];
|
|
@@ -135,10 +135,7 @@ export const SendController = {
|
|
|
135
135
|
},
|
|
136
136
|
|
|
137
137
|
async sendNativeToken(params: TxParams) {
|
|
138
|
-
|
|
139
|
-
view: 'Account',
|
|
140
|
-
goBack: false
|
|
141
|
-
});
|
|
138
|
+
const isAuth = !!ConnectionsController.state.connection?.properties?.provider;
|
|
142
139
|
|
|
143
140
|
const to = params.receiverAddress as `0x${string}`;
|
|
144
141
|
const address = CoreHelperUtil.getPlainAddress(
|
|
@@ -173,6 +170,7 @@ export const SendController = {
|
|
|
173
170
|
network: ConnectionsController.state.activeNetwork?.caipNetworkId || ''
|
|
174
171
|
}
|
|
175
172
|
});
|
|
173
|
+
RouterController.reset(isAuth ? 'Account' : 'AccountDefault');
|
|
176
174
|
this.resetSend();
|
|
177
175
|
} catch (error) {
|
|
178
176
|
state.loading = false;
|
|
@@ -191,10 +189,7 @@ export const SendController = {
|
|
|
191
189
|
},
|
|
192
190
|
|
|
193
191
|
async sendERC20Token(params: ContractWriteParams) {
|
|
194
|
-
|
|
195
|
-
view: 'Account',
|
|
196
|
-
goBack: false
|
|
197
|
-
});
|
|
192
|
+
const isAuth = !!ConnectionsController.state.connection?.properties?.provider;
|
|
198
193
|
|
|
199
194
|
const amount = ConnectionsController.parseUnits(
|
|
200
195
|
params.sendTokenAmount.toString(),
|
|
@@ -227,6 +222,7 @@ export const SendController = {
|
|
|
227
222
|
method: 'transfer',
|
|
228
223
|
abi: ContractUtil.getERC20Abi(tokenAddress)
|
|
229
224
|
});
|
|
225
|
+
RouterController.reset(isAuth ? 'Account' : 'AccountDefault');
|
|
230
226
|
SnackController.showSuccess('Transaction started');
|
|
231
227
|
this.resetSend();
|
|
232
228
|
}
|
|
@@ -41,8 +41,7 @@ class TransactionError extends Error {
|
|
|
41
41
|
|
|
42
42
|
export interface SwapControllerState {
|
|
43
43
|
// Loading states
|
|
44
|
-
|
|
45
|
-
initialized: boolean;
|
|
44
|
+
loadingTokens: boolean;
|
|
46
45
|
loadingPrices: boolean;
|
|
47
46
|
loadingQuote?: boolean;
|
|
48
47
|
loadingApprovalTransaction?: boolean;
|
|
@@ -92,8 +91,7 @@ type StateKey = keyof SwapControllerState;
|
|
|
92
91
|
// -- State --------------------------------------------- //
|
|
93
92
|
const initialState: SwapControllerState = {
|
|
94
93
|
// Loading states
|
|
95
|
-
|
|
96
|
-
initialized: false,
|
|
94
|
+
loadingTokens: false,
|
|
97
95
|
loadingPrices: false,
|
|
98
96
|
loadingQuote: false,
|
|
99
97
|
loadingApprovalTransaction: false,
|
|
@@ -195,7 +193,7 @@ export const SwapController = {
|
|
|
195
193
|
},
|
|
196
194
|
|
|
197
195
|
switchTokens() {
|
|
198
|
-
if (state.
|
|
196
|
+
if (state.loadingTokens) {
|
|
199
197
|
return;
|
|
200
198
|
}
|
|
201
199
|
|
|
@@ -221,24 +219,35 @@ export const SwapController = {
|
|
|
221
219
|
},
|
|
222
220
|
|
|
223
221
|
async fetchTokens() {
|
|
224
|
-
|
|
222
|
+
try {
|
|
223
|
+
const { networkAddress } = this.getParams();
|
|
225
224
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
225
|
+
state.loadingTokens = true;
|
|
226
|
+
await this.getTokenList();
|
|
227
|
+
await this.getNetworkTokenPrice();
|
|
228
|
+
await this.getMyTokensWithBalance();
|
|
229
229
|
|
|
230
|
-
|
|
230
|
+
const networkToken = state.tokens?.find(token => token.address === networkAddress);
|
|
231
231
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
232
|
+
if (networkToken) {
|
|
233
|
+
state.networkTokenSymbol = networkToken.symbol;
|
|
234
|
+
}
|
|
235
235
|
|
|
236
|
-
|
|
237
|
-
state.
|
|
238
|
-
|
|
236
|
+
// Set default source token if not set
|
|
237
|
+
if (!state.sourceToken && state.myTokensWithBalance?.length) {
|
|
238
|
+
const sourceToken =
|
|
239
|
+
state.myTokensWithBalance?.find(token => token.address.startsWith(networkAddress)) ||
|
|
240
|
+
state.myTokensWithBalance?.[0];
|
|
239
241
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
+
this.setSourceToken(sourceToken);
|
|
243
|
+
this.setSourceTokenAmount('1');
|
|
244
|
+
}
|
|
245
|
+
} catch (error) {
|
|
246
|
+
SnackController.showError('Failed to initialize swap');
|
|
247
|
+
RouterController.goBack();
|
|
248
|
+
} finally {
|
|
249
|
+
state.loadingTokens = false;
|
|
250
|
+
}
|
|
242
251
|
},
|
|
243
252
|
|
|
244
253
|
async getTokenList() {
|
|
@@ -275,10 +284,12 @@ export const SwapController = {
|
|
|
275
284
|
this.setBalances(swapBalances);
|
|
276
285
|
},
|
|
277
286
|
|
|
278
|
-
getFilteredPopularTokens() {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
287
|
+
getFilteredPopularTokens(balances?: SwapTokenWithBalance[]) {
|
|
288
|
+
if (!balances) {
|
|
289
|
+
return state.popularTokens;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return state.popularTokens?.filter(token => !balances.some(t => t.address === token.address));
|
|
282
293
|
},
|
|
283
294
|
|
|
284
295
|
setSourceToken(sourceToken: SwapTokenWithBalance | undefined) {
|
|
@@ -302,25 +313,6 @@ export const SwapController = {
|
|
|
302
313
|
}
|
|
303
314
|
},
|
|
304
315
|
|
|
305
|
-
async initializeState() {
|
|
306
|
-
if (state.initializing) {
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
state.initializing = true;
|
|
311
|
-
if (!state.initialized) {
|
|
312
|
-
try {
|
|
313
|
-
await this.fetchTokens();
|
|
314
|
-
state.initialized = true;
|
|
315
|
-
} catch (error) {
|
|
316
|
-
state.initialized = false;
|
|
317
|
-
SnackController.showError('Failed to initialize swap');
|
|
318
|
-
RouterController.goBack();
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
state.initializing = false;
|
|
322
|
-
},
|
|
323
|
-
|
|
324
316
|
async getAddressPrice(address: string) {
|
|
325
317
|
const existPrice = state.tokensPriceMap[address];
|
|
326
318
|
|
|
@@ -460,11 +452,11 @@ export const SwapController = {
|
|
|
460
452
|
amount: amountDecimal.toString()
|
|
461
453
|
});
|
|
462
454
|
|
|
463
|
-
state.loadingQuote = false;
|
|
464
|
-
|
|
465
455
|
const quoteToAmount = quoteResponse?.quotes?.[0]?.toAmount;
|
|
466
456
|
|
|
467
457
|
if (!quoteToAmount) {
|
|
458
|
+
state.loadingQuote = false;
|
|
459
|
+
|
|
468
460
|
return;
|
|
469
461
|
}
|
|
470
462
|
|
|
@@ -487,6 +479,7 @@ export const SwapController = {
|
|
|
487
479
|
}
|
|
488
480
|
} catch (error) {
|
|
489
481
|
SnackController.showError('Failed to get swap quote');
|
|
482
|
+
} finally {
|
|
490
483
|
state.loadingQuote = false;
|
|
491
484
|
}
|
|
492
485
|
},
|
|
@@ -677,12 +670,13 @@ export const SwapController = {
|
|
|
677
670
|
await this.swapTokens();
|
|
678
671
|
await this.getTransaction();
|
|
679
672
|
state.approvalTransaction = undefined;
|
|
680
|
-
state.loadingApprovalTransaction = false;
|
|
681
673
|
} catch (err) {
|
|
682
674
|
const error = err as TransactionError;
|
|
683
675
|
state.transactionError = error?.shortMessage as unknown as string;
|
|
684
|
-
|
|
676
|
+
|
|
685
677
|
SnackController.showError(error?.shortMessage ?? 'Transaction error');
|
|
678
|
+
} finally {
|
|
679
|
+
state.loadingApprovalTransaction = false;
|
|
686
680
|
}
|
|
687
681
|
},
|
|
688
682
|
|
|
@@ -690,13 +684,11 @@ export const SwapController = {
|
|
|
690
684
|
if (!data) {
|
|
691
685
|
return undefined;
|
|
692
686
|
}
|
|
693
|
-
const { fromAddress,
|
|
687
|
+
const { fromAddress, isAuthConnector } = this.getParams();
|
|
694
688
|
|
|
695
689
|
state.loadingTransaction = true;
|
|
696
690
|
|
|
697
|
-
const snackbarSuccessMessage = `Swapped ${state.sourceToken
|
|
698
|
-
?.symbol} to ${NumberUtil.formatNumberToLocalString(toTokenAmount, 3)} ${state.toToken
|
|
699
|
-
?.symbol}`;
|
|
691
|
+
const snackbarSuccessMessage = `Swapped ${state.sourceToken?.symbol} to ${state.toToken?.symbol}`;
|
|
700
692
|
|
|
701
693
|
SnackController.showLoading('Confirm transaction in your wallet');
|
|
702
694
|
|
|
@@ -770,21 +762,21 @@ export const SwapController = {
|
|
|
770
762
|
state.toTokenAmount = initialState.toTokenAmount;
|
|
771
763
|
state.toTokenPriceInUSD = initialState.toTokenPriceInUSD;
|
|
772
764
|
state.inputError = initialState.inputError;
|
|
765
|
+
state.loadingApprovalTransaction = initialState.loadingApprovalTransaction;
|
|
766
|
+
state.loadingBuildTransaction = initialState.loadingBuildTransaction;
|
|
767
|
+
state.loadingTransaction = initialState.loadingTransaction;
|
|
768
|
+
state.fetchError = initialState.fetchError;
|
|
769
|
+
state.transactionError = initialState.transactionError;
|
|
770
|
+
state.swapTransaction = initialState.swapTransaction;
|
|
771
|
+
state.approvalTransaction = initialState.approvalTransaction;
|
|
773
772
|
},
|
|
774
773
|
|
|
775
774
|
resetState() {
|
|
775
|
+
this.clearTokens();
|
|
776
776
|
state.myTokensWithBalance = initialState.myTokensWithBalance;
|
|
777
777
|
state.tokensPriceMap = initialState.tokensPriceMap;
|
|
778
|
-
state.initialized = initialState.initialized;
|
|
779
|
-
state.sourceToken = initialState.sourceToken;
|
|
780
|
-
state.sourceTokenAmount = initialState.sourceTokenAmount;
|
|
781
|
-
state.sourceTokenPriceInUSD = initialState.sourceTokenPriceInUSD;
|
|
782
|
-
state.toToken = initialState.toToken;
|
|
783
|
-
state.toTokenAmount = initialState.toTokenAmount;
|
|
784
|
-
state.toTokenPriceInUSD = initialState.toTokenPriceInUSD;
|
|
785
778
|
state.networkPrice = initialState.networkPrice;
|
|
786
779
|
state.networkTokenSymbol = initialState.networkTokenSymbol;
|
|
787
|
-
state.inputError = initialState.inputError;
|
|
788
780
|
},
|
|
789
781
|
|
|
790
782
|
// -- Checks -------------------------------------------- //
|
package/src/utils/SwapApiUtil.ts
CHANGED
|
@@ -66,16 +66,18 @@ export const SwapApiUtil = {
|
|
|
66
66
|
: undefined;
|
|
67
67
|
|
|
68
68
|
return (
|
|
69
|
-
balances
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
balances
|
|
70
|
+
?.filter(balance => balance?.quantity?.numeric)
|
|
71
|
+
.map(
|
|
72
|
+
token =>
|
|
73
|
+
({
|
|
74
|
+
...token,
|
|
75
|
+
address: token?.address ?? `${token?.chainId ?? activeCaipNetworkId}:${address}`,
|
|
76
|
+
decimals: parseInt(token.quantity?.decimals ?? '0', 10),
|
|
77
|
+
logoUri: token.iconUrl,
|
|
78
|
+
eip2612: false
|
|
79
|
+
}) as SwapTokenWithBalance
|
|
80
|
+
) || []
|
|
79
81
|
);
|
|
80
82
|
},
|
|
81
83
|
|