@rango-dev/wallets-core 0.40.1-next.0 → 0.40.1-next.10
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/dist/hub/store/providers.d.ts +2 -2
- package/dist/hub/store/providers.d.ts.map +1 -1
- package/dist/legacy/mod.d.ts +3 -3
- package/dist/legacy/mod.d.ts.map +1 -1
- package/dist/legacy/mod.js +1 -1
- package/dist/legacy/mod.js.map +3 -3
- package/dist/legacy/types.d.ts +25 -21
- package/dist/legacy/types.d.ts.map +1 -1
- package/dist/legacy/utils.d.ts +2 -4
- package/dist/legacy/utils.d.ts.map +1 -1
- package/dist/legacy/wallet.d.ts.map +1 -1
- package/dist/mod.js.map +1 -1
- package/dist/namespaces/common/builders.d.ts.map +1 -1
- package/dist/namespaces/common/mod.d.ts +1 -0
- package/dist/namespaces/common/mod.d.ts.map +1 -1
- package/dist/namespaces/common/mod.js +1 -1
- package/dist/namespaces/common/mod.js.map +3 -3
- package/dist/namespaces/common/types.d.ts +3 -0
- package/dist/namespaces/common/types.d.ts.map +1 -1
- package/dist/namespaces/evm/actions.d.ts +1 -0
- package/dist/namespaces/evm/actions.d.ts.map +1 -1
- package/dist/namespaces/evm/mod.js +1 -1
- package/dist/namespaces/evm/mod.js.map +3 -3
- package/dist/namespaces/solana/mod.js.map +1 -1
- package/dist/wallets-core.build.json +1 -1
- package/package.json +2 -2
- package/src/hub/store/providers.ts +2 -2
- package/src/legacy/mod.ts +1 -7
- package/src/legacy/types.ts +35 -39
- package/src/legacy/utils.ts +3 -14
- package/src/legacy/wallet.ts +7 -0
- package/src/namespaces/common/builders.ts +1 -6
- package/src/namespaces/common/mod.ts +2 -0
- package/src/namespaces/common/types.ts +16 -0
- package/src/namespaces/evm/actions.ts +54 -3
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* These are supported namespaces in Rango that we want to officially support.
|
|
3
|
+
* This should be private and don't make it public since core can support more namespaces and should be extendable.
|
|
4
|
+
*/
|
|
5
|
+
type RangoNamespace =
|
|
6
|
+
| 'EVM'
|
|
7
|
+
| 'Solana'
|
|
8
|
+
| 'Cosmos'
|
|
9
|
+
| 'UTXO'
|
|
10
|
+
| 'Starknet'
|
|
11
|
+
| 'Tron'
|
|
12
|
+
| 'Ton';
|
|
13
|
+
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
15
|
+
export type Namespace = RangoNamespace | (string & {});
|
|
16
|
+
|
|
1
17
|
export interface CommonActions {
|
|
2
18
|
init: () => void;
|
|
3
19
|
}
|
|
@@ -57,8 +57,9 @@ export function changeAccountSubscriber(
|
|
|
57
57
|
): [Subscriber<EvmActions>, SubscriberCleanUp<EvmActions>] {
|
|
58
58
|
let eventCallback: EIP1193EventMap['accountsChanged'];
|
|
59
59
|
|
|
60
|
+
// subscriber can be passed to `or`, it will get the error and should rethrow error to pass the error to next `or` or throw error.
|
|
60
61
|
return [
|
|
61
|
-
(context) => {
|
|
62
|
+
(context, err) => {
|
|
62
63
|
const evmInstance = instance();
|
|
63
64
|
|
|
64
65
|
if (!evmInstance) {
|
|
@@ -70,8 +71,18 @@ export function changeAccountSubscriber(
|
|
|
70
71
|
const [, setState] = context.state();
|
|
71
72
|
|
|
72
73
|
eventCallback = async (accounts) => {
|
|
73
|
-
|
|
74
|
+
/*
|
|
75
|
+
* In Phantom, when user is switching to an account which is not connected to dApp yet, it returns a null.
|
|
76
|
+
* So null means we don't have access to account and we need to disconnect and let the user connect the account.
|
|
77
|
+
*
|
|
78
|
+
* This assumption may not work for other wallets, if that the case, we need to consider a new approach.
|
|
79
|
+
*/
|
|
80
|
+
if (!accounts || accounts.length === 0) {
|
|
81
|
+
context.action('disconnect');
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
74
84
|
|
|
85
|
+
const chainId = await evmInstance.request({ method: 'eth_chainId' });
|
|
75
86
|
const formatAccounts = accounts.map((account) =>
|
|
76
87
|
AccountId.format({
|
|
77
88
|
address: account,
|
|
@@ -85,13 +96,53 @@ export function changeAccountSubscriber(
|
|
|
85
96
|
setState('accounts', formatAccounts);
|
|
86
97
|
};
|
|
87
98
|
evmInstance.on('accountsChanged', eventCallback);
|
|
99
|
+
|
|
100
|
+
if (err instanceof Error) {
|
|
101
|
+
throw err;
|
|
102
|
+
}
|
|
88
103
|
},
|
|
89
|
-
() => {
|
|
104
|
+
(_, err) => {
|
|
90
105
|
const evmInstance = instance();
|
|
91
106
|
|
|
92
107
|
if (eventCallback && evmInstance) {
|
|
93
108
|
evmInstance.removeListener('accountsChanged', eventCallback);
|
|
94
109
|
}
|
|
110
|
+
|
|
111
|
+
if (err instanceof Error) {
|
|
112
|
+
throw err;
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function changeChainSubscriber(
|
|
119
|
+
instance: () => ProviderAPI
|
|
120
|
+
): [Subscriber<EvmActions>, SubscriberCleanUp<EvmActions>] {
|
|
121
|
+
let eventCallback: EIP1193EventMap['chainChanged'];
|
|
122
|
+
|
|
123
|
+
return [
|
|
124
|
+
(context) => {
|
|
125
|
+
const evmInstance = instance();
|
|
126
|
+
|
|
127
|
+
if (!evmInstance) {
|
|
128
|
+
throw new Error(
|
|
129
|
+
'Trying to subscribe to your EVM wallet, but seems its instance is not available.'
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const [, setState] = context.state();
|
|
134
|
+
|
|
135
|
+
eventCallback = async (chainId: string) => {
|
|
136
|
+
setState('network', chainId);
|
|
137
|
+
};
|
|
138
|
+
evmInstance.on('chainChanged', eventCallback);
|
|
139
|
+
},
|
|
140
|
+
() => {
|
|
141
|
+
const evmInstance = instance();
|
|
142
|
+
|
|
143
|
+
if (eventCallback && evmInstance) {
|
|
144
|
+
evmInstance.removeListener('chainChanged', eventCallback);
|
|
145
|
+
}
|
|
95
146
|
},
|
|
96
147
|
];
|
|
97
148
|
}
|