@reown/appkit-ethers-react-native 0.0.0-feat-wallet-features-20240925132010 → 0.0.0-refactor-modal-migration-20241003185737
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 +5 -5
- package/lib/commonjs/client.js +0 -740
- 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 -732
- 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/lib/commonjs/client.js
DELETED
|
@@ -1,740 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.AppKit = void 0;
|
|
7
|
-
var _ethers = require("ethers");
|
|
8
|
-
var _appkitScaffoldReactNative = require("@reown/appkit-scaffold-react-native");
|
|
9
|
-
var _appkitCommonReactNative = require("@reown/appkit-common-react-native");
|
|
10
|
-
var _appkitScaffoldUtilsReactNative = require("@reown/appkit-scaffold-utils-react-native");
|
|
11
|
-
var _ethereumProvider = _interopRequireWildcard(require("@walletconnect/ethereum-provider"));
|
|
12
|
-
var _helpers = require("./utils/helpers");
|
|
13
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
|
-
// -- Types ---------------------------------------------------------------------
|
|
16
|
-
|
|
17
|
-
// @ts-expect-error: Overriden state type is correct
|
|
18
|
-
|
|
19
|
-
// -- Client --------------------------------------------------------------------
|
|
20
|
-
class AppKit extends _appkitScaffoldReactNative.AppKitScaffold {
|
|
21
|
-
hasSyncedConnectedAccount = false;
|
|
22
|
-
options = undefined;
|
|
23
|
-
constructor(options) {
|
|
24
|
-
const {
|
|
25
|
-
config,
|
|
26
|
-
siweConfig,
|
|
27
|
-
chains,
|
|
28
|
-
defaultChain,
|
|
29
|
-
tokens,
|
|
30
|
-
chainImages,
|
|
31
|
-
_sdkVersion,
|
|
32
|
-
...appKitOptions
|
|
33
|
-
} = options;
|
|
34
|
-
if (!config) {
|
|
35
|
-
throw new Error('appkit:constructor - config is undefined');
|
|
36
|
-
}
|
|
37
|
-
if (!appKitOptions.projectId) {
|
|
38
|
-
throw new Error('appkit:constructor - projectId is undefined');
|
|
39
|
-
}
|
|
40
|
-
const networkControllerClient = {
|
|
41
|
-
switchCaipNetwork: async caipNetwork => {
|
|
42
|
-
const chainId = _appkitCommonReactNative.NetworkUtil.caipNetworkIdToNumber(caipNetwork?.id);
|
|
43
|
-
if (chainId) {
|
|
44
|
-
try {
|
|
45
|
-
await this.switchNetwork(chainId);
|
|
46
|
-
} catch (error) {
|
|
47
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setError(error);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
getApprovedCaipNetworksData: async () => new Promise(async resolve => {
|
|
52
|
-
const walletChoice = await _appkitScaffoldUtilsReactNative.StorageUtil.getConnectedConnector();
|
|
53
|
-
const walletConnectType = _appkitScaffoldUtilsReactNative.PresetsUtil.ConnectorTypesMap[_appkitScaffoldUtilsReactNative.ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID];
|
|
54
|
-
const authType = _appkitScaffoldUtilsReactNative.PresetsUtil.ConnectorTypesMap[_appkitScaffoldUtilsReactNative.ConstantsUtil.AUTH_CONNECTOR_ID];
|
|
55
|
-
if (walletChoice?.includes(walletConnectType)) {
|
|
56
|
-
const provider = await this.getWalletConnectProvider();
|
|
57
|
-
const result = (0, _helpers.getWalletConnectCaipNetworks)(provider);
|
|
58
|
-
resolve(result);
|
|
59
|
-
} else if (walletChoice?.includes(authType)) {
|
|
60
|
-
const result = (0, _helpers.getAuthCaipNetworks)();
|
|
61
|
-
resolve(result);
|
|
62
|
-
} else {
|
|
63
|
-
const result = {
|
|
64
|
-
approvedCaipNetworkIds: undefined,
|
|
65
|
-
supportsAllNetworks: true
|
|
66
|
-
};
|
|
67
|
-
resolve(result);
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
};
|
|
71
|
-
const connectionControllerClient = {
|
|
72
|
-
connectWalletConnect: async onUri => {
|
|
73
|
-
const WalletConnectProvider = await this.getWalletConnectProvider();
|
|
74
|
-
if (!WalletConnectProvider) {
|
|
75
|
-
throw new Error('connectionControllerClient:getWalletConnectUri - provider is undefined');
|
|
76
|
-
}
|
|
77
|
-
WalletConnectProvider.on('display_uri', uri => {
|
|
78
|
-
onUri(uri);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// When connecting through walletconnect, we need to set the clientId in the store
|
|
82
|
-
const clientId = await WalletConnectProvider.signer?.client?.core?.crypto?.getClientId();
|
|
83
|
-
if (clientId) {
|
|
84
|
-
this.setClientId(clientId);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// SIWE
|
|
88
|
-
const params = await siweConfig?.getMessageParams?.();
|
|
89
|
-
if (siweConfig?.options?.enabled && params && Object.keys(params).length > 0) {
|
|
90
|
-
const {
|
|
91
|
-
SIWEController,
|
|
92
|
-
getDidChainId,
|
|
93
|
-
getDidAddress
|
|
94
|
-
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@reown/appkit-siwe-react-native')));
|
|
95
|
-
const result = await WalletConnectProvider.authenticate({
|
|
96
|
-
nonce: await siweConfig.getNonce(),
|
|
97
|
-
methods: _ethereumProvider.OPTIONAL_METHODS,
|
|
98
|
-
...params
|
|
99
|
-
});
|
|
100
|
-
// Auths is an array of signed CACAO objects https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-74.md
|
|
101
|
-
const signedCacao = result?.auths?.[0];
|
|
102
|
-
if (signedCacao) {
|
|
103
|
-
const {
|
|
104
|
-
p,
|
|
105
|
-
s
|
|
106
|
-
} = signedCacao;
|
|
107
|
-
const chainId = getDidChainId(p.iss);
|
|
108
|
-
const address = getDidAddress(p.iss);
|
|
109
|
-
try {
|
|
110
|
-
// Kicks off verifyMessage and populates external states
|
|
111
|
-
const message = WalletConnectProvider.signer.client.formatAuthMessage({
|
|
112
|
-
request: p,
|
|
113
|
-
iss: p.iss
|
|
114
|
-
});
|
|
115
|
-
await SIWEController.verifyMessage({
|
|
116
|
-
message,
|
|
117
|
-
signature: s.s,
|
|
118
|
-
cacao: signedCacao
|
|
119
|
-
});
|
|
120
|
-
if (address && chainId) {
|
|
121
|
-
const session = {
|
|
122
|
-
address,
|
|
123
|
-
chainId: parseInt(chainId, 10)
|
|
124
|
-
};
|
|
125
|
-
SIWEController.setSession(session);
|
|
126
|
-
SIWEController.onSignIn?.(session);
|
|
127
|
-
}
|
|
128
|
-
} catch (error) {
|
|
129
|
-
// eslint-disable-next-line no-console
|
|
130
|
-
console.error('Error verifying message', error);
|
|
131
|
-
// eslint-disable-next-line no-console
|
|
132
|
-
await WalletConnectProvider.disconnect().catch(console.error);
|
|
133
|
-
// eslint-disable-next-line no-console
|
|
134
|
-
await SIWEController.signOut().catch(console.error);
|
|
135
|
-
throw error;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
} else {
|
|
139
|
-
await WalletConnectProvider.connect();
|
|
140
|
-
}
|
|
141
|
-
await this.setWalletConnectProvider();
|
|
142
|
-
},
|
|
143
|
-
// @ts-expect-error TODO expected types in arguments are incomplete
|
|
144
|
-
connectExternal: async ({
|
|
145
|
-
id
|
|
146
|
-
}) => {
|
|
147
|
-
// If connecting with something else than walletconnect, we need to clear the clientId in the store
|
|
148
|
-
this.setClientId(null);
|
|
149
|
-
if (id === _appkitScaffoldUtilsReactNative.ConstantsUtil.COINBASE_CONNECTOR_ID) {
|
|
150
|
-
const coinbaseProvider = config.extraConnectors?.find(connector => connector.id === id);
|
|
151
|
-
if (!coinbaseProvider) {
|
|
152
|
-
throw new Error('connectionControllerClient:connectCoinbase - connector is undefined');
|
|
153
|
-
}
|
|
154
|
-
try {
|
|
155
|
-
await coinbaseProvider.request({
|
|
156
|
-
method: 'eth_requestAccounts'
|
|
157
|
-
});
|
|
158
|
-
await this.setCoinbaseProvider(coinbaseProvider);
|
|
159
|
-
} catch (error) {
|
|
160
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setError(error);
|
|
161
|
-
}
|
|
162
|
-
} else if (id === _appkitScaffoldUtilsReactNative.ConstantsUtil.AUTH_CONNECTOR_ID) {
|
|
163
|
-
await this.setAuthProvider();
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
disconnect: async () => {
|
|
167
|
-
const provider = _appkitScaffoldUtilsReactNative.EthersStoreUtil.state.provider;
|
|
168
|
-
const providerType = _appkitScaffoldUtilsReactNative.EthersStoreUtil.state.providerType;
|
|
169
|
-
const walletConnectType = _appkitScaffoldUtilsReactNative.PresetsUtil.ConnectorTypesMap[_appkitScaffoldUtilsReactNative.ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID];
|
|
170
|
-
const authType = _appkitScaffoldUtilsReactNative.PresetsUtil.ConnectorTypesMap[_appkitScaffoldUtilsReactNative.ConstantsUtil.AUTH_CONNECTOR_ID];
|
|
171
|
-
if (siweConfig?.options?.signOutOnDisconnect) {
|
|
172
|
-
const {
|
|
173
|
-
SIWEController
|
|
174
|
-
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@reown/appkit-siwe-react-native')));
|
|
175
|
-
await SIWEController.signOut();
|
|
176
|
-
}
|
|
177
|
-
if (providerType === walletConnectType) {
|
|
178
|
-
const WalletConnectProvider = provider;
|
|
179
|
-
await WalletConnectProvider.disconnect();
|
|
180
|
-
} else if (providerType === authType) {
|
|
181
|
-
await this.authProvider?.disconnect();
|
|
182
|
-
} else if (provider) {
|
|
183
|
-
provider.emit('disconnect');
|
|
184
|
-
}
|
|
185
|
-
_appkitScaffoldUtilsReactNative.StorageUtil.removeItem(_appkitScaffoldUtilsReactNative.EthersConstantsUtil.WALLET_ID);
|
|
186
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.reset();
|
|
187
|
-
this.setClientId(null);
|
|
188
|
-
},
|
|
189
|
-
signMessage: async message => {
|
|
190
|
-
const provider = _appkitScaffoldUtilsReactNative.EthersStoreUtil.state.provider;
|
|
191
|
-
if (!provider) {
|
|
192
|
-
throw new Error('connectionControllerClient:signMessage - provider is undefined');
|
|
193
|
-
}
|
|
194
|
-
const hexMessage = (0, _ethers.isHexString)(message) ? message : (0, _ethers.hexlify)((0, _ethers.toUtf8Bytes)(message));
|
|
195
|
-
const signature = await provider.request({
|
|
196
|
-
method: 'personal_sign',
|
|
197
|
-
params: [hexMessage, this.getAddress()]
|
|
198
|
-
});
|
|
199
|
-
return signature;
|
|
200
|
-
},
|
|
201
|
-
parseUnits: (value, decimals) => (0, _ethers.parseUnits)(value, decimals),
|
|
202
|
-
formatUnits: (value, decimals) => (0, _ethers.formatUnits)(value, decimals),
|
|
203
|
-
sendTransaction: async data => {
|
|
204
|
-
const {
|
|
205
|
-
chainId,
|
|
206
|
-
provider,
|
|
207
|
-
address
|
|
208
|
-
} = _appkitScaffoldUtilsReactNative.EthersStoreUtil.state;
|
|
209
|
-
if (!provider) {
|
|
210
|
-
throw new Error('ethersClient:sendTransaction - provider is undefined');
|
|
211
|
-
}
|
|
212
|
-
if (!address) {
|
|
213
|
-
throw new Error('ethersClient:sendTransaction - address is undefined');
|
|
214
|
-
}
|
|
215
|
-
const txParams = {
|
|
216
|
-
to: data.to,
|
|
217
|
-
value: data.value,
|
|
218
|
-
gasLimit: data.gas,
|
|
219
|
-
gasPrice: data.gasPrice,
|
|
220
|
-
data: data.data,
|
|
221
|
-
type: 0
|
|
222
|
-
};
|
|
223
|
-
const browserProvider = new _ethers.BrowserProvider(provider, chainId);
|
|
224
|
-
const signer = new _ethers.JsonRpcSigner(browserProvider, address);
|
|
225
|
-
const txResponse = await signer.sendTransaction(txParams);
|
|
226
|
-
const txReceipt = await txResponse.wait();
|
|
227
|
-
return txReceipt?.hash || null;
|
|
228
|
-
},
|
|
229
|
-
writeContract: async data => {
|
|
230
|
-
const {
|
|
231
|
-
chainId,
|
|
232
|
-
provider,
|
|
233
|
-
address
|
|
234
|
-
} = _appkitScaffoldUtilsReactNative.EthersStoreUtil.state;
|
|
235
|
-
if (!provider) {
|
|
236
|
-
throw new Error('ethersClient:writeContract - provider is undefined');
|
|
237
|
-
}
|
|
238
|
-
if (!address) {
|
|
239
|
-
throw new Error('ethersClient:writeContract - address is undefined');
|
|
240
|
-
}
|
|
241
|
-
const browserProvider = new _ethers.BrowserProvider(provider, chainId);
|
|
242
|
-
const signer = new _ethers.JsonRpcSigner(browserProvider, address);
|
|
243
|
-
const contract = new _ethers.Contract(data.tokenAddress, data.abi, signer);
|
|
244
|
-
if (!contract || !data.method) {
|
|
245
|
-
throw new Error('Contract method is undefined');
|
|
246
|
-
}
|
|
247
|
-
const method = contract[data.method];
|
|
248
|
-
if (method) {
|
|
249
|
-
const tx = await method(data.receiverAddress, data.tokenAmount);
|
|
250
|
-
return tx;
|
|
251
|
-
}
|
|
252
|
-
throw new Error('Contract method is undefined');
|
|
253
|
-
},
|
|
254
|
-
getEnsAddress: async value => {
|
|
255
|
-
try {
|
|
256
|
-
const chainId = Number(this.getCaipNetwork()?.id);
|
|
257
|
-
let ensName = null;
|
|
258
|
-
let wcName = false;
|
|
259
|
-
if (_appkitCommonReactNative.NamesUtil.isReownName(value)) {
|
|
260
|
-
wcName = (await this?.resolveReownName(value)) || false;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// If on mainnet, fetch from ENS
|
|
264
|
-
if (chainId === 1) {
|
|
265
|
-
const ensProvider = new _ethers.InfuraProvider('mainnet');
|
|
266
|
-
ensName = await ensProvider.resolveName(value);
|
|
267
|
-
}
|
|
268
|
-
return ensName || wcName || false;
|
|
269
|
-
} catch {
|
|
270
|
-
return false;
|
|
271
|
-
}
|
|
272
|
-
},
|
|
273
|
-
getEnsAvatar: async value => {
|
|
274
|
-
const chainId = Number(_appkitCommonReactNative.NetworkUtil.caipNetworkIdToNumber(this.getCaipNetwork()?.id));
|
|
275
|
-
if (chainId === 1) {
|
|
276
|
-
const ensProvider = new _ethers.InfuraProvider('mainnet');
|
|
277
|
-
const avatar = await ensProvider.getAvatar(value);
|
|
278
|
-
return avatar || false;
|
|
279
|
-
}
|
|
280
|
-
return false;
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
super({
|
|
284
|
-
networkControllerClient,
|
|
285
|
-
connectionControllerClient,
|
|
286
|
-
siweControllerClient: siweConfig,
|
|
287
|
-
defaultChain: _appkitScaffoldUtilsReactNative.EthersHelpersUtil.getCaipDefaultChain(defaultChain),
|
|
288
|
-
tokens: _appkitScaffoldUtilsReactNative.HelpersUtil.getCaipTokens(tokens),
|
|
289
|
-
_sdkVersion: _sdkVersion ?? `react-native-ethers-${_appkitScaffoldUtilsReactNative.ConstantsUtil.VERSION}`,
|
|
290
|
-
...appKitOptions
|
|
291
|
-
});
|
|
292
|
-
this.options = options;
|
|
293
|
-
this.metadata = config.metadata;
|
|
294
|
-
this.projectId = appKitOptions.projectId;
|
|
295
|
-
this.chains = chains;
|
|
296
|
-
this.createProvider();
|
|
297
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.subscribeKey('address', () => {
|
|
298
|
-
this.syncAccount();
|
|
299
|
-
});
|
|
300
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.subscribeKey('chainId', () => {
|
|
301
|
-
this.syncNetwork(chainImages);
|
|
302
|
-
});
|
|
303
|
-
this.syncRequestedNetworks(chains, chainImages);
|
|
304
|
-
this.syncConnectors(config);
|
|
305
|
-
this.syncAuthConnector(config);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// -- Public ------------------------------------------------------------------
|
|
309
|
-
|
|
310
|
-
// @ts-expect-error: Overriden state type is correct
|
|
311
|
-
getState() {
|
|
312
|
-
const state = super.getState();
|
|
313
|
-
return {
|
|
314
|
-
...state,
|
|
315
|
-
selectedNetworkId: _appkitCommonReactNative.NetworkUtil.caipNetworkIdToNumber(state.selectedNetworkId)
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// @ts-expect-error: Overriden state type is correct
|
|
320
|
-
subscribeState(callback) {
|
|
321
|
-
return super.subscribeState(state => callback({
|
|
322
|
-
...state,
|
|
323
|
-
selectedNetworkId: _appkitCommonReactNative.NetworkUtil.caipNetworkIdToNumber(state.selectedNetworkId)
|
|
324
|
-
}));
|
|
325
|
-
}
|
|
326
|
-
setAddress(address) {
|
|
327
|
-
const originalAddress = address ? (0, _ethers.getAddress)(address) : undefined;
|
|
328
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setAddress(originalAddress);
|
|
329
|
-
}
|
|
330
|
-
getAddress() {
|
|
331
|
-
const {
|
|
332
|
-
address
|
|
333
|
-
} = _appkitScaffoldUtilsReactNative.EthersStoreUtil.state;
|
|
334
|
-
return address ? (0, _ethers.getAddress)(address) : address;
|
|
335
|
-
}
|
|
336
|
-
getError() {
|
|
337
|
-
return _appkitScaffoldUtilsReactNative.EthersStoreUtil.state.error;
|
|
338
|
-
}
|
|
339
|
-
getChainId() {
|
|
340
|
-
return _appkitScaffoldUtilsReactNative.EthersStoreUtil.state.chainId;
|
|
341
|
-
}
|
|
342
|
-
getIsConnected() {
|
|
343
|
-
return _appkitScaffoldUtilsReactNative.EthersStoreUtil.state.isConnected;
|
|
344
|
-
}
|
|
345
|
-
getWalletProvider() {
|
|
346
|
-
return _appkitScaffoldUtilsReactNative.EthersStoreUtil.state.provider;
|
|
347
|
-
}
|
|
348
|
-
getWalletProviderType() {
|
|
349
|
-
return _appkitScaffoldUtilsReactNative.EthersStoreUtil.state.providerType;
|
|
350
|
-
}
|
|
351
|
-
subscribeProvider(callback) {
|
|
352
|
-
return _appkitScaffoldUtilsReactNative.EthersStoreUtil.subscribe(callback);
|
|
353
|
-
}
|
|
354
|
-
async disconnect() {
|
|
355
|
-
const {
|
|
356
|
-
provider
|
|
357
|
-
} = _appkitScaffoldUtilsReactNative.EthersStoreUtil.state;
|
|
358
|
-
_appkitScaffoldUtilsReactNative.StorageUtil.removeItem(_appkitScaffoldUtilsReactNative.EthersConstantsUtil.WALLET_ID);
|
|
359
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.reset();
|
|
360
|
-
this.setClientId(null);
|
|
361
|
-
await provider.disconnect();
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
// -- Private -----------------------------------------------------------------
|
|
365
|
-
createProvider() {
|
|
366
|
-
if (!this.walletConnectProviderInitPromise) {
|
|
367
|
-
this.walletConnectProviderInitPromise = this.initWalletConnectProvider();
|
|
368
|
-
}
|
|
369
|
-
return this.walletConnectProviderInitPromise;
|
|
370
|
-
}
|
|
371
|
-
async initWalletConnectProvider() {
|
|
372
|
-
const rpcMap = this.chains ? this.chains.reduce((map, chain) => {
|
|
373
|
-
map[chain.chainId] = chain.rpcUrl;
|
|
374
|
-
return map;
|
|
375
|
-
}, {}) : {};
|
|
376
|
-
const walletConnectProviderOptions = {
|
|
377
|
-
projectId: this.projectId,
|
|
378
|
-
showQrModal: false,
|
|
379
|
-
rpcMap,
|
|
380
|
-
optionalChains: [...this.chains.map(chain => chain.chainId)],
|
|
381
|
-
metadata: this.metadata
|
|
382
|
-
};
|
|
383
|
-
this.walletConnectProvider = await _ethereumProvider.default.init(walletConnectProviderOptions);
|
|
384
|
-
await this.checkActiveWalletConnectProvider();
|
|
385
|
-
}
|
|
386
|
-
async getWalletConnectProvider() {
|
|
387
|
-
if (!this.walletConnectProvider) {
|
|
388
|
-
try {
|
|
389
|
-
await this.createProvider();
|
|
390
|
-
} catch (error) {
|
|
391
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setError(error);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
return this.walletConnectProvider;
|
|
395
|
-
}
|
|
396
|
-
syncRequestedNetworks(chains, chainImages) {
|
|
397
|
-
const requestedCaipNetworks = chains?.map(chain => ({
|
|
398
|
-
id: `${_appkitScaffoldUtilsReactNative.ConstantsUtil.EIP155}:${chain.chainId}`,
|
|
399
|
-
name: chain.name,
|
|
400
|
-
imageId: _appkitScaffoldUtilsReactNative.PresetsUtil.EIP155NetworkImageIds[chain.chainId],
|
|
401
|
-
imageUrl: chainImages?.[chain.chainId]
|
|
402
|
-
}));
|
|
403
|
-
this.setRequestedCaipNetworks(requestedCaipNetworks ?? []);
|
|
404
|
-
}
|
|
405
|
-
async checkActiveWalletConnectProvider() {
|
|
406
|
-
const WalletConnectProvider = await this.getWalletConnectProvider();
|
|
407
|
-
const walletId = await _appkitScaffoldUtilsReactNative.StorageUtil.getItem(_appkitScaffoldUtilsReactNative.EthersConstantsUtil.WALLET_ID);
|
|
408
|
-
if (WalletConnectProvider) {
|
|
409
|
-
if (walletId === _appkitScaffoldUtilsReactNative.ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID) {
|
|
410
|
-
await this.setWalletConnectProvider();
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
async checkActiveCoinbaseProvider(provider) {
|
|
415
|
-
const CoinbaseProvider = provider;
|
|
416
|
-
const walletId = await _appkitScaffoldUtilsReactNative.StorageUtil.getItem(_appkitScaffoldUtilsReactNative.EthersConstantsUtil.WALLET_ID);
|
|
417
|
-
if (CoinbaseProvider) {
|
|
418
|
-
if (walletId === _appkitScaffoldUtilsReactNative.ConstantsUtil.COINBASE_CONNECTOR_ID) {
|
|
419
|
-
if (CoinbaseProvider.address) {
|
|
420
|
-
await this.setCoinbaseProvider(provider);
|
|
421
|
-
await this.watchCoinbase(provider);
|
|
422
|
-
} else {
|
|
423
|
-
await _appkitScaffoldUtilsReactNative.StorageUtil.removeItem(_appkitScaffoldUtilsReactNative.EthersConstantsUtil.WALLET_ID);
|
|
424
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.reset();
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
async setWalletConnectProvider() {
|
|
430
|
-
_appkitScaffoldUtilsReactNative.StorageUtil.setItem(_appkitScaffoldUtilsReactNative.EthersConstantsUtil.WALLET_ID, _appkitScaffoldUtilsReactNative.ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID);
|
|
431
|
-
const WalletConnectProvider = await this.getWalletConnectProvider();
|
|
432
|
-
if (WalletConnectProvider) {
|
|
433
|
-
const providerType = _appkitScaffoldUtilsReactNative.PresetsUtil.ConnectorTypesMap[_appkitScaffoldUtilsReactNative.ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID];
|
|
434
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setChainId(WalletConnectProvider.chainId);
|
|
435
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setProviderType(providerType);
|
|
436
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setProvider(WalletConnectProvider);
|
|
437
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setIsConnected(true);
|
|
438
|
-
this.setAddress(WalletConnectProvider.accounts?.[0]);
|
|
439
|
-
await this.watchWalletConnect();
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
async setCoinbaseProvider(provider) {
|
|
443
|
-
await _appkitScaffoldUtilsReactNative.StorageUtil.setItem(_appkitScaffoldUtilsReactNative.EthersConstantsUtil.WALLET_ID, _appkitScaffoldUtilsReactNative.ConstantsUtil.COINBASE_CONNECTOR_ID);
|
|
444
|
-
if (provider) {
|
|
445
|
-
const {
|
|
446
|
-
address,
|
|
447
|
-
chainId
|
|
448
|
-
} = await _appkitScaffoldUtilsReactNative.EthersHelpersUtil.getUserInfo(provider);
|
|
449
|
-
if (address && chainId) {
|
|
450
|
-
const providerType = _appkitScaffoldUtilsReactNative.PresetsUtil.ConnectorTypesMap[_appkitScaffoldUtilsReactNative.ConstantsUtil.COINBASE_CONNECTOR_ID];
|
|
451
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setChainId(chainId);
|
|
452
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setProviderType(providerType);
|
|
453
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setProvider(provider);
|
|
454
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setIsConnected(true);
|
|
455
|
-
this.setAddress(address);
|
|
456
|
-
await this.watchCoinbase(provider);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
async setAuthProvider() {
|
|
461
|
-
_appkitScaffoldUtilsReactNative.StorageUtil.setItem(_appkitScaffoldUtilsReactNative.EthersConstantsUtil.WALLET_ID, _appkitScaffoldUtilsReactNative.ConstantsUtil.AUTH_CONNECTOR_ID);
|
|
462
|
-
if (this.authProvider) {
|
|
463
|
-
const {
|
|
464
|
-
address,
|
|
465
|
-
chainId
|
|
466
|
-
} = await this.authProvider.connect();
|
|
467
|
-
super.setLoading(false);
|
|
468
|
-
if (address && chainId) {
|
|
469
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setChainId(chainId);
|
|
470
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setProviderType(_appkitScaffoldUtilsReactNative.PresetsUtil.ConnectorTypesMap[_appkitScaffoldUtilsReactNative.ConstantsUtil.AUTH_CONNECTOR_ID]);
|
|
471
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setProvider(this.authProvider);
|
|
472
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setIsConnected(true);
|
|
473
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setAddress(address);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
async watchWalletConnect() {
|
|
478
|
-
const WalletConnectProvider = await this.getWalletConnectProvider();
|
|
479
|
-
function disconnectHandler() {
|
|
480
|
-
_appkitScaffoldUtilsReactNative.StorageUtil.removeItem(_appkitScaffoldUtilsReactNative.EthersConstantsUtil.WALLET_ID);
|
|
481
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.reset();
|
|
482
|
-
WalletConnectProvider?.removeListener('disconnect', disconnectHandler);
|
|
483
|
-
WalletConnectProvider?.removeListener('accountsChanged', accountsChangedHandler);
|
|
484
|
-
WalletConnectProvider?.removeListener('chainChanged', chainChangedHandler);
|
|
485
|
-
}
|
|
486
|
-
function chainChangedHandler(chainId) {
|
|
487
|
-
if (chainId) {
|
|
488
|
-
const chain = _appkitScaffoldUtilsReactNative.EthersHelpersUtil.hexStringToNumber(chainId);
|
|
489
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setChainId(chain);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
const accountsChangedHandler = async accounts => {
|
|
493
|
-
if (accounts.length > 0) {
|
|
494
|
-
await this.setWalletConnectProvider();
|
|
495
|
-
}
|
|
496
|
-
};
|
|
497
|
-
if (WalletConnectProvider) {
|
|
498
|
-
WalletConnectProvider.on('disconnect', disconnectHandler);
|
|
499
|
-
WalletConnectProvider.on('accountsChanged', accountsChangedHandler);
|
|
500
|
-
WalletConnectProvider.on('chainChanged', chainChangedHandler);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
async watchCoinbase(provider) {
|
|
504
|
-
const walletId = await _appkitScaffoldUtilsReactNative.StorageUtil.getItem(_appkitScaffoldUtilsReactNative.EthersConstantsUtil.WALLET_ID);
|
|
505
|
-
function disconnectHandler() {
|
|
506
|
-
_appkitScaffoldUtilsReactNative.StorageUtil.removeItem(_appkitScaffoldUtilsReactNative.EthersConstantsUtil.WALLET_ID);
|
|
507
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.reset();
|
|
508
|
-
provider?.removeListener('disconnect', disconnectHandler);
|
|
509
|
-
provider?.removeListener('accountsChanged', accountsChangedHandler);
|
|
510
|
-
provider?.removeListener('chainChanged', chainChangedHandler);
|
|
511
|
-
}
|
|
512
|
-
function accountsChangedHandler(accounts) {
|
|
513
|
-
if (accounts.length === 0) {
|
|
514
|
-
_appkitScaffoldUtilsReactNative.StorageUtil.removeItem(_appkitScaffoldUtilsReactNative.EthersConstantsUtil.WALLET_ID);
|
|
515
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.reset();
|
|
516
|
-
} else {
|
|
517
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setAddress(accounts[0]);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
function chainChangedHandler(chainId) {
|
|
521
|
-
if (chainId && walletId === _appkitScaffoldUtilsReactNative.ConstantsUtil.COINBASE_CONNECTOR_ID) {
|
|
522
|
-
const chain = Number(chainId);
|
|
523
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setChainId(chain);
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
if (provider) {
|
|
527
|
-
provider.on('disconnect', disconnectHandler);
|
|
528
|
-
provider.on('accountsChanged', accountsChangedHandler);
|
|
529
|
-
provider.on('chainChanged', chainChangedHandler);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
async syncAccount() {
|
|
533
|
-
const address = _appkitScaffoldUtilsReactNative.EthersStoreUtil.state.address;
|
|
534
|
-
const chainId = _appkitScaffoldUtilsReactNative.EthersStoreUtil.state.chainId;
|
|
535
|
-
const isConnected = _appkitScaffoldUtilsReactNative.EthersStoreUtil.state.isConnected;
|
|
536
|
-
this.resetAccount();
|
|
537
|
-
if (isConnected && address && chainId) {
|
|
538
|
-
const caipAddress = `${_appkitScaffoldUtilsReactNative.ConstantsUtil.EIP155}:${chainId}:${address}`;
|
|
539
|
-
this.setIsConnected(isConnected);
|
|
540
|
-
this.setCaipAddress(caipAddress);
|
|
541
|
-
await Promise.all([this.syncProfile(address), this.syncBalance(address), this.getApprovedCaipNetworksData()]);
|
|
542
|
-
this.hasSyncedConnectedAccount = true;
|
|
543
|
-
} else if (!isConnected && this.hasSyncedConnectedAccount) {
|
|
544
|
-
this.resetWcConnection();
|
|
545
|
-
this.resetNetwork();
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
async syncNetwork(chainImages) {
|
|
549
|
-
const address = _appkitScaffoldUtilsReactNative.EthersStoreUtil.state.address;
|
|
550
|
-
const chainId = _appkitScaffoldUtilsReactNative.EthersStoreUtil.state.chainId;
|
|
551
|
-
const isConnected = _appkitScaffoldUtilsReactNative.EthersStoreUtil.state.isConnected;
|
|
552
|
-
if (this.chains) {
|
|
553
|
-
const chain = this.chains.find(c => c.chainId === chainId);
|
|
554
|
-
if (chain) {
|
|
555
|
-
const caipChainId = `${_appkitScaffoldUtilsReactNative.ConstantsUtil.EIP155}:${chain.chainId}`;
|
|
556
|
-
this.setCaipNetwork({
|
|
557
|
-
id: caipChainId,
|
|
558
|
-
name: chain.name,
|
|
559
|
-
imageId: _appkitScaffoldUtilsReactNative.PresetsUtil.EIP155NetworkImageIds[chain.chainId],
|
|
560
|
-
imageUrl: chainImages?.[chain.chainId]
|
|
561
|
-
});
|
|
562
|
-
if (isConnected && address) {
|
|
563
|
-
const caipAddress = `${_appkitScaffoldUtilsReactNative.ConstantsUtil.EIP155}:${chainId}:${address}`;
|
|
564
|
-
this.setCaipAddress(caipAddress);
|
|
565
|
-
if (chain.explorerUrl) {
|
|
566
|
-
const url = `${chain.explorerUrl}/address/${address}`;
|
|
567
|
-
this.setAddressExplorerUrl(url);
|
|
568
|
-
} else {
|
|
569
|
-
this.setAddressExplorerUrl(undefined);
|
|
570
|
-
}
|
|
571
|
-
if (this.hasSyncedConnectedAccount) {
|
|
572
|
-
await this.syncBalance(address);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
async syncProfile(address) {
|
|
579
|
-
const chainId = _appkitScaffoldUtilsReactNative.EthersStoreUtil.state.chainId;
|
|
580
|
-
try {
|
|
581
|
-
const response = await this.fetchIdentity({
|
|
582
|
-
address
|
|
583
|
-
});
|
|
584
|
-
if (!response) {
|
|
585
|
-
throw new Error('Couldnt fetch idendity');
|
|
586
|
-
}
|
|
587
|
-
this.setProfileName(response.name);
|
|
588
|
-
this.setProfileImage(response.avatar);
|
|
589
|
-
} catch {
|
|
590
|
-
if (chainId === 1) {
|
|
591
|
-
const ensProvider = new _ethers.InfuraProvider('mainnet');
|
|
592
|
-
const name = await ensProvider.lookupAddress(address);
|
|
593
|
-
const avatar = await ensProvider.getAvatar(address);
|
|
594
|
-
if (name) {
|
|
595
|
-
this.setProfileName(name);
|
|
596
|
-
}
|
|
597
|
-
if (avatar) {
|
|
598
|
-
this.setProfileImage(avatar);
|
|
599
|
-
}
|
|
600
|
-
} else {
|
|
601
|
-
this.setProfileName(undefined);
|
|
602
|
-
this.setProfileImage(undefined);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
async syncBalance(address) {
|
|
607
|
-
const chainId = _appkitScaffoldUtilsReactNative.EthersStoreUtil.state.chainId;
|
|
608
|
-
if (chainId && this.chains) {
|
|
609
|
-
const chain = this.chains.find(c => c.chainId === chainId);
|
|
610
|
-
if (chain) {
|
|
611
|
-
const jsonRpcProvider = new _ethers.JsonRpcProvider(chain.rpcUrl, {
|
|
612
|
-
chainId,
|
|
613
|
-
name: chain.name
|
|
614
|
-
});
|
|
615
|
-
if (jsonRpcProvider) {
|
|
616
|
-
const balance = await jsonRpcProvider.getBalance(address);
|
|
617
|
-
const formattedBalance = (0, _ethers.formatEther)(balance);
|
|
618
|
-
this.setBalance(formattedBalance, chain.currency);
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
async switchNetwork(chainId) {
|
|
624
|
-
const provider = _appkitScaffoldUtilsReactNative.EthersStoreUtil.state.provider;
|
|
625
|
-
const providerType = _appkitScaffoldUtilsReactNative.EthersStoreUtil.state.providerType;
|
|
626
|
-
if (this.chains) {
|
|
627
|
-
const chain = this.chains.find(c => c.chainId === chainId);
|
|
628
|
-
const walletConnectType = _appkitScaffoldUtilsReactNative.PresetsUtil.ConnectorTypesMap[_appkitScaffoldUtilsReactNative.ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID];
|
|
629
|
-
const coinbaseType = _appkitScaffoldUtilsReactNative.PresetsUtil.ConnectorTypesMap[_appkitScaffoldUtilsReactNative.ConstantsUtil.COINBASE_CONNECTOR_ID];
|
|
630
|
-
const authType = _appkitScaffoldUtilsReactNative.PresetsUtil.ConnectorTypesMap[_appkitScaffoldUtilsReactNative.ConstantsUtil.AUTH_CONNECTOR_ID];
|
|
631
|
-
if (providerType === walletConnectType && chain) {
|
|
632
|
-
const WalletConnectProvider = provider;
|
|
633
|
-
if (WalletConnectProvider) {
|
|
634
|
-
try {
|
|
635
|
-
await WalletConnectProvider.request({
|
|
636
|
-
method: 'wallet_switchEthereumChain',
|
|
637
|
-
params: [{
|
|
638
|
-
chainId: _appkitScaffoldUtilsReactNative.EthersHelpersUtil.numberToHexString(chain.chainId)
|
|
639
|
-
}]
|
|
640
|
-
});
|
|
641
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setChainId(chainId);
|
|
642
|
-
} catch (switchError) {
|
|
643
|
-
const message = switchError?.message;
|
|
644
|
-
if (/(?<temp1>user rejected)/u.test(message?.toLowerCase())) {
|
|
645
|
-
throw new Error('Chain is not supported');
|
|
646
|
-
}
|
|
647
|
-
await _appkitScaffoldUtilsReactNative.EthersHelpersUtil.addEthereumChain(WalletConnectProvider, chain);
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
} else if (providerType === coinbaseType && chain) {
|
|
651
|
-
const CoinbaseProvider = provider;
|
|
652
|
-
if (CoinbaseProvider) {
|
|
653
|
-
try {
|
|
654
|
-
await CoinbaseProvider.request({
|
|
655
|
-
method: 'wallet_switchEthereumChain',
|
|
656
|
-
params: [{
|
|
657
|
-
chainId: _appkitScaffoldUtilsReactNative.EthersHelpersUtil.numberToHexString(chain.chainId)
|
|
658
|
-
}]
|
|
659
|
-
});
|
|
660
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setChainId(chain.chainId);
|
|
661
|
-
} catch (switchError) {
|
|
662
|
-
if (switchError.code === _appkitScaffoldUtilsReactNative.EthersConstantsUtil.ERROR_CODE_UNRECOGNIZED_CHAIN_ID || switchError.code === _appkitScaffoldUtilsReactNative.EthersConstantsUtil.ERROR_CODE_DEFAULT || switchError?.data?.originalError?.code === _appkitScaffoldUtilsReactNative.EthersConstantsUtil.ERROR_CODE_UNRECOGNIZED_CHAIN_ID) {
|
|
663
|
-
await _appkitScaffoldUtilsReactNative.EthersHelpersUtil.addEthereumChain(CoinbaseProvider, chain);
|
|
664
|
-
} else {
|
|
665
|
-
throw new Error('Error switching network');
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
} else if (providerType === authType) {
|
|
670
|
-
if (this.authProvider && chain?.chainId) {
|
|
671
|
-
try {
|
|
672
|
-
await this.authProvider?.switchNetwork(chain?.chainId);
|
|
673
|
-
_appkitScaffoldUtilsReactNative.EthersStoreUtil.setChainId(chain.chainId);
|
|
674
|
-
} catch {
|
|
675
|
-
throw new Error('Switching chain failed');
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
syncConnectors(config) {
|
|
682
|
-
const _connectors = [];
|
|
683
|
-
const EXCLUDED_CONNECTORS = [_appkitScaffoldUtilsReactNative.ConstantsUtil.AUTH_CONNECTOR_ID];
|
|
684
|
-
_connectors.push({
|
|
685
|
-
id: _appkitScaffoldUtilsReactNative.ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID,
|
|
686
|
-
explorerId: _appkitScaffoldUtilsReactNative.PresetsUtil.ConnectorExplorerIds[_appkitScaffoldUtilsReactNative.ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID],
|
|
687
|
-
imageId: _appkitScaffoldUtilsReactNative.PresetsUtil.ConnectorImageIds[_appkitScaffoldUtilsReactNative.ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID],
|
|
688
|
-
imageUrl: this.options?.connectorImages?.[_appkitScaffoldUtilsReactNative.ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID],
|
|
689
|
-
name: _appkitScaffoldUtilsReactNative.PresetsUtil.ConnectorNamesMap[_appkitScaffoldUtilsReactNative.ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID],
|
|
690
|
-
type: _appkitScaffoldUtilsReactNative.PresetsUtil.ConnectorTypesMap[_appkitScaffoldUtilsReactNative.ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID]
|
|
691
|
-
});
|
|
692
|
-
config.extraConnectors?.forEach(connector => {
|
|
693
|
-
if (!EXCLUDED_CONNECTORS.includes(connector.id)) {
|
|
694
|
-
if (connector.id === _appkitScaffoldUtilsReactNative.ConstantsUtil.COINBASE_CONNECTOR_ID) {
|
|
695
|
-
_connectors.push({
|
|
696
|
-
id: _appkitScaffoldUtilsReactNative.ConstantsUtil.COINBASE_CONNECTOR_ID,
|
|
697
|
-
explorerId: _appkitScaffoldUtilsReactNative.PresetsUtil.ConnectorExplorerIds[_appkitScaffoldUtilsReactNative.ConstantsUtil.COINBASE_CONNECTOR_ID],
|
|
698
|
-
imageId: _appkitScaffoldUtilsReactNative.PresetsUtil.ConnectorImageIds[_appkitScaffoldUtilsReactNative.ConstantsUtil.COINBASE_CONNECTOR_ID],
|
|
699
|
-
imageUrl: this.options?.connectorImages?.[_appkitScaffoldUtilsReactNative.ConstantsUtil.COINBASE_CONNECTOR_ID],
|
|
700
|
-
name: _appkitScaffoldUtilsReactNative.PresetsUtil.ConnectorNamesMap[_appkitScaffoldUtilsReactNative.ConstantsUtil.COINBASE_CONNECTOR_ID],
|
|
701
|
-
type: _appkitScaffoldUtilsReactNative.PresetsUtil.ConnectorTypesMap[_appkitScaffoldUtilsReactNative.ConstantsUtil.COINBASE_CONNECTOR_ID]
|
|
702
|
-
});
|
|
703
|
-
this.checkActiveCoinbaseProvider(connector);
|
|
704
|
-
} else {
|
|
705
|
-
_connectors.push({
|
|
706
|
-
id: connector.id,
|
|
707
|
-
name: connector.name,
|
|
708
|
-
type: 'EXTERNAL'
|
|
709
|
-
});
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
});
|
|
713
|
-
this.setConnectors(_connectors);
|
|
714
|
-
}
|
|
715
|
-
async syncAuthConnector(config) {
|
|
716
|
-
const authConnector = config.extraConnectors?.find(connector => connector.id === _appkitScaffoldUtilsReactNative.ConstantsUtil.AUTH_CONNECTOR_ID);
|
|
717
|
-
if (!authConnector) {
|
|
718
|
-
return;
|
|
719
|
-
}
|
|
720
|
-
this.authProvider = authConnector;
|
|
721
|
-
this.addConnector({
|
|
722
|
-
id: _appkitScaffoldUtilsReactNative.ConstantsUtil.AUTH_CONNECTOR_ID,
|
|
723
|
-
name: _appkitScaffoldUtilsReactNative.PresetsUtil.ConnectorNamesMap[_appkitScaffoldUtilsReactNative.ConstantsUtil.AUTH_CONNECTOR_ID],
|
|
724
|
-
type: _appkitScaffoldUtilsReactNative.PresetsUtil.ConnectorTypesMap[_appkitScaffoldUtilsReactNative.ConstantsUtil.AUTH_CONNECTOR_ID],
|
|
725
|
-
provider: authConnector
|
|
726
|
-
});
|
|
727
|
-
const connectedConnector = await _appkitScaffoldUtilsReactNative.StorageUtil.getItem('@w3m/connected_connector');
|
|
728
|
-
if (connectedConnector === 'AUTH') {
|
|
729
|
-
this.setLoading(true);
|
|
730
|
-
}
|
|
731
|
-
const {
|
|
732
|
-
isConnected
|
|
733
|
-
} = await this.authProvider.isConnected();
|
|
734
|
-
if (isConnected) {
|
|
735
|
-
this.setAuthProvider();
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
exports.AppKit = AppKit;
|
|
740
|
-
//# sourceMappingURL=client.js.map
|