@rango-dev/wallets-core 0.51.1-next.1 → 0.53.1-next.0

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.
@@ -21,14 +21,16 @@ export const connect = () =>
21
21
  export const changeAccountSubscriber = (getInstance: () => ProviderAPI) =>
22
22
  new ChangeAccountSubscriberBuilder<string, ProviderAPI>()
23
23
  .getInstance(getInstance)
24
- .validateEventPayload(
25
- (accounts) =>
26
- /*
27
- * In some wallets, when a user switches to an account not yet connected to the dApp, it returns null.
28
- * A null value indicates no access to the account, requiring a disconnect and user reconnection.
29
- */
30
- !!accounts
31
- )
24
+ /*
25
+ * In some wallets, when a user switches to an account not yet connected to the dApp, it returns null.
26
+ * A null value indicates no access to the account, requiring a disconnect and user reconnection.
27
+ */
28
+ .onSwitchAccount((event, context) => {
29
+ if (!event.payload) {
30
+ context.action('disconnect');
31
+ event.preventDefault();
32
+ }
33
+ })
32
34
  .format(async (_, accounts) => formatAccountsToCAIP([accounts]))
33
35
  .addEventListener((instance, callback) => {
34
36
  instance.on('accountChanged', callback);
@@ -59,15 +59,16 @@ export const changeAccountSubscriber = (
59
59
  ProviderAPI
60
60
  >()
61
61
  .getInstance(() => getInstanceOrThrow(params.name))
62
- .validateEventPayload(
63
- (event) =>
64
- /*
65
- * In some wallets, when a user switches to an account not yet connected to the dApp, it returns null.
66
- * A null value indicates no access to the account, requiring a disconnect and user reconnection.
67
- */
68
-
69
- event.accounts?.length !== 0
70
- )
62
+ /*
63
+ * In some wallets, when a user switches to an account not yet connected to the dApp, it returns null.
64
+ * A null value indicates no access to the account, requiring a disconnect and user reconnection.
65
+ */
66
+ .onSwitchAccount((event, context) => {
67
+ if (!event.payload.accounts?.length) {
68
+ context.action('disconnect');
69
+ event.preventDefault();
70
+ }
71
+ })
71
72
  .format(async (_, event) => formatAccountsToCAIP(event.accounts))
72
73
  .addEventListener((instance, callback) =>
73
74
  instance.features['standard:events'].on('change', callback)
@@ -3,6 +3,6 @@ export * as after from './after.js';
3
3
  export * as and from './and.js';
4
4
  export * as before from './before.js';
5
5
  export * as builders from './builders.js';
6
-
6
+ export * as utils from './utils.js';
7
7
  export type { ProviderAPI, UtxoActions } from './types.js';
8
8
  export { CAIP_NAMESPACE, CAIP_BITCOIN_CHAIN_ID } from './constants.js';
@@ -0,0 +1,18 @@
1
+ import type { CaipAccount } from '../common/mod.js';
2
+
3
+ import { AccountId } from 'caip';
4
+
5
+ import { CAIP_BITCOIN_CHAIN_ID, CAIP_NAMESPACE } from './constants.js';
6
+
7
+ export function formatAccountsToCAIP(accounts: string[]) {
8
+ return accounts.map(
9
+ (account) =>
10
+ AccountId.format({
11
+ address: account.toString(),
12
+ chainId: {
13
+ namespace: CAIP_NAMESPACE,
14
+ reference: CAIP_BITCOIN_CHAIN_ID,
15
+ },
16
+ }) as CaipAccount
17
+ );
18
+ }