@reown/appkit-ethers-react-native 0.0.0-feat-multichain-20250515131524 → 0.0.0-feat-multichain-20250516115442
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/adapter.js +8 -26
- package/lib/commonjs/adapter.js.map +1 -1
- package/lib/commonjs/helpers.js +33 -0
- package/lib/commonjs/helpers.js.map +1 -0
- package/lib/module/adapter.js +8 -26
- package/lib/module/adapter.js.map +1 -1
- package/lib/module/helpers.js +25 -0
- package/lib/module/helpers.js.map +1 -0
- package/lib/typescript/adapter.d.ts +0 -1
- package/lib/typescript/adapter.d.ts.map +1 -1
- package/lib/typescript/helpers.d.ts +3 -0
- package/lib/typescript/helpers.d.ts.map +1 -0
- package/package.json +5 -9
- package/src/adapter.ts +11 -24
- package/src/helpers.ts +25 -0
package/lib/commonjs/adapter.js
CHANGED
|
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.EthersAdapter = void 0;
|
|
7
|
-
var _ethers = require("ethers");
|
|
8
7
|
var _appkitCommonReactNative = require("@reown/appkit-common-react-native");
|
|
9
8
|
var _appkitScaffoldUtilsReactNative = require("@reown/appkit-scaffold-utils-react-native");
|
|
9
|
+
var _helpers = require("./helpers");
|
|
10
10
|
class EthersAdapter extends _appkitCommonReactNative.EVMAdapter {
|
|
11
11
|
static supportedNamespace = 'eip155';
|
|
12
12
|
constructor(configParams) {
|
|
@@ -23,34 +23,24 @@ class EthersAdapter extends _appkitCommonReactNative.EVMAdapter {
|
|
|
23
23
|
if (!this.connector) throw new Error('No active connector');
|
|
24
24
|
if (!network) throw new Error('No network provided');
|
|
25
25
|
const balanceAddress = address || this.getAccounts()?.find(account => account.includes(network.id.toString()));
|
|
26
|
-
|
|
26
|
+
const balance = {
|
|
27
27
|
amount: '0.00',
|
|
28
28
|
symbol: network.nativeCurrency.symbol || 'ETH'
|
|
29
29
|
};
|
|
30
|
-
if (!balanceAddress)
|
|
31
|
-
return Promise.resolve(balance);
|
|
32
|
-
}
|
|
30
|
+
if (!balanceAddress) return balance;
|
|
33
31
|
const account = balanceAddress.split(':')[2];
|
|
32
|
+
const rpcUrl = network.rpcUrls.default.http?.[0];
|
|
33
|
+
if (!rpcUrl || !account) return balance;
|
|
34
34
|
try {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
name: network.name
|
|
38
|
-
});
|
|
39
|
-
if (jsonRpcProvider && account) {
|
|
40
|
-
const _balance = await jsonRpcProvider.getBalance(account);
|
|
41
|
-
const formattedBalance = (0, _ethers.formatEther)(_balance);
|
|
42
|
-
balance = {
|
|
43
|
-
amount: formattedBalance,
|
|
44
|
-
symbol: network.nativeCurrency.symbol || 'ETH'
|
|
45
|
-
};
|
|
46
|
-
}
|
|
35
|
+
const wei = await (0, _helpers.getEthBalance)(rpcUrl, account);
|
|
36
|
+
balance.amount = (0, _helpers.formatEther)(wei);
|
|
47
37
|
this.emit('balanceChanged', {
|
|
48
38
|
namespace: this.getSupportedNamespace(),
|
|
49
39
|
address: balanceAddress,
|
|
50
40
|
balance
|
|
51
41
|
});
|
|
52
42
|
return balance;
|
|
53
|
-
} catch
|
|
43
|
+
} catch {
|
|
54
44
|
return balance;
|
|
55
45
|
}
|
|
56
46
|
}
|
|
@@ -82,14 +72,6 @@ class EthersAdapter extends _appkitCommonReactNative.EVMAdapter {
|
|
|
82
72
|
if (!this.connector) throw new Error('EthersAdapter:disconnect - No active connector');
|
|
83
73
|
return this.connector.disconnect();
|
|
84
74
|
}
|
|
85
|
-
async request(method, params) {
|
|
86
|
-
if (!this.connector) throw new Error('No active connector');
|
|
87
|
-
const provider = this.connector.getProvider();
|
|
88
|
-
return provider.request({
|
|
89
|
-
method,
|
|
90
|
-
params
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
75
|
getSupportedNamespace() {
|
|
94
76
|
return EthersAdapter.supportedNamespace;
|
|
95
77
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_appkitCommonReactNative","require","_appkitScaffoldUtilsReactNative","_helpers","EthersAdapter","EVMAdapter","supportedNamespace","constructor","configParams","projectId","getBalance","params","network","address","connector","Error","balanceAddress","getAccounts","find","account","includes","id","toString","balance","amount","symbol","nativeCurrency","split","rpcUrl","rpcUrls","default","http","wei","getEthBalance","formatEther","emit","namespace","getSupportedNamespace","switchNetwork","provider","getProvider","request","method","chainId","EthersHelpersUtil","numberToHexString","Number","chainNamespace","switchError","message","test","toLowerCase","namespaces","getNamespaces","accounts","disconnect","exports"],"sourceRoot":"../../src","sources":["adapter.ts"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AAQA,IAAAC,+BAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEO,MAAMG,aAAa,SAASC,mCAAU,CAAC;EAC5C,OAAeC,kBAAkB,GAAmB,QAAQ;EAE5DC,WAAWA,CAACC,YAAmC,EAAE;IAC/C,KAAK,CAAC;MACJC,SAAS,EAAED,YAAY,CAACC,SAAS;MACjCH,kBAAkB,EAAEF,aAAa,CAACE;IACpC,CAAC,CAAC;EACJ;EAEA,MAAMI,UAAUA,CAACC,MAAwB,EAA+B;IACtE,MAAM;MAAEC,OAAO;MAAEC;IAAQ,CAAC,GAAGF,MAAM;IAEnC,IAAI,CAAC,IAAI,CAACG,SAAS,EAAE,MAAM,IAAIC,KAAK,CAAC,qBAAqB,CAAC;IAC3D,IAAI,CAACH,OAAO,EAAE,MAAM,IAAIG,KAAK,CAAC,qBAAqB,CAAC;IAEpD,MAAMC,cAAc,GAClBH,OAAO,IAAI,IAAI,CAACI,WAAW,CAAC,CAAC,EAAEC,IAAI,CAACC,OAAO,IAAIA,OAAO,CAACC,QAAQ,CAACR,OAAO,CAACS,EAAE,CAACC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEzF,MAAMC,OAA2B,GAA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AAC;MACjF,CAAC,EACA,GAAET,OAAO,CAACmC,cAAc,IAAI,QAAS,IAAGnC,OAAO,CAACS,EAAG,EACtD,CAAC;IACH,CAAC,CAAC,OAAO2B,WAAgB,EAAE;MACzB,MAAMC,OAAO,GAAGD,WAAW,EAAEC,OAAiB;MAC9C,IAAI,0BAA0B,CAACC,IAAI,CAACD,OAAO,EAAEE,WAAW,CAAC,CAAC,CAAC,EAAE;QAC3D,MAAM,IAAIpC,KAAK,CAAC,wBAAwB,CAAC;MAC3C;MAEA,MAAMiC,WAAW;IACnB;EACF;EAEA/B,WAAWA,CAAA,EAA8B;IACvC,IAAI,CAAC,IAAI,CAACH,SAAS,EAAE,MAAM,IAAIC,KAAK,CAAC,qBAAqB,CAAC;IAC3D,MAAMqC,UAAU,GAAG,IAAI,CAACtC,SAAS,CAACuC,aAAa,CAAC,CAAC;IAEjD,OAAOD,UAAU,CAAC,IAAI,CAACf,qBAAqB,CAAC,CAAC,CAAC,EAAEiB,QAAQ;EAC3D;EAEAC,UAAUA,CAAA,EAAkB;IAC1B,IAAI,CAAC,IAAI,CAACzC,SAAS,EAAE,MAAM,IAAIC,KAAK,CAAC,gDAAgD,CAAC;IAEtF,OAAO,IAAI,CAACD,SAAS,CAACyC,UAAU,CAAC,CAAC;EACpC;EAEAlB,qBAAqBA,CAAA,EAAmB;IACtC,OAAOjC,aAAa,CAACE,kBAAkB;EACzC;AACF;AAACkD,OAAA,CAAApD,aAAA,GAAAA,aAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.formatEther = void 0;
|
|
7
|
+
exports.getEthBalance = getEthBalance;
|
|
8
|
+
// Helper to convert Wei (as string or bigint) to ETH
|
|
9
|
+
const formatEther = wei => {
|
|
10
|
+
return (Number(wei) / 1e18).toString();
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Raw JSON-RPC for balance lookup
|
|
14
|
+
exports.formatEther = formatEther;
|
|
15
|
+
async function getEthBalance(rpcUrl, address) {
|
|
16
|
+
const body = {
|
|
17
|
+
jsonrpc: '2.0',
|
|
18
|
+
method: 'eth_getBalance',
|
|
19
|
+
params: [address, 'latest'],
|
|
20
|
+
id: 1
|
|
21
|
+
};
|
|
22
|
+
const response = await fetch(rpcUrl, {
|
|
23
|
+
method: 'POST',
|
|
24
|
+
headers: {
|
|
25
|
+
'Content-Type': 'application/json'
|
|
26
|
+
},
|
|
27
|
+
body: JSON.stringify(body)
|
|
28
|
+
});
|
|
29
|
+
const json = await response.json();
|
|
30
|
+
if (json.error) throw new Error(json.error.message);
|
|
31
|
+
return BigInt(json.result); // result is hex string
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["formatEther","wei","Number","toString","exports","getEthBalance","rpcUrl","address","body","jsonrpc","method","params","id","response","fetch","headers","JSON","stringify","json","error","Error","message","BigInt","result"],"sourceRoot":"../../src","sources":["helpers.ts"],"mappings":";;;;;;;AAAA;AACO,MAAMA,WAAW,GAAIC,GAAW,IAAa;EAClD,OAAO,CAACC,MAAM,CAACD,GAAG,CAAC,GAAG,IAAI,EAAEE,QAAQ,CAAC,CAAC;AACxC,CAAC;;AAED;AAAAC,OAAA,CAAAJ,WAAA,GAAAA,WAAA;AACO,eAAeK,aAAaA,CAACC,MAAc,EAAEC,OAAe,EAAmB;EACpF,MAAMC,IAAI,GAAG;IACXC,OAAO,EAAE,KAAK;IACdC,MAAM,EAAE,gBAAgB;IACxBC,MAAM,EAAE,CAACJ,OAAO,EAAE,QAAQ,CAAC;IAC3BK,EAAE,EAAE;EACN,CAAC;EAED,MAAMC,QAAQ,GAAG,MAAMC,KAAK,CAACR,MAAM,EAAE;IACnCI,MAAM,EAAE,MAAM;IACdK,OAAO,EAAE;MAAE,cAAc,EAAE;IAAmB,CAAC;IAC/CP,IAAI,EAAEQ,IAAI,CAACC,SAAS,CAACT,IAAI;EAC3B,CAAC,CAAC;EAEF,MAAMU,IAAI,GAAG,MAAML,QAAQ,CAACK,IAAI,CAAC,CAAC;EAClC,IAAIA,IAAI,CAACC,KAAK,EAAE,MAAM,IAAIC,KAAK,CAACF,IAAI,CAACC,KAAK,CAACE,OAAO,CAAC;EAEnD,OAAOC,MAAM,CAACJ,IAAI,CAACK,MAAM,CAAC,CAAC,CAAC;AAC9B"}
|
package/lib/module/adapter.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { formatEther, JsonRpcProvider } from 'ethers';
|
|
2
1
|
import { EVMAdapter } from '@reown/appkit-common-react-native';
|
|
3
2
|
import { EthersHelpersUtil } from '@reown/appkit-scaffold-utils-react-native';
|
|
3
|
+
import { formatEther, getEthBalance } from './helpers';
|
|
4
4
|
export class EthersAdapter extends EVMAdapter {
|
|
5
5
|
static supportedNamespace = 'eip155';
|
|
6
6
|
constructor(configParams) {
|
|
@@ -17,34 +17,24 @@ export class EthersAdapter extends EVMAdapter {
|
|
|
17
17
|
if (!this.connector) throw new Error('No active connector');
|
|
18
18
|
if (!network) throw new Error('No network provided');
|
|
19
19
|
const balanceAddress = address || this.getAccounts()?.find(account => account.includes(network.id.toString()));
|
|
20
|
-
|
|
20
|
+
const balance = {
|
|
21
21
|
amount: '0.00',
|
|
22
22
|
symbol: network.nativeCurrency.symbol || 'ETH'
|
|
23
23
|
};
|
|
24
|
-
if (!balanceAddress)
|
|
25
|
-
return Promise.resolve(balance);
|
|
26
|
-
}
|
|
24
|
+
if (!balanceAddress) return balance;
|
|
27
25
|
const account = balanceAddress.split(':')[2];
|
|
26
|
+
const rpcUrl = network.rpcUrls.default.http?.[0];
|
|
27
|
+
if (!rpcUrl || !account) return balance;
|
|
28
28
|
try {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
name: network.name
|
|
32
|
-
});
|
|
33
|
-
if (jsonRpcProvider && account) {
|
|
34
|
-
const _balance = await jsonRpcProvider.getBalance(account);
|
|
35
|
-
const formattedBalance = formatEther(_balance);
|
|
36
|
-
balance = {
|
|
37
|
-
amount: formattedBalance,
|
|
38
|
-
symbol: network.nativeCurrency.symbol || 'ETH'
|
|
39
|
-
};
|
|
40
|
-
}
|
|
29
|
+
const wei = await getEthBalance(rpcUrl, account);
|
|
30
|
+
balance.amount = formatEther(wei);
|
|
41
31
|
this.emit('balanceChanged', {
|
|
42
32
|
namespace: this.getSupportedNamespace(),
|
|
43
33
|
address: balanceAddress,
|
|
44
34
|
balance
|
|
45
35
|
});
|
|
46
36
|
return balance;
|
|
47
|
-
} catch
|
|
37
|
+
} catch {
|
|
48
38
|
return balance;
|
|
49
39
|
}
|
|
50
40
|
}
|
|
@@ -76,14 +66,6 @@ export class EthersAdapter extends EVMAdapter {
|
|
|
76
66
|
if (!this.connector) throw new Error('EthersAdapter:disconnect - No active connector');
|
|
77
67
|
return this.connector.disconnect();
|
|
78
68
|
}
|
|
79
|
-
async request(method, params) {
|
|
80
|
-
if (!this.connector) throw new Error('No active connector');
|
|
81
|
-
const provider = this.connector.getProvider();
|
|
82
|
-
return provider.request({
|
|
83
|
-
method,
|
|
84
|
-
params
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
69
|
getSupportedNamespace() {
|
|
88
70
|
return EthersAdapter.supportedNamespace;
|
|
89
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["EVMAdapter","EthersHelpersUtil","formatEther","getEthBalance","EthersAdapter","supportedNamespace","constructor","configParams","projectId","getBalance","params","network","address","connector","Error","balanceAddress","getAccounts","find","account","includes","id","toString","balance","amount","symbol","nativeCurrency","split","rpcUrl","rpcUrls","default","http","wei","emit","namespace","getSupportedNamespace","switchNetwork","provider","getProvider","request","method","chainId","numberToHexString","Number","chainNamespace","switchError","message","test","toLowerCase","namespaces","getNamespaces","accounts","disconnect"],"sourceRoot":"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AACH,SAAS,EAAE,MAAM,IAAIC,KAAK,CAAC,qBAAqB,CAAC;IAC3D,MAAMkC,UAAU,GAAG,IAAI,CAACnC,SAAS,CAACoC,aAAa,CAAC,CAAC;IAEjD,OAAOD,UAAU,CAAC,IAAI,CAACd,qBAAqB,CAAC,CAAC,CAAC,EAAEgB,QAAQ;EAC3D;EAEAC,UAAUA,CAAA,EAAkB;IAC1B,IAAI,CAAC,IAAI,CAACtC,SAAS,EAAE,MAAM,IAAIC,KAAK,CAAC,gDAAgD,CAAC;IAEtF,OAAO,IAAI,CAACD,SAAS,CAACsC,UAAU,CAAC,CAAC;EACpC;EAEAjB,qBAAqBA,CAAA,EAAmB;IACtC,OAAO9B,aAAa,CAACC,kBAAkB;EACzC;AACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Helper to convert Wei (as string or bigint) to ETH
|
|
2
|
+
export const formatEther = wei => {
|
|
3
|
+
return (Number(wei) / 1e18).toString();
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
// Raw JSON-RPC for balance lookup
|
|
7
|
+
export async function getEthBalance(rpcUrl, address) {
|
|
8
|
+
const body = {
|
|
9
|
+
jsonrpc: '2.0',
|
|
10
|
+
method: 'eth_getBalance',
|
|
11
|
+
params: [address, 'latest'],
|
|
12
|
+
id: 1
|
|
13
|
+
};
|
|
14
|
+
const response = await fetch(rpcUrl, {
|
|
15
|
+
method: 'POST',
|
|
16
|
+
headers: {
|
|
17
|
+
'Content-Type': 'application/json'
|
|
18
|
+
},
|
|
19
|
+
body: JSON.stringify(body)
|
|
20
|
+
});
|
|
21
|
+
const json = await response.json();
|
|
22
|
+
if (json.error) throw new Error(json.error.message);
|
|
23
|
+
return BigInt(json.result); // result is hex string
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["formatEther","wei","Number","toString","getEthBalance","rpcUrl","address","body","jsonrpc","method","params","id","response","fetch","headers","JSON","stringify","json","error","Error","message","BigInt","result"],"sourceRoot":"../../src","sources":["helpers.ts"],"mappings":"AAAA;AACA,OAAO,MAAMA,WAAW,GAAIC,GAAW,IAAa;EAClD,OAAO,CAACC,MAAM,CAACD,GAAG,CAAC,GAAG,IAAI,EAAEE,QAAQ,CAAC,CAAC;AACxC,CAAC;;AAED;AACA,OAAO,eAAeC,aAAaA,CAACC,MAAc,EAAEC,OAAe,EAAmB;EACpF,MAAMC,IAAI,GAAG;IACXC,OAAO,EAAE,KAAK;IACdC,MAAM,EAAE,gBAAgB;IACxBC,MAAM,EAAE,CAACJ,OAAO,EAAE,QAAQ,CAAC;IAC3BK,EAAE,EAAE;EACN,CAAC;EAED,MAAMC,QAAQ,GAAG,MAAMC,KAAK,CAACR,MAAM,EAAE;IACnCI,MAAM,EAAE,MAAM;IACdK,OAAO,EAAE;MAAE,cAAc,EAAE;IAAmB,CAAC;IAC/CP,IAAI,EAAEQ,IAAI,CAACC,SAAS,CAACT,IAAI;EAC3B,CAAC,CAAC;EAEF,MAAMU,IAAI,GAAG,MAAML,QAAQ,CAACK,IAAI,CAAC,CAAC;EAClC,IAAIA,IAAI,CAACC,KAAK,EAAE,MAAM,IAAIC,KAAK,CAACF,IAAI,CAACC,KAAK,CAACE,OAAO,CAAC;EAEnD,OAAOC,MAAM,CAACJ,IAAI,CAACK,MAAM,CAAC,CAAC,CAAC;AAC9B"}
|
|
@@ -8,7 +8,6 @@ export declare class EthersAdapter extends EVMAdapter {
|
|
|
8
8
|
switchNetwork(network: AppKitNetwork): Promise<void>;
|
|
9
9
|
getAccounts(): CaipAddress[] | undefined;
|
|
10
10
|
disconnect(): Promise<void>;
|
|
11
|
-
request(method: string, params?: any[]): Promise<unknown>;
|
|
12
11
|
getSupportedNamespace(): ChainNamespace;
|
|
13
12
|
}
|
|
14
13
|
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACxB,MAAM,mCAAmC,CAAC;AAI3C,qBAAa,aAAc,SAAQ,UAAU;IAC3C,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAA4B;gBAEjD,YAAY,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE;IAOzC,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAoCjE,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB1D,WAAW,IAAI,WAAW,EAAE,GAAG,SAAS;IAOxC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAM3B,qBAAqB,IAAI,cAAc;CAGxC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW,QAAS,MAAM,KAAG,MAEzC,CAAC;AAGF,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAkBpF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reown/appkit-ethers-react-native",
|
|
3
|
-
"version": "0.0.0-feat-multichain-
|
|
3
|
+
"version": "0.0.0-feat-multichain-20250516115442",
|
|
4
4
|
"main": "lib/commonjs/index.js",
|
|
5
5
|
"types": "lib/typescript/index.d.ts",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -38,23 +38,19 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@reown/appkit-common-react-native": "0.0.0-feat-multichain-
|
|
42
|
-
"@reown/appkit-react-native": "0.0.0-feat-multichain-
|
|
43
|
-
"@reown/appkit-scaffold-utils-react-native": "0.0.0-feat-multichain-
|
|
44
|
-
"@reown/appkit-siwe-react-native": "0.0.0-feat-multichain-
|
|
41
|
+
"@reown/appkit-common-react-native": "0.0.0-feat-multichain-20250516115442",
|
|
42
|
+
"@reown/appkit-react-native": "0.0.0-feat-multichain-20250516115442",
|
|
43
|
+
"@reown/appkit-scaffold-utils-react-native": "0.0.0-feat-multichain-20250516115442",
|
|
44
|
+
"@reown/appkit-siwe-react-native": "0.0.0-feat-multichain-20250516115442",
|
|
45
45
|
"@walletconnect/ethereum-provider": "2.20.2"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@react-native-async-storage/async-storage": ">=1.17.0",
|
|
49
49
|
"@react-native-community/netinfo": "*",
|
|
50
50
|
"@walletconnect/react-native-compat": ">=2.13.1",
|
|
51
|
-
"ethers": ">=6.0.0",
|
|
52
51
|
"react": ">=17",
|
|
53
52
|
"react-native": ">=0.68.5",
|
|
54
53
|
"react-native-get-random-values": "*"
|
|
55
54
|
},
|
|
56
|
-
"devDependencies": {
|
|
57
|
-
"ethers": "6.10.0"
|
|
58
|
-
},
|
|
59
55
|
"react-native": "src/index.tsx"
|
|
60
56
|
}
|
package/src/adapter.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { formatEther, JsonRpcProvider } from 'ethers';
|
|
2
1
|
import {
|
|
3
2
|
EVMAdapter,
|
|
4
3
|
type AppKitNetwork,
|
|
@@ -8,6 +7,7 @@ import {
|
|
|
8
7
|
type GetBalanceResponse
|
|
9
8
|
} from '@reown/appkit-common-react-native';
|
|
10
9
|
import { EthersHelpersUtil } from '@reown/appkit-scaffold-utils-react-native';
|
|
10
|
+
import { formatEther, getEthBalance } from './helpers';
|
|
11
11
|
|
|
12
12
|
export class EthersAdapter extends EVMAdapter {
|
|
13
13
|
private static supportedNamespace: ChainNamespace = 'eip155';
|
|
@@ -28,26 +28,20 @@ export class EthersAdapter extends EVMAdapter {
|
|
|
28
28
|
const balanceAddress =
|
|
29
29
|
address || this.getAccounts()?.find(account => account.includes(network.id.toString()));
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
const balance: GetBalanceResponse = {
|
|
32
|
+
amount: '0.00',
|
|
33
|
+
symbol: network.nativeCurrency.symbol || 'ETH'
|
|
34
|
+
};
|
|
32
35
|
|
|
33
|
-
if (!balanceAddress)
|
|
34
|
-
return Promise.resolve(balance);
|
|
35
|
-
}
|
|
36
|
+
if (!balanceAddress) return balance;
|
|
36
37
|
|
|
37
38
|
const account = balanceAddress.split(':')[2];
|
|
39
|
+
const rpcUrl = network.rpcUrls.default.http?.[0];
|
|
40
|
+
if (!rpcUrl || !account) return balance;
|
|
38
41
|
|
|
39
42
|
try {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
name: network.name
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
if (jsonRpcProvider && account) {
|
|
46
|
-
const _balance = await jsonRpcProvider.getBalance(account);
|
|
47
|
-
const formattedBalance = formatEther(_balance);
|
|
48
|
-
|
|
49
|
-
balance = { amount: formattedBalance, symbol: network.nativeCurrency.symbol || 'ETH' };
|
|
50
|
-
}
|
|
43
|
+
const wei = await getEthBalance(rpcUrl, account);
|
|
44
|
+
balance.amount = formatEther(wei);
|
|
51
45
|
|
|
52
46
|
this.emit('balanceChanged', {
|
|
53
47
|
namespace: this.getSupportedNamespace(),
|
|
@@ -56,7 +50,7 @@ export class EthersAdapter extends EVMAdapter {
|
|
|
56
50
|
});
|
|
57
51
|
|
|
58
52
|
return balance;
|
|
59
|
-
} catch
|
|
53
|
+
} catch {
|
|
60
54
|
return balance;
|
|
61
55
|
}
|
|
62
56
|
}
|
|
@@ -98,13 +92,6 @@ export class EthersAdapter extends EVMAdapter {
|
|
|
98
92
|
return this.connector.disconnect();
|
|
99
93
|
}
|
|
100
94
|
|
|
101
|
-
async request(method: string, params?: any[]) {
|
|
102
|
-
if (!this.connector) throw new Error('No active connector');
|
|
103
|
-
const provider = this.connector.getProvider();
|
|
104
|
-
|
|
105
|
-
return provider.request({ method, params });
|
|
106
|
-
}
|
|
107
|
-
|
|
108
95
|
getSupportedNamespace(): ChainNamespace {
|
|
109
96
|
return EthersAdapter.supportedNamespace;
|
|
110
97
|
}
|
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Helper to convert Wei (as string or bigint) to ETH
|
|
2
|
+
export const formatEther = (wei: bigint): string => {
|
|
3
|
+
return (Number(wei) / 1e18).toString();
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
// Raw JSON-RPC for balance lookup
|
|
7
|
+
export async function getEthBalance(rpcUrl: string, address: string): Promise<bigint> {
|
|
8
|
+
const body = {
|
|
9
|
+
jsonrpc: '2.0',
|
|
10
|
+
method: 'eth_getBalance',
|
|
11
|
+
params: [address, 'latest'],
|
|
12
|
+
id: 1
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const response = await fetch(rpcUrl, {
|
|
16
|
+
method: 'POST',
|
|
17
|
+
headers: { 'Content-Type': 'application/json' },
|
|
18
|
+
body: JSON.stringify(body)
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const json = await response.json();
|
|
22
|
+
if (json.error) throw new Error(json.error.message);
|
|
23
|
+
|
|
24
|
+
return BigInt(json.result); // result is hex string
|
|
25
|
+
}
|