@rango-dev/wallets-core 0.43.1-next.1 → 0.43.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/builders/namespace.d.ts.map +1 -1
- package/dist/hub/hub.d.ts +1 -0
- package/dist/hub/hub.d.ts.map +1 -1
- package/dist/hub/namespaces/namespace.d.ts +1 -0
- package/dist/hub/namespaces/namespace.d.ts.map +1 -1
- package/dist/hub/provider/provider.d.ts.map +1 -1
- package/dist/hub/store/mod.js +1 -1
- package/dist/hub/store/mod.js.map +2 -2
- package/dist/hub/store/providers.d.ts +26 -2
- package/dist/hub/store/providers.d.ts.map +1 -1
- package/dist/legacy/mod.js.map +2 -2
- package/dist/legacy/types.d.ts +1 -2
- package/dist/legacy/types.d.ts.map +1 -1
- package/dist/mod.js +1 -1
- package/dist/mod.js.map +3 -3
- package/dist/namespaces/common/mod.d.ts +1 -1
- 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 +2 -2
- package/dist/namespaces/common/types.d.ts +0 -4
- package/dist/namespaces/common/types.d.ts.map +1 -1
- package/dist/namespaces/evm/mod.d.ts +0 -1
- package/dist/namespaces/evm/mod.d.ts.map +1 -1
- package/dist/namespaces/evm/mod.js +1 -1
- package/dist/namespaces/evm/mod.js.map +4 -4
- package/dist/namespaces/solana/actions.d.ts +3 -1
- package/dist/namespaces/solana/actions.d.ts.map +1 -1
- package/dist/namespaces/solana/mod.d.ts +0 -1
- package/dist/namespaces/solana/mod.d.ts.map +1 -1
- package/dist/namespaces/solana/mod.js +1 -1
- package/dist/namespaces/solana/mod.js.map +4 -4
- package/dist/namespaces/solana/utils.d.ts +7 -0
- package/dist/namespaces/solana/utils.d.ts.map +1 -0
- package/dist/namespaces/sui/actions.d.ts +5 -1
- package/dist/namespaces/sui/actions.d.ts.map +1 -1
- package/dist/namespaces/sui/builders.d.ts +1 -0
- package/dist/namespaces/sui/builders.d.ts.map +1 -1
- package/dist/namespaces/sui/mod.d.ts +1 -2
- package/dist/namespaces/sui/mod.d.ts.map +1 -1
- package/dist/namespaces/sui/mod.js +1 -1
- package/dist/namespaces/sui/mod.js.map +4 -4
- package/dist/namespaces/sui/utils.d.ts +4 -0
- package/dist/namespaces/sui/utils.d.ts.map +1 -1
- package/dist/namespaces/utxo/mod.d.ts +0 -1
- package/dist/namespaces/utxo/mod.d.ts.map +1 -1
- package/dist/namespaces/utxo/mod.js +1 -1
- package/dist/namespaces/utxo/mod.js.map +4 -4
- package/dist/wallets-core.build.json +1 -1
- package/package.json +1 -1
- package/src/builders/namespace.ts +31 -2
- package/src/hub/hub.ts +13 -0
- package/src/hub/namespaces/namespace.test.ts +21 -0
- package/src/hub/namespaces/namespace.ts +3 -1
- package/src/hub/provider/provider.test.ts +2 -1
- package/src/hub/provider/provider.ts +2 -0
- package/src/hub/store/providers.ts +45 -2
- package/src/hub/store/selectors.ts +1 -1
- package/src/hub/store/store.test.ts +20 -0
- package/src/legacy/types.ts +1 -2
- package/src/namespaces/common/mod.ts +1 -1
- package/src/namespaces/common/types.ts +0 -5
- package/src/namespaces/evm/mod.ts +0 -1
- package/src/namespaces/solana/actions.ts +29 -2
- package/src/namespaces/solana/mod.ts +0 -1
- package/src/namespaces/solana/utils.ts +12 -0
- package/src/namespaces/sui/actions.ts +26 -1
- package/src/namespaces/sui/builders.ts +3 -0
- package/src/namespaces/sui/mod.ts +1 -2
- package/src/namespaces/sui/utils.ts +11 -2
- package/src/namespaces/utxo/mod.ts +0 -1
- package/dist/namespaces/evm/chains.d.ts +0 -5
- package/dist/namespaces/evm/chains.d.ts.map +0 -1
- package/dist/namespaces/solana/chains.d.ts +0 -3
- package/dist/namespaces/solana/chains.d.ts.map +0 -1
- package/dist/namespaces/sui/chains.d.ts +0 -3
- package/dist/namespaces/sui/chains.d.ts.map +0 -1
- package/dist/namespaces/utxo/chains.d.ts +0 -3
- package/dist/namespaces/utxo/chains.d.ts.map +0 -1
- package/src/namespaces/evm/chains.ts +0 -14
- package/src/namespaces/solana/chains.ts +0 -6
- package/src/namespaces/sui/chains.ts +0 -6
- package/src/namespaces/utxo/chains.ts +0 -6
|
@@ -19,6 +19,17 @@ export const allowedMethods = [
|
|
|
19
19
|
'or_else',
|
|
20
20
|
'store',
|
|
21
21
|
] as const;
|
|
22
|
+
/**
|
|
23
|
+
* List of value types that are considered safe to return directly when
|
|
24
|
+
* accessing properties on a proxied `Namespace`.
|
|
25
|
+
*
|
|
26
|
+
* This is useful for allowing public values like `version` to be accessed.
|
|
27
|
+
* If a property's value is of one of these types (e.g.,`'string'`, `'number'`),
|
|
28
|
+
* it will be returned as-is.
|
|
29
|
+
*
|
|
30
|
+
* @const {Array<'string' | 'number'>} allowedPublicValues
|
|
31
|
+
*/
|
|
32
|
+
const allowedPublicValues = ['string', 'number'];
|
|
22
33
|
|
|
23
34
|
export class NamespaceBuilder<T extends Actions<T>> {
|
|
24
35
|
#id: string;
|
|
@@ -192,6 +203,26 @@ export class NamespaceBuilder<T extends Actions<T>> {
|
|
|
192
203
|
this.#addHooksFromActionBuilders(namespace);
|
|
193
204
|
|
|
194
205
|
const api = new Proxy(namespace, {
|
|
206
|
+
has: (_, property) => {
|
|
207
|
+
if (typeof property !== 'string') {
|
|
208
|
+
throw new Error(
|
|
209
|
+
'You can use string as your property on Namespace instance.'
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
213
|
+
// @ts-ignore-next-line
|
|
214
|
+
if (allowedMethods.includes(property)) {
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
218
|
+
// @ts-ignore-next-line
|
|
219
|
+
if (allowedPublicValues.includes(typeof namespace[property])) {
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
223
|
+
// @ts-ignore-next-line
|
|
224
|
+
return namespace.has(property);
|
|
225
|
+
},
|
|
195
226
|
get: (_, property) => {
|
|
196
227
|
if (typeof property !== 'string') {
|
|
197
228
|
throw new Error(
|
|
@@ -207,12 +238,10 @@ export class NamespaceBuilder<T extends Actions<T>> {
|
|
|
207
238
|
) {
|
|
208
239
|
return targetValue.bind(namespace);
|
|
209
240
|
}
|
|
210
|
-
|
|
211
241
|
/*
|
|
212
242
|
* This is useful accessing values like `version`, If we don't do this, we should whitelist
|
|
213
243
|
* All the values as well, So it can be confusing for someone that only wants to add a public value to `Namespace`
|
|
214
244
|
*/
|
|
215
|
-
const allowedPublicValues = ['string', 'number'];
|
|
216
245
|
if (allowedPublicValues.includes(typeof targetValue)) {
|
|
217
246
|
return targetValue;
|
|
218
247
|
}
|
package/src/hub/hub.ts
CHANGED
|
@@ -80,6 +80,18 @@ export class Hub {
|
|
|
80
80
|
this.#providers.set(id, provider);
|
|
81
81
|
return this;
|
|
82
82
|
}
|
|
83
|
+
remove(id: string) {
|
|
84
|
+
const providerToRemove = this.#providers.get(id);
|
|
85
|
+
|
|
86
|
+
if (!providerToRemove) {
|
|
87
|
+
throw new Error(`Provider not found: No provider exists with ID "${id}"`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
this.#options.store?.getState().providers.removeProvider(id);
|
|
91
|
+
this.#providers.delete(id);
|
|
92
|
+
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
83
95
|
|
|
84
96
|
get(providerId: string): Provider | undefined {
|
|
85
97
|
return this.#providers.get(providerId);
|
|
@@ -96,6 +108,7 @@ export class Hub {
|
|
|
96
108
|
output.forEach((result) => {
|
|
97
109
|
const namespaces: NamespaceState[] = [];
|
|
98
110
|
result.namespaces.forEach((b) => {
|
|
111
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
99
112
|
const [getNamespaceState] = b as ReturnType<Namespace<any>['state']>;
|
|
100
113
|
|
|
101
114
|
namespaces.push(getNamespaceState());
|
|
@@ -133,6 +133,27 @@ describe('check initializing Namespace', () => {
|
|
|
133
133
|
expect(currentState('connecting')).toBe(true);
|
|
134
134
|
});
|
|
135
135
|
|
|
136
|
+
test('has method returns true when namespace contains the specified action', () => {
|
|
137
|
+
const connectAction = vi.fn((context) => {
|
|
138
|
+
const [, setState] = context.state();
|
|
139
|
+
setState('connected', true);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const actionsMap = new Map([['connect', connectAction]]);
|
|
143
|
+
|
|
144
|
+
const store = createStore();
|
|
145
|
+
const namespace = new Namespace<TestNamespaceActions>(
|
|
146
|
+
NAMESPACE,
|
|
147
|
+
PROVIDER_ID,
|
|
148
|
+
{
|
|
149
|
+
actions: actionsMap,
|
|
150
|
+
store,
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
expect(namespace.has('connect')).toBe(true);
|
|
155
|
+
expect(namespace.has('disconnect')).toBe(false);
|
|
156
|
+
});
|
|
136
157
|
test("throw an error if store doesn't set", () => {
|
|
137
158
|
const ns = new Namespace<TestNamespaceActions>(NAMESPACE, PROVIDER_ID, {
|
|
138
159
|
actions: new Map(),
|
|
@@ -278,7 +278,9 @@ class Namespace<T extends Actions<T>> {
|
|
|
278
278
|
|
|
279
279
|
return this;
|
|
280
280
|
}
|
|
281
|
-
|
|
281
|
+
public has<K extends keyof T>(actionName: K): boolean {
|
|
282
|
+
return !!this.#actions.get(actionName);
|
|
283
|
+
}
|
|
282
284
|
/**
|
|
283
285
|
*
|
|
284
286
|
* Registered actions will be called using `run`. it will run an action and all the operators or hooks that assigned.
|
|
@@ -16,6 +16,7 @@ describe('check providers', () => {
|
|
|
16
16
|
evm: NamespaceBuilder<EvmActions>;
|
|
17
17
|
solana: NamespaceBuilder<SolanaActions>;
|
|
18
18
|
};
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
20
|
let namespacesMap: Map<any, any>;
|
|
20
21
|
let store: Store;
|
|
21
22
|
|
|
@@ -39,6 +40,7 @@ describe('check providers', () => {
|
|
|
39
40
|
return () => {
|
|
40
41
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
41
42
|
// @ts-ignore-next-line
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
42
44
|
(store = undefined), (namespaces = undefined);
|
|
43
45
|
};
|
|
44
46
|
});
|
|
@@ -52,7 +54,6 @@ describe('check providers', () => {
|
|
|
52
54
|
|
|
53
55
|
expect(allNamespaces.size).toBe(2);
|
|
54
56
|
});
|
|
55
|
-
|
|
56
57
|
test("throw an error if store hasn't set and try to access .state() and .info()", () => {
|
|
57
58
|
const provider = new Provider('garbage', namespacesMap, {
|
|
58
59
|
info: garbageWalletInfo,
|
|
@@ -296,10 +296,12 @@ export class Provider {
|
|
|
296
296
|
|
|
297
297
|
this.#namespaces.forEach((namespace) => {
|
|
298
298
|
if (hookName === 'after') {
|
|
299
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
299
300
|
namespace.after(actionName as any, cb, {
|
|
300
301
|
context,
|
|
301
302
|
});
|
|
302
303
|
} else if (hookName === 'before') {
|
|
304
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
303
305
|
namespace.before(actionName as any, cb, {
|
|
304
306
|
context,
|
|
305
307
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Namespace } from '../../namespaces/common/types.js';
|
|
2
2
|
import type { State as InternalProviderState } from '../provider/mod.js';
|
|
3
|
+
import type { BlockchainMeta } from 'rango-types';
|
|
3
4
|
import type { StateCreator } from 'zustand';
|
|
4
5
|
|
|
5
6
|
import { produce } from 'immer';
|
|
@@ -9,13 +10,47 @@ import { guessProviderStateSelector, type State } from './mod.js';
|
|
|
9
10
|
|
|
10
11
|
type Browsers = 'firefox' | 'chrome' | 'edge' | 'brave' | 'homepage';
|
|
11
12
|
type Property<N extends string, V> = { name: N; value: V };
|
|
12
|
-
|
|
13
|
+
|
|
14
|
+
type NamespacesProperty = Property<
|
|
15
|
+
'namespaces',
|
|
16
|
+
{
|
|
17
|
+
selection: 'single' | 'multiple';
|
|
18
|
+
data: {
|
|
19
|
+
label: string;
|
|
20
|
+
id: string;
|
|
21
|
+
value: Namespace;
|
|
22
|
+
unsupported?: boolean;
|
|
23
|
+
getSupportedChains: (chains: BlockchainMeta[]) => BlockchainMeta[];
|
|
24
|
+
}[];
|
|
25
|
+
}
|
|
26
|
+
>;
|
|
27
|
+
type DerivationPathProperty = Property<
|
|
28
|
+
'derivationPath',
|
|
29
|
+
{
|
|
30
|
+
data: {
|
|
31
|
+
id: string;
|
|
32
|
+
label: string;
|
|
33
|
+
namespace: Namespace;
|
|
34
|
+
generateDerivationPath: (index: string) => string;
|
|
35
|
+
}[];
|
|
36
|
+
}
|
|
37
|
+
>;
|
|
38
|
+
type DetailsProperty = Property<
|
|
39
|
+
'details',
|
|
40
|
+
{
|
|
41
|
+
mobileWallet?: boolean;
|
|
42
|
+
showOnMobile?: boolean;
|
|
43
|
+
isContractWallet?: boolean;
|
|
44
|
+
}
|
|
45
|
+
>;
|
|
13
46
|
|
|
14
47
|
export type ProviderInfo = {
|
|
15
48
|
name: string;
|
|
16
49
|
icon: string;
|
|
17
50
|
extensions: Partial<Record<Browsers, string>>;
|
|
18
|
-
properties?:
|
|
51
|
+
properties?: Array<
|
|
52
|
+
NamespacesProperty | DerivationPathProperty | DetailsProperty
|
|
53
|
+
>;
|
|
19
54
|
};
|
|
20
55
|
|
|
21
56
|
export interface ProviderConfig {
|
|
@@ -38,6 +73,7 @@ type ProviderState = {
|
|
|
38
73
|
};
|
|
39
74
|
interface ProviderActions {
|
|
40
75
|
addProvider: (id: string, config: ProviderConfig) => void;
|
|
76
|
+
removeProvider: (id: string) => void;
|
|
41
77
|
updateStatus: <K extends keyof ProviderData>(
|
|
42
78
|
id: string,
|
|
43
79
|
key: K,
|
|
@@ -82,6 +118,13 @@ const providersStore: ProvidersStateCreator = (set, get) => ({
|
|
|
82
118
|
})
|
|
83
119
|
);
|
|
84
120
|
},
|
|
121
|
+
removeProvider: (id) => {
|
|
122
|
+
set(
|
|
123
|
+
produce((state: State) => {
|
|
124
|
+
delete state.providers.list[id];
|
|
125
|
+
})
|
|
126
|
+
);
|
|
127
|
+
},
|
|
85
128
|
updateStatus: (id, key, value) => {
|
|
86
129
|
const provider = get().providers.list[id];
|
|
87
130
|
if (!provider) {
|
|
@@ -28,7 +28,7 @@ export function guessProviderStateSelector(
|
|
|
28
28
|
);
|
|
29
29
|
|
|
30
30
|
// Returning provider state value directly.
|
|
31
|
-
const installed = state.providers.list[providerId]
|
|
31
|
+
const installed = !!state.providers.list[providerId]?.data.installed;
|
|
32
32
|
|
|
33
33
|
/*
|
|
34
34
|
* If any namespaces returns `true`, we consider the whole provider for this field to be `true`.
|
|
@@ -29,4 +29,24 @@ describe('checking store', () => {
|
|
|
29
29
|
expect(getState().providers.list[id]).toBeDefined();
|
|
30
30
|
expect(Object.keys(getState().providers.list).length).toBe(1);
|
|
31
31
|
});
|
|
32
|
+
test('provider can be removed from store', () => {
|
|
33
|
+
const id = 'sol-or-something';
|
|
34
|
+
const info = {
|
|
35
|
+
info: {
|
|
36
|
+
name: 'sol grabage wallet',
|
|
37
|
+
icon: 'http://somewhere.world',
|
|
38
|
+
extensions: {
|
|
39
|
+
homepage: 'http://somewhere.world',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const { getState } = hubStore;
|
|
45
|
+
getState().providers.addProvider(id, info);
|
|
46
|
+
expect(getState().providers.list[id]).toBeDefined();
|
|
47
|
+
expect(Object.keys(getState().providers.list).length).toBe(1);
|
|
48
|
+
getState().providers.removeProvider(id);
|
|
49
|
+
expect(getState().providers.list[id]).toBeUndefined();
|
|
50
|
+
expect(Object.keys(getState().providers.list).length).toBe(0);
|
|
51
|
+
});
|
|
32
52
|
});
|
package/src/legacy/types.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { State as WalletState } from './wallet.js';
|
|
2
2
|
import type { Namespace } from '../namespaces/common/mod.js';
|
|
3
|
-
import type { Chain } from '../namespaces/common/types.js';
|
|
4
3
|
import type { BlockchainMeta, SignerFactory } from 'rango-types';
|
|
5
4
|
|
|
6
5
|
export enum Networks {
|
|
@@ -95,7 +94,7 @@ export type NamespaceMeta = {
|
|
|
95
94
|
id: string;
|
|
96
95
|
value: Namespace;
|
|
97
96
|
unsupported?: boolean;
|
|
98
|
-
chains:
|
|
97
|
+
getSupportedChains: (chains: BlockchainMeta[]) => BlockchainMeta[];
|
|
99
98
|
};
|
|
100
99
|
|
|
101
100
|
interface NeedsNamespace {
|
|
@@ -4,7 +4,6 @@ export * as and from './and.js';
|
|
|
4
4
|
export * as before from './before.js';
|
|
5
5
|
export * as utils from './utils.js';
|
|
6
6
|
export * as builders from './builders.js';
|
|
7
|
-
export * as chains from './chains.js';
|
|
8
7
|
|
|
9
8
|
export type { EvmActions, ProviderAPI } from './types.js';
|
|
10
9
|
export { CAIP_NAMESPACE, CAIP_ETHEREUM_CHAIN_ID } from './constants.js';
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { ProviderAPI, SolanaActions } from './types.js';
|
|
2
|
-
import type { Subscriber } from '../../hub/namespaces/mod.js';
|
|
2
|
+
import type { Context, Subscriber } from '../../hub/namespaces/mod.js';
|
|
3
3
|
import type { SubscriberCleanUp } from '../../hub/namespaces/types.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type { CaipAccount } from '../../types/accounts.js';
|
|
5
|
+
import type { AnyFunction, FunctionWithContext } from '../../types/actions.js';
|
|
5
6
|
|
|
6
7
|
import { AccountId } from 'caip';
|
|
7
8
|
|
|
8
9
|
import { recommended as commonRecommended } from '../common/actions.js';
|
|
9
10
|
|
|
10
11
|
import { CAIP_NAMESPACE, CAIP_SOLANA_CHAIN_ID } from './constants.js';
|
|
12
|
+
import { getAccounts } from './utils.js';
|
|
11
13
|
|
|
12
14
|
export const recommended = [...commonRecommended];
|
|
13
15
|
|
|
@@ -64,3 +66,28 @@ export function changeAccountSubscriber(
|
|
|
64
66
|
},
|
|
65
67
|
];
|
|
66
68
|
}
|
|
69
|
+
export function connect(
|
|
70
|
+
instance: () => ProviderAPI
|
|
71
|
+
): FunctionWithContext<SolanaActions['connect'], Context> {
|
|
72
|
+
return async () => {
|
|
73
|
+
const solanaInstance = instance();
|
|
74
|
+
const result = await getAccounts(solanaInstance);
|
|
75
|
+
|
|
76
|
+
if (Array.isArray(result)) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
'Expecting solana response to be a single value, not an array.'
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return result.accounts.map(
|
|
83
|
+
(account) =>
|
|
84
|
+
AccountId.format({
|
|
85
|
+
address: account,
|
|
86
|
+
chainId: {
|
|
87
|
+
namespace: CAIP_NAMESPACE,
|
|
88
|
+
reference: CAIP_SOLANA_CHAIN_ID,
|
|
89
|
+
},
|
|
90
|
+
}) as CaipAccount
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
}
|
|
@@ -3,7 +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
|
-
export * as chains from './chains.js';
|
|
7
6
|
|
|
8
7
|
export type { ProviderAPI, SolanaActions } from './types.js';
|
|
9
8
|
export { CAIP_NAMESPACE, CAIP_SOLANA_CHAIN_ID } from './constants.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ProviderAPI } from './types.js';
|
|
2
|
+
|
|
3
|
+
import { LegacyNetworks } from '../../legacy/mod.js';
|
|
4
|
+
|
|
5
|
+
export async function getAccounts(provider: ProviderAPI) {
|
|
6
|
+
const solanaResponse = await provider.connect();
|
|
7
|
+
const account = solanaResponse.publicKey.toString();
|
|
8
|
+
return {
|
|
9
|
+
accounts: [account],
|
|
10
|
+
chainId: LegacyNetworks.SOLANA,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { SuiActions } from './types.js';
|
|
2
2
|
import type { Subscriber } from '../../hub/namespaces/mod.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
CanEagerConnect,
|
|
5
|
+
SubscriberCleanUp,
|
|
6
|
+
} from '../../hub/namespaces/types.js';
|
|
4
7
|
import type { StandardEventsChangeProperties } from '@mysten/wallet-standard';
|
|
5
8
|
|
|
6
9
|
import { AccountId } from 'caip';
|
|
@@ -60,3 +63,25 @@ export function changeAccountSubscriber(
|
|
|
60
63
|
},
|
|
61
64
|
];
|
|
62
65
|
}
|
|
66
|
+
interface CanEagerConnectParams {
|
|
67
|
+
name: string;
|
|
68
|
+
}
|
|
69
|
+
export function canEagerConnect(
|
|
70
|
+
params: CanEagerConnectParams
|
|
71
|
+
): CanEagerConnect<SuiActions> {
|
|
72
|
+
return async () => {
|
|
73
|
+
const wallet = getInstanceOrThrow(params.name);
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const connectResult = await wallet.features['standard:connect'].connect({
|
|
77
|
+
silent: true,
|
|
78
|
+
});
|
|
79
|
+
if (connectResult.accounts.length) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
} catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -39,3 +39,6 @@ export const connect = (params: ConnectParams) =>
|
|
|
39
39
|
.and(connectAndUpdateStateForSingleNetwork)
|
|
40
40
|
.before(intoConnecting)
|
|
41
41
|
.after(intoConnectionFinished);
|
|
42
|
+
|
|
43
|
+
export const canEagerConnect = () =>
|
|
44
|
+
new ActionBuilder<SuiActions, 'canEagerConnect'>('canEagerConnect');
|
|
@@ -2,7 +2,6 @@ export type { ProviderAPI, SuiActions } from './types.js';
|
|
|
2
2
|
|
|
3
3
|
export * as actions from './actions.js';
|
|
4
4
|
export * as builders from './builders.js';
|
|
5
|
-
export
|
|
6
|
-
export { getInstanceOrThrow } from './utils.js';
|
|
5
|
+
export { getInstanceOrThrow, getInstance } from './utils.js';
|
|
7
6
|
|
|
8
7
|
export { CAIP_NAMESPACE, CAIP_SUI_CHAIN_ID } from './constants.js';
|
|
@@ -15,7 +15,7 @@ type SuiWalletStandard = WalletWithFeatures<
|
|
|
15
15
|
/**
|
|
16
16
|
* @param name each wallet has a name in WalletStandard. you should pass that value
|
|
17
17
|
*/
|
|
18
|
-
export function
|
|
18
|
+
export function getInstance(name: string): SuiWalletStandard | undefined {
|
|
19
19
|
const wallet = getWallets()
|
|
20
20
|
.get()
|
|
21
21
|
.find(
|
|
@@ -23,11 +23,20 @@ export function getInstanceOrThrow(name: string): SuiWalletStandard {
|
|
|
23
23
|
wallet.name === name && wallet.chains.includes(SUI_MAINNET_CHAIN)
|
|
24
24
|
);
|
|
25
25
|
|
|
26
|
+
return wallet as SuiWalletStandard;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param name each wallet has a name in WalletStandard. you should pass that value
|
|
31
|
+
*/
|
|
32
|
+
export function getInstanceOrThrow(name: string): SuiWalletStandard {
|
|
33
|
+
const wallet = getInstance(name);
|
|
34
|
+
|
|
26
35
|
if (!wallet) {
|
|
27
36
|
throw new Error(
|
|
28
37
|
"We couldn't find the Sui instance on your wallet. It may be fixed by refreshing the page."
|
|
29
38
|
);
|
|
30
39
|
}
|
|
31
40
|
|
|
32
|
-
return wallet
|
|
41
|
+
return wallet;
|
|
33
42
|
}
|
|
@@ -3,7 +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
|
-
export * as chains from './chains.js';
|
|
7
6
|
|
|
8
7
|
export type { ProviderAPI, UtxoActions } from './types.js';
|
|
9
8
|
export { CAIP_NAMESPACE, CAIP_BITCOIN_CHAIN_ID } from './constants.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../../../src/namespaces/evm/chains.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,eAAO,MAAM,QAAQ,EAAE,KAGtB,CAAC;AACF,eAAO,MAAM,OAAO,EAAE,KAGrB,CAAC;AACF,eAAO,MAAM,IAAI,EAAE,KAGlB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../../../src/namespaces/solana/chains.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,eAAO,MAAM,MAAM,EAAE,KAGpB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../../../src/namespaces/sui/chains.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,eAAO,MAAM,GAAG,EAAE,KAGjB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../../../src/namespaces/utxo/chains.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,eAAO,MAAM,OAAO,EAAE,KAGrB,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Chain } from '../common/types.js';
|
|
2
|
-
|
|
3
|
-
export const ethereum: Chain = {
|
|
4
|
-
name: 'ETH',
|
|
5
|
-
logo: 'https://raw.githubusercontent.com/rango-exchange/assets/main/blockchains/ETH/icon.svg',
|
|
6
|
-
};
|
|
7
|
-
export const polygon: Chain = {
|
|
8
|
-
name: 'POLYGON',
|
|
9
|
-
logo: 'https://raw.githubusercontent.com/rango-exchange/assets/main/blockchains/POLYGON/icon.svg',
|
|
10
|
-
};
|
|
11
|
-
export const base: Chain = {
|
|
12
|
-
name: 'BASE',
|
|
13
|
-
logo: 'https://raw.githubusercontent.com/rango-exchange/assets/main/blockchains/BASE/icon.svg',
|
|
14
|
-
};
|