@reown/appkit-core-react-native 0.0.0-feat-multi-social-20250703185818 → 0.0.0-feat-multi-social-20250708154835
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 +23 -23
- package/lib/commonjs/controllers/ConnectionsController.js.map +1 -1
- package/lib/commonjs/controllers/SendController.js +7 -8
- package/lib/commonjs/controllers/SendController.js.map +1 -1
- package/lib/commonjs/controllers/SwapController.js +17 -48
- package/lib/commonjs/controllers/SwapController.js.map +1 -1
- package/lib/commonjs/utils/SwapApiUtil.js +1 -13
- package/lib/commonjs/utils/SwapApiUtil.js.map +1 -1
- package/lib/module/controllers/ConnectionsController.js +23 -23
- package/lib/module/controllers/ConnectionsController.js.map +1 -1
- package/lib/module/controllers/SendController.js +7 -8
- package/lib/module/controllers/SendController.js.map +1 -1
- package/lib/module/controllers/SwapController.js +17 -48
- package/lib/module/controllers/SwapController.js.map +1 -1
- package/lib/module/utils/SwapApiUtil.js +1 -13
- package/lib/module/utils/SwapApiUtil.js.map +1 -1
- package/lib/typescript/controllers/ConnectionsController.d.ts +2 -1
- package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -1
- package/lib/typescript/controllers/SendController.d.ts.map +1 -1
- package/lib/typescript/controllers/SwapController.d.ts +0 -1
- package/lib/typescript/controllers/SwapController.d.ts.map +1 -1
- package/lib/typescript/utils/SwapApiUtil.d.ts +3 -4
- package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/controllers/ConnectionsController.ts +31 -21
- package/src/controllers/SendController.ts +7 -12
- package/src/controllers/SwapController.ts +19 -59
- package/src/utils/SwapApiUtil.ts +4 -20
|
@@ -40,18 +40,6 @@ export const SwapApiUtil = {
|
|
|
40
40
|
}
|
|
41
41
|
return false;
|
|
42
42
|
},
|
|
43
|
-
async getMyTokensWithBalance(forceUpdate) {
|
|
44
|
-
const {
|
|
45
|
-
activeAddress
|
|
46
|
-
} = ConnectionsController.state;
|
|
47
|
-
const response = await BlockchainApiController.getBalance(activeAddress, forceUpdate);
|
|
48
|
-
const balances = response?.balances.filter(balance => balance.quantity.decimals !== '0');
|
|
49
|
-
|
|
50
|
-
// TODO: update balances
|
|
51
|
-
// ConnectionsController.updateBalances(balances);
|
|
52
|
-
|
|
53
|
-
return this.mapBalancesToSwapTokens(balances);
|
|
54
|
-
},
|
|
55
43
|
mapBalancesToSwapTokens(balances) {
|
|
56
44
|
const {
|
|
57
45
|
activeNamespace,
|
|
@@ -61,7 +49,7 @@ export const SwapApiUtil = {
|
|
|
61
49
|
return balances?.map(token => ({
|
|
62
50
|
...token,
|
|
63
51
|
address: token?.address ?? `${token?.chainId ?? activeCaipNetworkId}:${address}`,
|
|
64
|
-
decimals: parseInt(token.quantity
|
|
52
|
+
decimals: parseInt(token.quantity?.decimals ?? '0', 10),
|
|
65
53
|
logoUri: token.iconUrl,
|
|
66
54
|
eip2612: false
|
|
67
55
|
})) || [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BlockchainApiController","OptionsController","ConnectionsController","ConstantsUtil","SwapApiUtil","getTokenList","chainId","state","activeNetwork","caipNetworkId","response","fetchSwapTokens","projectId","tokens","map","token","eip2612","quantity","decimals","numeric","price","value","fetchSwapAllowance","tokenAddress","userAddress","sourceTokenAmount","sourceTokenDecimals","allowance","parsedValue","parseUnits","hasAllowance","BigInt","
|
|
1
|
+
{"version":3,"names":["BlockchainApiController","OptionsController","ConnectionsController","ConstantsUtil","SwapApiUtil","getTokenList","chainId","state","activeNetwork","caipNetworkId","response","fetchSwapTokens","projectId","tokens","map","token","eip2612","quantity","decimals","numeric","price","value","fetchSwapAllowance","tokenAddress","userAddress","sourceTokenAmount","sourceTokenDecimals","allowance","parsedValue","parseUnits","hasAllowance","BigInt","mapBalancesToSwapTokens","balances","activeNamespace","activeCaipNetworkId","address","NATIVE_TOKEN_ADDRESS","undefined","parseInt","logoUri","iconU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AC;MAC/E,MAAMI,YAAY,GAAGC,MAAM,CAACrB,QAAQ,CAACiB,SAAS,CAAC,IAAIC,WAAW;MAE9D,OAAOE,YAAY;IACrB;IAEA,OAAO,KAAK;EACd,CAAC;EAEDE,uBAAuBA,CAACC,QAAoB,EAAE;IAC5C,MAAM;MAAEC,eAAe;MAAEC;IAAoB,CAAC,GAAGjC,qBAAqB,CAACK,KAAK;IAC5E,MAAM6B,OAAO,GAAGF,eAAe,GAC3B/B,aAAa,CAACkC,oBAAoB,CAACH,eAAe,CAAC,GACnDI,SAAS;IAEb,OACEL,QAAQ,EAAEnB,GAAG,CACXC,KAAK,KACF;MACC,GAAGA,KAAK;MACRqB,OAAO,EAAErB,KAAK,EAAEqB,OAAO,IAAK,GAAErB,KAAK,EAAET,OAAO,IAAI6B,mBAAoB,IAAGC,OAAQ,EAAC;MAChFlB,QAAQ,EAAEqB,QAAQ,CAACxB,KAAK,CAACE,QAAQ,EAAEC,QAAQ,IAAI,GAAG,EAAE,EAAE,CAAC;MACvDsB,OAAO,EAAEzB,KAAK,CAAC0B,OAAO;MACtBzB,OAAO,EAAE;IACX,CAAC,CACL,CAAC,IAAI,EAAE;EAEX,CAAC;EAED,MAAM0B,aAAaA,CAAA,EAAG;IACpB,MAAM9B,SAAS,GAAGX,iBAAiB,CAACM,KAAK,CAACK,SAAS;IACnD,MAAM+B,WAAW,GAAGzC,qBAAqB,CAACK,KAAK,CAACC,aAAa;IAE7D,IAAI,CAACmC,WAAW,EAAE;MAChB,OAAO,IAAI;IACb;IAEA,OAAO,MAAM3C,uBAAuB,CAAC0C,aAAa,CAAC;MACjD9B,SAAS;MACTN,OAAO,EAAEqC,WAAW,CAAClC;IACvB,CAAC,CAAC;EACJ;AACF,CAAC"}
|
|
@@ -44,7 +44,8 @@ export declare const ConnectionsController: {
|
|
|
44
44
|
signMessage(address: CaipAddress, message: string): Promise<string | undefined>;
|
|
45
45
|
sendTransaction(args: any): Promise<`0x${string}` | null | undefined>;
|
|
46
46
|
estimateGas(args: any): Promise<bigint | undefined>;
|
|
47
|
-
|
|
47
|
+
writeContract(args: any): Promise<`0x${string}` | null | undefined>;
|
|
48
|
+
fetchBalance(forceUpdateAddresses?: CaipAddress[]): Promise<void>;
|
|
48
49
|
getSmartAccountEnabledNetworks(): AppKitNetwork[];
|
|
49
50
|
};
|
|
50
51
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionsController.d.ts","sourceRoot":"","sources":["../../../src/controllers/ConnectionsController.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,oBAAoB,EACzB,KAAK,WAAW,EACjB,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"ConnectionsController.d.ts","sourceRoot":"","sources":["../../../src/controllers/ConnectionsController.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,oBAAoB,EACzB,KAAK,WAAW,EACjB,MAAM,mCAAmC,CAAC;AAO3C,UAAU,UAAU;IAClB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,QAAQ,EAAE,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,CAAC,CAAC;IACtC,OAAO,EAAE,iBAAiB,CAAC;IAC3B,WAAW,EAAE,aAAa,CAAC;IAC3B,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAClC,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED,MAAM,WAAW,0BAA0B;IACzC,eAAe,CAAC,EAAE,cAAc,CAAC;IACjC,WAAW,EAAE,GAAG,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;IAC7C,QAAQ,EAAE,aAAa,EAAE,CAAC;CAC3B;AA+KD,eAAO,MAAM,qBAAqB;;;;;;;;;;;mCAGD,cAAc;;kBAajC,WAAW,EAAE;iBACd,iBAAiB;qBACb,aAAa;mBACf,cAAc;;;;8BA0BD,cAAc,YAAY,WAAW,EAAE;6BAYxC,cAAc,WAAW,WAAW,WAAW,OAAO;gCAiCnD,cAAc,aAAa,aAAa;0BAa9C,aAAa,EAAE;;8BAaX,cAAc,QAAQ,WAAW;0BAU/B,cAAc;sBA4CxB,MAAM,YAAY,MAAM;yBAQf,WAAW,WAAW,MAAM;0BAkB3B,GAAG;sBAWP,GAAG;wBAWD,GAAG;wCAWa,WAAW,EAAE;sCAoCrB,aAAa,EAAE;CAuBlD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SendController.d.ts","sourceRoot":"","sources":["../../../src/controllers/SendController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,KAAK,OAAO,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"SendController.d.ts","sourceRoot":"","sources":["../../../src/controllers/SendController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,KAAK,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAS/E,MAAM,WAAW,QAAQ;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;CAClB;AAUD,eAAO,MAAM,cAAc;;mCAGM,mBAAmB,KAAK,IAAI;2GAI2B,IAAI;oBAI1E,mBAAmB,CAAC,OAAO,CAAC;oCAMZ,mBAAmB,CAAC,iBAAiB,CAAC;wCAIlC,mBAAmB,CAAC,iBAAiB,CAAC;wDAK/C,mBAAmB,CAAC,yBAAyB,CAAC;gDAK7B,mBAAmB,CAAC,qBAAqB,CAAC;0BAIhE,mBAAmB,CAAC,UAAU,CAAC;oCAIrB,mBAAmB,CAAC,eAAe,CAAC;wBAIhD,mBAAmB,CAAC,SAAS,CAAC;;4BAiDpB,QAAQ;2BAwDT,mBAAmB;;CAsDjD,CAAC"}
|
|
@@ -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;
|
|
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,M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AAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC;AAwDD,eAAO,MAAM,cAAc;;mCAGM,mBAAmB,KAAK,IAAI;2GAI2B,IAAI;;;;;;;;;;;;;;;;;;;;;yCAmI/C,WAAW,EAAE;;gCAiB5B,oBAAoB,GAAG,SAAS;iCAa/B,MAAM;;6BA2BJ,MAAM;;;;;;;;;;;;0BA8Df,oBAAoB,EAAE;wBAQxB,oBAAoB,GAAG,SAAS;6BAa3B,MAAM;2BAMF,MAAM,UAAU,eAAe;;;;;;;;;;;;;;;;;;;qCAwPrB,iBAAiB;iCA4BrB,iBAAiB,GAAG,SAAS;4CAgFxB,MAAM,sBAAsB,MAAM;;CAiD3E,CAAC"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { Balance } from '@reown/appkit-common-react-native';
|
|
2
|
+
import type { BlockchainApiSwapAllowanceRequest, SwapTokenWithBalance } from './TypeUtil';
|
|
3
3
|
export declare const SwapApiUtil: {
|
|
4
4
|
getTokenList(): Promise<SwapTokenWithBalance[]>;
|
|
5
5
|
fetchSwapAllowance({ tokenAddress, userAddress, sourceTokenAmount, sourceTokenDecimals }: Pick<BlockchainApiSwapAllowanceRequest, "tokenAddress" | "userAddress"> & {
|
|
6
6
|
sourceTokenAmount: string;
|
|
7
7
|
sourceTokenDecimals: number;
|
|
8
8
|
}): Promise<boolean>;
|
|
9
|
-
|
|
10
|
-
mapBalancesToSwapTokens(balances?: BlockchainApiBalanceResponse['balances']): SwapTokenWithBalance[];
|
|
9
|
+
mapBalancesToSwapTokens(balances?: Balance[]): SwapTokenWithBalance[];
|
|
11
10
|
fetchGasPrice(): Promise<import("./TypeUtil").BlockchainApiGasPriceResponse | null | undefined>;
|
|
12
11
|
};
|
|
13
12
|
//# sourceMappingURL=SwapApiUtil.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwapApiUtil.d.ts","sourceRoot":"","sources":["../../../src/utils/SwapApiUtil.ts"],"names":[],"mappings":"
|
|
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;;CAiC7C,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-20250708154835",
|
|
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-20250708154835",
|
|
42
42
|
"countries-and-timezones": "3.7.2",
|
|
43
43
|
"valtio": "1.11.2"
|
|
44
44
|
},
|
|
@@ -18,11 +18,9 @@ import { SnackController } from './SnackController';
|
|
|
18
18
|
import { OptionsController } from './OptionsController';
|
|
19
19
|
|
|
20
20
|
// -- Types --------------------------------------------- //
|
|
21
|
-
|
|
22
|
-
//TODO: balance could be elsewhere
|
|
23
21
|
interface Connection {
|
|
24
22
|
accounts: CaipAddress[];
|
|
25
|
-
balances: Map<CaipAddress, Balance[]>;
|
|
23
|
+
balances: Map<CaipAddress, Balance[]>;
|
|
26
24
|
adapter: BlockchainAdapter;
|
|
27
25
|
caipNetwork: CaipNetworkId;
|
|
28
26
|
wallet?: WalletInfo;
|
|
@@ -85,8 +83,11 @@ const getActiveAddress = (connection: Connection): CaipAddress | undefined => {
|
|
|
85
83
|
return findEOAForNetwork(connection);
|
|
86
84
|
};
|
|
87
85
|
|
|
88
|
-
const updateConnection = (
|
|
89
|
-
|
|
86
|
+
const updateConnection = (
|
|
87
|
+
namespace: ChainNamespace,
|
|
88
|
+
connection: Connection,
|
|
89
|
+
updates: Partial<Connection>
|
|
90
|
+
) => {
|
|
90
91
|
if (!connection) return;
|
|
91
92
|
const newConnectionsMap = new Map(baseState.connections);
|
|
92
93
|
newConnectionsMap.set(namespace, { ...connection, ...updates });
|
|
@@ -132,7 +133,7 @@ const derivedState = derive(
|
|
|
132
133
|
if (configuredToken) {
|
|
133
134
|
// Find the configured token in the balances
|
|
134
135
|
const specificToken = addressBalances.find(
|
|
135
|
-
balance => balance.
|
|
136
|
+
balance => balance.address === configuredToken.address
|
|
136
137
|
);
|
|
137
138
|
if (specificToken) {
|
|
138
139
|
return specificToken;
|
|
@@ -140,8 +141,8 @@ const derivedState = derive(
|
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
143
|
|
|
143
|
-
// Return the native token (first balance without
|
|
144
|
-
const nativeToken = addressBalances.find(balance => !balance.
|
|
144
|
+
// Return the native token (first balance without address)
|
|
145
|
+
const nativeToken = addressBalances.find(balance => !balance.address);
|
|
145
146
|
if (nativeToken) {
|
|
146
147
|
return nativeToken;
|
|
147
148
|
}
|
|
@@ -274,8 +275,8 @@ export const ConnectionsController = {
|
|
|
274
275
|
const existingBalances = connection.balances.get(address) || [];
|
|
275
276
|
// Check if this token already exists by contract address or symbol
|
|
276
277
|
const existingIndex = existingBalances.findIndex(existingBalance => {
|
|
277
|
-
if (balance.
|
|
278
|
-
return existingBalance.
|
|
278
|
+
if (balance.address) {
|
|
279
|
+
return existingBalance.address === balance.address;
|
|
279
280
|
}
|
|
280
281
|
|
|
281
282
|
return existingBalance.symbol === balance.symbol;
|
|
@@ -293,7 +294,7 @@ export const ConnectionsController = {
|
|
|
293
294
|
updatedBalances = [...existingBalances, balance];
|
|
294
295
|
}
|
|
295
296
|
newBalances.set(address, updatedBalances);
|
|
296
|
-
updateConnection(namespace, { balances: newBalances });
|
|
297
|
+
updateConnection(namespace, connection, { balances: newBalances });
|
|
297
298
|
},
|
|
298
299
|
|
|
299
300
|
setActiveNetwork(namespace: ChainNamespace, networkId: CaipNetworkId) {
|
|
@@ -327,7 +328,8 @@ export const ConnectionsController = {
|
|
|
327
328
|
if (!connection) return;
|
|
328
329
|
|
|
329
330
|
const newConnectionsMap = new Map(baseState.connections);
|
|
330
|
-
|
|
331
|
+
const newConnection = { ...connection, type };
|
|
332
|
+
newConnectionsMap.set(namespace, newConnection);
|
|
331
333
|
baseState.connections = newConnectionsMap;
|
|
332
334
|
},
|
|
333
335
|
|
|
@@ -423,24 +425,32 @@ export const ConnectionsController = {
|
|
|
423
425
|
return undefined;
|
|
424
426
|
},
|
|
425
427
|
|
|
426
|
-
async
|
|
428
|
+
async writeContract(args: any) {
|
|
429
|
+
if (!baseState.activeNamespace) return undefined;
|
|
430
|
+
|
|
431
|
+
const adapter = baseState.connections.get(baseState.activeNamespace)?.adapter;
|
|
432
|
+
if (adapter instanceof EVMAdapter) {
|
|
433
|
+
return adapter.writeContract(args);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
return undefined;
|
|
437
|
+
},
|
|
438
|
+
|
|
439
|
+
async fetchBalance(forceUpdateAddresses?: CaipAddress[]) {
|
|
427
440
|
const connection = getActiveConnection(baseState);
|
|
428
441
|
if (!connection) {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
return;
|
|
442
|
+
throw new Error('No active connection found for balance fetch');
|
|
432
443
|
}
|
|
444
|
+
|
|
433
445
|
const chainId = connection.caipNetwork;
|
|
434
446
|
const address = getActiveAddress(connection);
|
|
435
447
|
const namespace = baseState.activeNamespace;
|
|
436
448
|
if (!namespace || !address || !chainId) {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
return;
|
|
449
|
+
throw new Error('Missing required data for balance fetch');
|
|
440
450
|
}
|
|
441
451
|
|
|
442
452
|
try {
|
|
443
|
-
const response = await BlockchainApiController.getBalance(address);
|
|
453
|
+
const response = await BlockchainApiController.getBalance(address, forceUpdateAddresses);
|
|
444
454
|
if (!response) {
|
|
445
455
|
throw new Error('Failed to fetch token balance');
|
|
446
456
|
}
|
|
@@ -450,7 +460,7 @@ export const ConnectionsController = {
|
|
|
450
460
|
name: balance.name,
|
|
451
461
|
symbol: balance.symbol,
|
|
452
462
|
amount: balance.quantity.numeric,
|
|
453
|
-
|
|
463
|
+
address: balance.address,
|
|
454
464
|
quantity: balance.quantity,
|
|
455
465
|
price: balance.price,
|
|
456
466
|
value: balance.value,
|
|
@@ -2,7 +2,6 @@ import { subscribeKey as subKey } from 'valtio/vanilla/utils';
|
|
|
2
2
|
import { proxy, ref, subscribe as sub } from 'valtio/vanilla';
|
|
3
3
|
import { ContractUtil, type Balance } from '@reown/appkit-common-react-native';
|
|
4
4
|
|
|
5
|
-
import { ConnectionController } from './ConnectionController';
|
|
6
5
|
import { SnackController } from './SnackController';
|
|
7
6
|
import { CoreHelperUtil } from '../utils/CoreHelperUtil';
|
|
8
7
|
import { EventsController } from './EventsController';
|
|
@@ -91,25 +90,21 @@ export const SendController = {
|
|
|
91
90
|
},
|
|
92
91
|
|
|
93
92
|
sendToken() {
|
|
94
|
-
if (
|
|
95
|
-
this.state.token?.contractAddress &&
|
|
96
|
-
this.state.sendTokenAmount &&
|
|
97
|
-
this.state.receiverAddress
|
|
98
|
-
) {
|
|
93
|
+
if (this.state.token?.address && this.state.sendTokenAmount && this.state.receiverAddress) {
|
|
99
94
|
state.loading = true;
|
|
100
95
|
EventsController.sendEvent({
|
|
101
96
|
type: 'track',
|
|
102
97
|
event: 'SEND_INITIATED',
|
|
103
98
|
properties: {
|
|
104
99
|
isSmartAccount: ConnectionsController.state.accountType === 'smartAccount',
|
|
105
|
-
token: this.state.token.
|
|
100
|
+
token: this.state.token.address,
|
|
106
101
|
amount: this.state.sendTokenAmount,
|
|
107
102
|
network: ConnectionsController.state.activeNetwork?.caipNetworkId || ''
|
|
108
103
|
}
|
|
109
104
|
});
|
|
110
105
|
this.sendERC20Token({
|
|
111
106
|
receiverAddress: this.state.receiverAddress,
|
|
112
|
-
tokenAddress: this.state.token.
|
|
107
|
+
tokenAddress: this.state.token.address,
|
|
113
108
|
sendTokenAmount: this.state.sendTokenAmount,
|
|
114
109
|
decimals: this.state.token.quantity?.decimals || '0'
|
|
115
110
|
});
|
|
@@ -153,14 +148,14 @@ export const SendController = {
|
|
|
153
148
|
throw new Error('Invalid address');
|
|
154
149
|
}
|
|
155
150
|
|
|
156
|
-
const value =
|
|
151
|
+
const value = ConnectionsController.parseUnits(
|
|
157
152
|
params.sendTokenAmount.toString(),
|
|
158
153
|
Number(params.decimals)
|
|
159
154
|
);
|
|
160
155
|
const data = '0x';
|
|
161
156
|
|
|
162
157
|
try {
|
|
163
|
-
await
|
|
158
|
+
await ConnectionsController.sendTransaction({
|
|
164
159
|
to,
|
|
165
160
|
address,
|
|
166
161
|
data,
|
|
@@ -201,7 +196,7 @@ export const SendController = {
|
|
|
201
196
|
goBack: false
|
|
202
197
|
});
|
|
203
198
|
|
|
204
|
-
const amount =
|
|
199
|
+
const amount = ConnectionsController.parseUnits(
|
|
205
200
|
params.sendTokenAmount.toString(),
|
|
206
201
|
Number(params.decimals)
|
|
207
202
|
);
|
|
@@ -224,7 +219,7 @@ export const SendController = {
|
|
|
224
219
|
throw new Error('Invalid address');
|
|
225
220
|
}
|
|
226
221
|
|
|
227
|
-
await
|
|
222
|
+
await ConnectionsController.writeContract({
|
|
228
223
|
fromAddress,
|
|
229
224
|
tokenAddress,
|
|
230
225
|
receiverAddress: params.receiverAddress as `0x${string}`,
|
|
@@ -10,7 +10,6 @@ import { SwapCalculationUtil } from '../utils/SwapCalculationUtil';
|
|
|
10
10
|
import { SnackController } from './SnackController';
|
|
11
11
|
import { RouterController } from './RouterController';
|
|
12
12
|
import type { SwapInputTarget, SwapTokenWithBalance } from '../utils/TypeUtil';
|
|
13
|
-
import { ConnectorController } from './ConnectorController';
|
|
14
13
|
import { CoreHelperUtil } from '../utils/CoreHelperUtil';
|
|
15
14
|
import { TransactionsController } from './TransactionsController';
|
|
16
15
|
import { EventsController } from './EventsController';
|
|
@@ -66,7 +65,6 @@ export interface SwapControllerState {
|
|
|
66
65
|
toTokenAmount: string;
|
|
67
66
|
toTokenPriceInUSD: number;
|
|
68
67
|
networkPrice: string;
|
|
69
|
-
networkBalanceInUSD: string;
|
|
70
68
|
networkTokenSymbol: string;
|
|
71
69
|
inputError: string | undefined;
|
|
72
70
|
|
|
@@ -118,7 +116,6 @@ const initialState: SwapControllerState = {
|
|
|
118
116
|
toTokenAmount: '',
|
|
119
117
|
toTokenPriceInUSD: 0,
|
|
120
118
|
networkPrice: '0',
|
|
121
|
-
networkBalanceInUSD: '0',
|
|
122
119
|
networkTokenSymbol: '',
|
|
123
120
|
inputError: undefined,
|
|
124
121
|
|
|
@@ -156,7 +153,8 @@ export const SwapController = {
|
|
|
156
153
|
},
|
|
157
154
|
|
|
158
155
|
getParams() {
|
|
159
|
-
const { activeAddress, activeNamespace, activeNetwork } =
|
|
156
|
+
const { activeAddress, activeNamespace, activeNetwork, connection } =
|
|
157
|
+
ConnectionsController.state;
|
|
160
158
|
const address = CoreHelperUtil.getPlainAddress(activeAddress);
|
|
161
159
|
|
|
162
160
|
if (!activeNamespace || !activeNetwork) {
|
|
@@ -165,8 +163,6 @@ export const SwapController = {
|
|
|
165
163
|
|
|
166
164
|
const networkAddress: CaipAddress = `${activeNetwork.caipNetworkId}:${ConstantsUtil.NATIVE_TOKEN_ADDRESS[activeNamespace]}`;
|
|
167
165
|
|
|
168
|
-
const type = ConnectorController.state.connectedConnector;
|
|
169
|
-
|
|
170
166
|
if (!address) {
|
|
171
167
|
throw new Error('No address found to swap the tokens from.');
|
|
172
168
|
}
|
|
@@ -194,7 +190,7 @@ export const SwapController = {
|
|
|
194
190
|
invalidSourceTokenAmount,
|
|
195
191
|
availableToSwap:
|
|
196
192
|
activeAddress && !invalidToToken && !invalidSourceToken && !invalidSourceTokenAmount,
|
|
197
|
-
isAuthConnector:
|
|
193
|
+
isAuthConnector: !!connection?.properties?.provider
|
|
198
194
|
};
|
|
199
195
|
},
|
|
200
196
|
|
|
@@ -236,7 +232,6 @@ export const SwapController = {
|
|
|
236
232
|
state.toTokenPriceInUSD = initialState.toTokenPriceInUSD;
|
|
237
233
|
state.networkPrice = initialState.networkPrice;
|
|
238
234
|
state.networkTokenSymbol = initialState.networkTokenSymbol;
|
|
239
|
-
state.networkBalanceInUSD = initialState.networkBalanceInUSD;
|
|
240
235
|
state.inputError = initialState.inputError;
|
|
241
236
|
},
|
|
242
237
|
|
|
@@ -285,13 +280,14 @@ export const SwapController = {
|
|
|
285
280
|
},
|
|
286
281
|
|
|
287
282
|
async getMyTokensWithBalance(forceUpdate?: CaipAddress[]) {
|
|
288
|
-
|
|
289
|
-
|
|
283
|
+
await ConnectionsController.fetchBalance(forceUpdate);
|
|
284
|
+
const swapBalances = SwapApiUtil.mapBalancesToSwapTokens(ConnectionsController.state.balances);
|
|
285
|
+
if (!swapBalances) {
|
|
290
286
|
return;
|
|
291
287
|
}
|
|
292
288
|
|
|
293
289
|
await this.getInitialGasPrice();
|
|
294
|
-
this.setBalances(
|
|
290
|
+
this.setBalances(swapBalances);
|
|
295
291
|
},
|
|
296
292
|
|
|
297
293
|
getFilteredPopularTokens() {
|
|
@@ -403,26 +399,11 @@ export const SwapController = {
|
|
|
403
399
|
},
|
|
404
400
|
|
|
405
401
|
setBalances(balances: SwapTokenWithBalance[]) {
|
|
406
|
-
|
|
407
|
-
const caipNetwork = ConnectionsController.state.activeNetwork;
|
|
408
|
-
|
|
409
|
-
if (!caipNetwork) {
|
|
410
|
-
return;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
const networkToken = balances.find(token => token.address === networkAddress);
|
|
402
|
+
state.myTokensWithBalance = balances;
|
|
414
403
|
|
|
415
404
|
balances.forEach(token => {
|
|
416
405
|
state.tokensPriceMap[token.address] = token.price || 0;
|
|
417
406
|
});
|
|
418
|
-
|
|
419
|
-
state.myTokensWithBalance = balances.filter(
|
|
420
|
-
token => token.address?.startsWith(caipNetwork.caipNetworkId)
|
|
421
|
-
);
|
|
422
|
-
|
|
423
|
-
state.networkBalanceInUSD = networkToken
|
|
424
|
-
? NumberUtil.multiply(networkToken.quantity.numeric, networkToken.price).toString()
|
|
425
|
-
: '0';
|
|
426
407
|
},
|
|
427
408
|
|
|
428
409
|
setToToken(toToken: SwapTokenWithBalance | undefined) {
|
|
@@ -693,22 +674,10 @@ export const SwapController = {
|
|
|
693
674
|
},
|
|
694
675
|
|
|
695
676
|
async sendTransactionForApproval(data: TransactionParams) {
|
|
696
|
-
const { fromAddress
|
|
697
|
-
|
|
677
|
+
const { fromAddress } = this.getParams();
|
|
698
678
|
state.loadingApprovalTransaction = true;
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
if (isAuthConnector) {
|
|
702
|
-
RouterController.pushTransactionStack({
|
|
703
|
-
view: null,
|
|
704
|
-
goBack: true,
|
|
705
|
-
onSuccess() {
|
|
706
|
-
SnackController.showLoading(approveLimitMessage);
|
|
707
|
-
}
|
|
708
|
-
});
|
|
709
|
-
} else {
|
|
710
|
-
SnackController.showLoading(approveLimitMessage);
|
|
711
|
-
}
|
|
679
|
+
|
|
680
|
+
SnackController.showLoading('Approve limit increase in your wallet');
|
|
712
681
|
|
|
713
682
|
try {
|
|
714
683
|
await ConnectionsController.sendTransaction({
|
|
@@ -740,25 +709,11 @@ export const SwapController = {
|
|
|
740
709
|
|
|
741
710
|
state.loadingTransaction = true;
|
|
742
711
|
|
|
743
|
-
const snackbarPendingMessage = `Swapping ${state.sourceToken
|
|
744
|
-
?.symbol} to ${NumberUtil.formatNumberToLocalString(toTokenAmount, 3)} ${state.toToken
|
|
745
|
-
?.symbol}`;
|
|
746
712
|
const snackbarSuccessMessage = `Swapped ${state.sourceToken
|
|
747
713
|
?.symbol} to ${NumberUtil.formatNumberToLocalString(toTokenAmount, 3)} ${state.toToken
|
|
748
714
|
?.symbol}`;
|
|
749
715
|
|
|
750
|
-
|
|
751
|
-
RouterController.pushTransactionStack({
|
|
752
|
-
view: 'Account',
|
|
753
|
-
goBack: false,
|
|
754
|
-
onSuccess() {
|
|
755
|
-
SnackController.showLoading(snackbarPendingMessage);
|
|
756
|
-
SwapController.resetState();
|
|
757
|
-
}
|
|
758
|
-
});
|
|
759
|
-
} else {
|
|
760
|
-
SnackController.showLoading('Confirm transaction in your wallet');
|
|
761
|
-
}
|
|
716
|
+
SnackController.showLoading('Confirm transaction in your wallet');
|
|
762
717
|
|
|
763
718
|
try {
|
|
764
719
|
const forceUpdateAddresses = [state.sourceToken?.address, state.toToken?.address].filter(
|
|
@@ -796,7 +751,6 @@ export const SwapController = {
|
|
|
796
751
|
}
|
|
797
752
|
|
|
798
753
|
SwapController.getMyTokensWithBalance(forceUpdateAddresses);
|
|
799
|
-
ConnectionsController.fetchBalance();
|
|
800
754
|
|
|
801
755
|
setTimeout(() => {
|
|
802
756
|
TransactionsController.fetchTransactions(ConnectionsController.state.activeAddress, true);
|
|
@@ -828,6 +782,12 @@ export const SwapController = {
|
|
|
828
782
|
|
|
829
783
|
// -- Checks -------------------------------------------- //
|
|
830
784
|
hasInsufficientToken(sourceTokenAmount: string, sourceTokenAddress: string) {
|
|
785
|
+
const { balances } = ConnectionsController.state;
|
|
786
|
+
const networkToken = balances?.find(t => t.address === undefined);
|
|
787
|
+
const networkBalanceInUSD = networkToken
|
|
788
|
+
? NumberUtil.multiply(networkToken.quantity?.numeric ?? '0', networkToken.price).toString()
|
|
789
|
+
: '0';
|
|
790
|
+
|
|
831
791
|
const isInsufficientSourceTokenForSwap = SwapCalculationUtil.isInsufficientSourceTokenForSwap(
|
|
832
792
|
sourceTokenAmount,
|
|
833
793
|
sourceTokenAddress,
|
|
@@ -840,7 +800,7 @@ export const SwapController = {
|
|
|
840
800
|
insufficientNetworkTokenForGas = false;
|
|
841
801
|
} else {
|
|
842
802
|
insufficientNetworkTokenForGas = SwapCalculationUtil.isInsufficientNetworkTokenForGas(
|
|
843
|
-
|
|
803
|
+
networkBalanceInUSD,
|
|
844
804
|
state.gasPriceInUSD
|
|
845
805
|
);
|
|
846
806
|
}
|
package/src/utils/SwapApiUtil.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
+
import type { Balance, CaipNetworkId } from '@reown/appkit-common-react-native';
|
|
1
2
|
import { BlockchainApiController } from '../controllers/BlockchainApiController';
|
|
2
3
|
import { OptionsController } from '../controllers/OptionsController';
|
|
3
|
-
import type {
|
|
4
|
-
BlockchainApiBalanceResponse,
|
|
5
|
-
BlockchainApiSwapAllowanceRequest,
|
|
6
|
-
SwapTokenWithBalance
|
|
7
|
-
} from './TypeUtil';
|
|
4
|
+
import type { BlockchainApiSwapAllowanceRequest, SwapTokenWithBalance } from './TypeUtil';
|
|
8
5
|
import { ConnectionsController } from '../controllers/ConnectionsController';
|
|
9
|
-
import type { CaipAddress, CaipNetworkId } from '@reown/appkit-common-react-native';
|
|
10
6
|
import { ConstantsUtil } from './ConstantsUtil';
|
|
11
7
|
|
|
12
8
|
export const SwapApiUtil = {
|
|
@@ -63,19 +59,7 @@ export const SwapApiUtil = {
|
|
|
63
59
|
return false;
|
|
64
60
|
},
|
|
65
61
|
|
|
66
|
-
|
|
67
|
-
const { activeAddress } = ConnectionsController.state;
|
|
68
|
-
|
|
69
|
-
const response = await BlockchainApiController.getBalance(activeAddress, forceUpdate);
|
|
70
|
-
const balances = response?.balances.filter(balance => balance.quantity.decimals !== '0');
|
|
71
|
-
|
|
72
|
-
// TODO: update balances
|
|
73
|
-
// ConnectionsController.updateBalances(balances);
|
|
74
|
-
|
|
75
|
-
return this.mapBalancesToSwapTokens(balances);
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
mapBalancesToSwapTokens(balances?: BlockchainApiBalanceResponse['balances']) {
|
|
62
|
+
mapBalancesToSwapTokens(balances?: Balance[]) {
|
|
79
63
|
const { activeNamespace, activeCaipNetworkId } = ConnectionsController.state;
|
|
80
64
|
const address = activeNamespace
|
|
81
65
|
? ConstantsUtil.NATIVE_TOKEN_ADDRESS[activeNamespace]
|
|
@@ -87,7 +71,7 @@ export const SwapApiUtil = {
|
|
|
87
71
|
({
|
|
88
72
|
...token,
|
|
89
73
|
address: token?.address ?? `${token?.chainId ?? activeCaipNetworkId}:${address}`,
|
|
90
|
-
decimals: parseInt(token.quantity
|
|
74
|
+
decimals: parseInt(token.quantity?.decimals ?? '0', 10),
|
|
91
75
|
logoUri: token.iconUrl,
|
|
92
76
|
eip2612: false
|
|
93
77
|
}) as SwapTokenWithBalance
|