@rango-dev/wallets-core 0.1.16-next.6 → 0.1.16-next.8

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/src/provider.tsx CHANGED
@@ -95,6 +95,7 @@ function Provider(props: ProviderProps) {
95
95
  const wallets = checkWalletProviders(listOfProviders);
96
96
  const api: ProviderContext = {
97
97
  // TODO: Fix type error
98
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
98
99
  // @ts-ignore
99
100
  async connect(type, network) {
100
101
  const wallet = wallets.get(type);
@@ -125,7 +126,7 @@ function Provider(props: ProviderProps) {
125
126
  connectedWallets(providersState).forEach((type) => {
126
127
  const wallet = wallets.get(type);
127
128
 
128
- if (!!wallet) {
129
+ if (wallet) {
129
130
  const ref = addWalletRef(wallet);
130
131
  disconnect_promises.push(ref.disconnect());
131
132
  }
@@ -143,13 +144,15 @@ function Provider(props: ProviderProps) {
143
144
  }
144
145
 
145
146
  const ref = addWalletRef(wallet);
146
- return ref.canSwitchNetworkTo ? ref.canSwitchNetworkTo(network) : false;
147
+ return ref.canSwitchNetworkTo
148
+ ? ref.canSwitchNetworkTo(network, ref.provider)
149
+ : false;
147
150
  },
148
151
  providers() {
149
152
  const providers: { [type in WalletType]?: any } = {};
150
153
  availableWallets(providersState).forEach((type) => {
151
154
  const wallet = wallets.get(type);
152
- if (!!wallet) {
155
+ if (wallet) {
153
156
  const ref = addWalletRef(wallet);
154
157
  providers[type] = ref.provider;
155
158
  }
@@ -193,7 +196,7 @@ function Provider(props: ProviderProps) {
193
196
  wallets.forEach((wallet) => {
194
197
  const ref = addWalletRef(wallet);
195
198
  const runOnInit = () => {
196
- if (!!ref.onInit) {
199
+ if (ref.onInit) {
197
200
  ref.onInit();
198
201
  }
199
202
  };
@@ -220,7 +223,7 @@ function Provider(props: ProviderProps) {
220
223
 
221
224
  useEffect(() => {
222
225
  const allBlockChains = props.allBlockChains;
223
- if (!!allBlockChains) {
226
+ if (allBlockChains) {
224
227
  wallets.forEach((wallet) => {
225
228
  const ref = addWalletRef(wallet);
226
229
  const supportedChains = ref.getWalletInfo(
package/src/types.ts CHANGED
@@ -54,7 +54,9 @@ export type GetInstanceOptions = {
54
54
  currentProvider: any;
55
55
  meta: BlockchainMeta[];
56
56
  force?: boolean;
57
+ updateChainId: (chainId: number | string) => void;
57
58
  };
59
+
58
60
  export type GetInstance =
59
61
  | (() => any)
60
62
  | ((options: GetInstanceOptions) => Promise<any>);
@@ -91,6 +93,7 @@ export type SwitchNetwork = (options: {
91
93
  export type CanSwitchNetwork = (options: {
92
94
  network: Network;
93
95
  meta: BlockchainMeta[];
96
+ provider: any;
94
97
  }) => boolean;
95
98
 
96
99
  export interface WalletActions {
package/src/wallet.ts CHANGED
@@ -92,7 +92,7 @@ class Wallet<InstanceType = any> {
92
92
  const requestedNetwork =
93
93
  network || currentNetwork || this.options.config.defaultNetwork;
94
94
 
95
- if (!!eagerConnection) {
95
+ if (eagerConnection) {
96
96
  const networkChanged =
97
97
  currentNetwork !== requestedNetwork && !!requestedNetwork;
98
98
 
@@ -105,6 +105,7 @@ class Wallet<InstanceType = any> {
105
105
  instance: this.provider,
106
106
  meta: this.meta,
107
107
  // TODO: Fix type error
108
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
108
109
  // @ts-ignore
109
110
  network: requestedNetwork,
110
111
  newInstance: this.tryGetInstance.bind(this),
@@ -216,13 +217,14 @@ class Wallet<InstanceType = any> {
216
217
  getWalletInfo(allBlockChains: BlockchainMeta[]) {
217
218
  return this.actions.getWalletInfo(allBlockChains);
218
219
  }
219
- canSwitchNetworkTo(network: Network) {
220
+ canSwitchNetworkTo(network: Network, provider: any) {
220
221
  const switchTo = this.actions.canSwitchNetworkTo;
221
222
  if (!switchTo) return false;
222
223
 
223
224
  return switchTo({
224
225
  network,
225
226
  meta: this.meta,
227
+ provider,
226
228
  });
227
229
  }
228
230
 
@@ -237,7 +239,6 @@ class Wallet<InstanceType = any> {
237
239
 
238
240
  setProvider(value: any) {
239
241
  this.provider = value;
240
-
241
242
  if (!!value && !!this.actions.subscribe) {
242
243
  this.actions.subscribe({
243
244
  instance: value,
@@ -260,7 +261,7 @@ class Wallet<InstanceType = any> {
260
261
  }
261
262
  },
262
263
  updateChainId: (chainId) => {
263
- const network = !!chainId
264
+ const network = chainId
264
265
  ? getBlockChainNameFromId(chainId, this.meta)
265
266
  : Network.Unknown;
266
267
  this.updateState({
@@ -353,19 +354,25 @@ class Wallet<InstanceType = any> {
353
354
  // We only kill the session (and not restting the whole state)
354
355
  // So we are relying on this.provider for achieving this functionality.
355
356
  this.setProvider(null);
356
-
357
357
  if (this.options.config.isAsyncInstance) {
358
358
  // Trying to connect
359
359
  const instanceOptions: GetInstanceOptions = {
360
360
  currentProvider: this.provider,
361
361
  meta: this.meta,
362
362
  force: force || false,
363
+ updateChainId: (chainId) => {
364
+ const network = chainId
365
+ ? getBlockChainNameFromId(chainId, this.meta)
366
+ : Network.Unknown;
367
+ this.updateState({
368
+ network,
369
+ });
370
+ },
363
371
  };
364
372
 
365
373
  if (network) {
366
374
  instanceOptions.network = network;
367
375
  }
368
-
369
376
  instance = await this.actions.getInstance(instanceOptions);
370
377
  } else {
371
378
  instance = this.actions.getInstance();