@reown/appkit-ethers-react-native 0.0.0-fix-token-balance-20241017200828 → 0.0.0-fix-fetch-error-improvements-20241114124235
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/package.json +6 -6
- package/src/client.ts +52 -10
- package/lib/commonjs/client.js +0 -753
- package/lib/commonjs/client.js.map +0 -1
- package/lib/commonjs/index.js +0 -170
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/utils/defaultConfig.js +0 -18
- package/lib/commonjs/utils/defaultConfig.js.map +0 -1
- package/lib/commonjs/utils/helpers.js +0 -27
- package/lib/commonjs/utils/helpers.js.map +0 -1
- package/lib/module/client.js +0 -745
- package/lib/module/client.js.map +0 -1
- package/lib/module/index.js +0 -121
- package/lib/module/index.js.map +0 -1
- package/lib/module/utils/defaultConfig.js +0 -12
- package/lib/module/utils/defaultConfig.js.map +0 -1
- package/lib/module/utils/helpers.js +0 -20
- package/lib/module/utils/helpers.js.map +0 -1
- package/lib/typescript/client.d.ts +0 -61
- package/lib/typescript/client.d.ts.map +0 -1
- package/lib/typescript/index.d.ts +0 -39
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/utils/defaultConfig.d.ts +0 -7
- package/lib/typescript/utils/defaultConfig.d.ts.map +0 -1
- package/lib/typescript/utils/helpers.d.ts +0 -10
- package/lib/typescript/utils/helpers.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reown/appkit-ethers-react-native",
|
|
3
|
-
"version": "0.0.0-fix-
|
|
3
|
+
"version": "0.0.0-fix-fetch-error-improvements-20241114124235",
|
|
4
4
|
"main": "lib/commonjs/index.js",
|
|
5
5
|
"types": "lib/typescript/index.d.ts",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@reown/appkit-common-react-native": "0.0.0-fix-
|
|
42
|
-
"@reown/appkit-scaffold-react-native": "0.0.0-fix-
|
|
43
|
-
"@reown/appkit-scaffold-utils-react-native": "0.0.0-fix-
|
|
44
|
-
"@reown/appkit-siwe-react-native": "0.0.0-fix-
|
|
45
|
-
"@walletconnect/ethereum-provider": "2.
|
|
41
|
+
"@reown/appkit-common-react-native": "0.0.0-fix-fetch-error-improvements-20241114124235",
|
|
42
|
+
"@reown/appkit-scaffold-react-native": "0.0.0-fix-fetch-error-improvements-20241114124235",
|
|
43
|
+
"@reown/appkit-scaffold-utils-react-native": "0.0.0-fix-fetch-error-improvements-20241114124235",
|
|
44
|
+
"@reown/appkit-siwe-react-native": "0.0.0-fix-fetch-error-improvements-20241114124235",
|
|
45
|
+
"@walletconnect/ethereum-provider": "2.17.2"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@react-native-async-storage/async-storage": ">=1.17.0",
|
package/src/client.ts
CHANGED
|
@@ -24,9 +24,10 @@ import {
|
|
|
24
24
|
type SendTransactionArgs,
|
|
25
25
|
type Token,
|
|
26
26
|
AppKitScaffold,
|
|
27
|
-
type WriteContractArgs
|
|
27
|
+
type WriteContractArgs,
|
|
28
|
+
type AppKitFrameAccountType
|
|
28
29
|
} from '@reown/appkit-scaffold-react-native';
|
|
29
|
-
import { erc20ABI, NamesUtil, NetworkUtil } from '@reown/appkit-common-react-native';
|
|
30
|
+
import { erc20ABI, ErrorUtil, NamesUtil, NetworkUtil } from '@reown/appkit-common-react-native';
|
|
30
31
|
import {
|
|
31
32
|
ConstantsUtil,
|
|
32
33
|
PresetsUtil,
|
|
@@ -46,6 +47,7 @@ import {
|
|
|
46
47
|
} from '@reown/appkit-scaffold-utils-react-native';
|
|
47
48
|
import EthereumProvider, { OPTIONAL_METHODS } from '@walletconnect/ethereum-provider';
|
|
48
49
|
import type { EthereumProviderOptions } from '@walletconnect/ethereum-provider';
|
|
50
|
+
import { type JsonRpcError } from '@walletconnect/jsonrpc-types';
|
|
49
51
|
|
|
50
52
|
import { getAuthCaipNetworks, getWalletConnectCaipNetworks } from './utils/helpers';
|
|
51
53
|
import type { AppKitSIWEClient } from '@reown/appkit-siwe-react-native';
|
|
@@ -107,7 +109,7 @@ export class AppKit extends AppKitScaffold {
|
|
|
107
109
|
}
|
|
108
110
|
|
|
109
111
|
if (!appKitOptions.projectId) {
|
|
110
|
-
throw new Error(
|
|
112
|
+
throw new Error(ErrorUtil.ALERT_ERRORS.PROJECT_ID_NOT_CONFIGURED.shortMessage);
|
|
111
113
|
}
|
|
112
114
|
|
|
113
115
|
const networkControllerClient: NetworkControllerClient = {
|
|
@@ -126,9 +128,9 @@ export class AppKit extends AppKitScaffold {
|
|
|
126
128
|
new Promise(async resolve => {
|
|
127
129
|
const walletChoice = await StorageUtil.getConnectedConnector();
|
|
128
130
|
const walletConnectType =
|
|
129
|
-
PresetsUtil.ConnectorTypesMap[ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID]
|
|
131
|
+
PresetsUtil.ConnectorTypesMap[ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID]!;
|
|
130
132
|
|
|
131
|
-
const authType = PresetsUtil.ConnectorTypesMap[ConstantsUtil.AUTH_CONNECTOR_ID]
|
|
133
|
+
const authType = PresetsUtil.ConnectorTypesMap[ConstantsUtil.AUTH_CONNECTOR_ID]!;
|
|
132
134
|
if (walletChoice?.includes(walletConnectType)) {
|
|
133
135
|
const provider = await this.getWalletConnectProvider();
|
|
134
136
|
const result = getWalletConnectCaipNetworks(provider);
|
|
@@ -399,8 +401,8 @@ export class AppKit extends AppKitScaffold {
|
|
|
399
401
|
|
|
400
402
|
this.createProvider();
|
|
401
403
|
|
|
402
|
-
EthersStoreUtil.subscribeKey('address',
|
|
403
|
-
this.syncAccount();
|
|
404
|
+
EthersStoreUtil.subscribeKey('address', address => {
|
|
405
|
+
this.syncAccount({ address });
|
|
404
406
|
});
|
|
405
407
|
|
|
406
408
|
EthersStoreUtil.subscribeKey('chainId', () => {
|
|
@@ -505,6 +507,7 @@ export class AppKit extends AppKitScaffold {
|
|
|
505
507
|
};
|
|
506
508
|
|
|
507
509
|
this.walletConnectProvider = await EthereumProvider.init(walletConnectProviderOptions);
|
|
510
|
+
this.addWalletConnectListeners(this.walletConnectProvider);
|
|
508
511
|
|
|
509
512
|
await this.checkActiveWalletConnectProvider();
|
|
510
513
|
}
|
|
@@ -681,12 +684,10 @@ export class AppKit extends AppKitScaffold {
|
|
|
681
684
|
}
|
|
682
685
|
}
|
|
683
686
|
|
|
684
|
-
private async syncAccount() {
|
|
685
|
-
const address = EthersStoreUtil.state.address;
|
|
687
|
+
private async syncAccount({ address }: { address?: Address }) {
|
|
686
688
|
const chainId = EthersStoreUtil.state.chainId;
|
|
687
689
|
const isConnected = EthersStoreUtil.state.isConnected;
|
|
688
690
|
|
|
689
|
-
this.resetAccount();
|
|
690
691
|
if (isConnected && address && chainId) {
|
|
691
692
|
const caipAddress: CaipAddress = `${ConstantsUtil.EIP155}:${chainId}:${address}`;
|
|
692
693
|
|
|
@@ -701,6 +702,7 @@ export class AppKit extends AppKitScaffold {
|
|
|
701
702
|
]);
|
|
702
703
|
this.hasSyncedConnectedAccount = true;
|
|
703
704
|
} else if (!isConnected && this.hasSyncedConnectedAccount) {
|
|
705
|
+
this.resetAccount();
|
|
704
706
|
this.resetWcConnection();
|
|
705
707
|
this.resetNetwork();
|
|
706
708
|
}
|
|
@@ -874,6 +876,20 @@ export class AppKit extends AppKitScaffold {
|
|
|
874
876
|
}
|
|
875
877
|
}
|
|
876
878
|
|
|
879
|
+
private async handleAuthSetPreferredAccount(address: string, type: AppKitFrameAccountType) {
|
|
880
|
+
if (!address) {
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
const chainId = this.getCaipNetwork()?.id;
|
|
885
|
+
const caipAddress: CaipAddress = `${ConstantsUtil.EIP155}:${chainId}:${address}`;
|
|
886
|
+
this.setCaipAddress(caipAddress);
|
|
887
|
+
this.setPreferredAccountType(type);
|
|
888
|
+
|
|
889
|
+
await this.syncAccount({ address: address as Address });
|
|
890
|
+
this.setLoading(false);
|
|
891
|
+
}
|
|
892
|
+
|
|
877
893
|
private syncConnectors(config: ProviderType) {
|
|
878
894
|
const _connectors: Connector[] = [];
|
|
879
895
|
const EXCLUDED_CONNECTORS = [ConstantsUtil.AUTH_CONNECTOR_ID];
|
|
@@ -932,6 +948,7 @@ export class AppKit extends AppKitScaffold {
|
|
|
932
948
|
|
|
933
949
|
const connectedConnector = await StorageUtil.getItem('@w3m/connected_connector');
|
|
934
950
|
if (connectedConnector === 'AUTH') {
|
|
951
|
+
// Set loader until it reconnects
|
|
935
952
|
this.setLoading(true);
|
|
936
953
|
}
|
|
937
954
|
|
|
@@ -939,5 +956,30 @@ export class AppKit extends AppKitScaffold {
|
|
|
939
956
|
if (isConnected) {
|
|
940
957
|
this.setAuthProvider();
|
|
941
958
|
}
|
|
959
|
+
|
|
960
|
+
this.addAuthListeners(this.authProvider);
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
private async addAuthListeners(authProvider: AppKitFrameProvider) {
|
|
964
|
+
authProvider.onSetPreferredAccount(async ({ address, type }) => {
|
|
965
|
+
if (address) {
|
|
966
|
+
await this.handleAuthSetPreferredAccount(address, type);
|
|
967
|
+
}
|
|
968
|
+
this.setLoading(false);
|
|
969
|
+
});
|
|
970
|
+
|
|
971
|
+
authProvider.setOnTimeout(async () => {
|
|
972
|
+
this.handleAlertError(ErrorUtil.ALERT_ERRORS.SOCIALS_TIMEOUT);
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
private async addWalletConnectListeners(provider: EthereumProvider) {
|
|
977
|
+
if (provider) {
|
|
978
|
+
provider.signer.client.core.relayer.provider.on('payload', (payload: JsonRpcError) => {
|
|
979
|
+
if (payload?.error) {
|
|
980
|
+
this.handleAlertError(payload?.error.message);
|
|
981
|
+
}
|
|
982
|
+
});
|
|
983
|
+
}
|
|
942
984
|
}
|
|
943
985
|
}
|