@rango-dev/wallets-core 0.47.1-next.1 → 0.48.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.
- package/CHANGELOG.md +9 -0
- package/dist/hub/mod.d.ts +2 -2
- package/dist/hub/mod.d.ts.map +1 -1
- package/dist/hub/provider/mod.d.ts +1 -1
- package/dist/hub/provider/mod.d.ts.map +1 -1
- package/dist/hub/provider/provider.d.ts +2 -2
- package/dist/hub/provider/provider.d.ts.map +1 -1
- package/dist/hub/provider/types.d.ts +12 -1
- package/dist/hub/provider/types.d.ts.map +1 -1
- package/dist/hub/store/mod.d.ts +1 -1
- package/dist/hub/store/mod.d.ts.map +1 -1
- package/dist/hub/store/mod.js.map +2 -2
- package/dist/hub/store/providers.d.ts +5 -3
- package/dist/hub/store/providers.d.ts.map +1 -1
- package/dist/legacy/mod.js.map +2 -2
- package/dist/legacy/types.d.ts +2 -0
- package/dist/legacy/types.d.ts.map +1 -1
- package/dist/mod.d.ts +1 -1
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +1 -1
- package/dist/mod.js.map +3 -3
- package/dist/namespaces/common/mod.js +1 -1
- package/dist/namespaces/common/mod.js.map +2 -2
- package/dist/namespaces/evm/mod.js +1 -1
- package/dist/namespaces/evm/mod.js.map +2 -2
- package/dist/namespaces/solana/mod.js +1 -1
- package/dist/namespaces/solana/mod.js.map +2 -2
- package/dist/namespaces/sui/mod.js +1 -1
- package/dist/namespaces/sui/mod.js.map +2 -2
- package/dist/namespaces/utxo/mod.js +1 -1
- package/dist/namespaces/utxo/mod.js.map +2 -2
- package/dist/test-utils/fixtures.d.ts +4 -2
- package/dist/test-utils/fixtures.d.ts.map +1 -1
- package/dist/wallets-core.build.json +1 -1
- package/package.json +1 -1
- package/src/builders/provider.ts +1 -1
- package/src/hub/mod.ts +7 -2
- package/src/hub/provider/mod.ts +2 -0
- package/src/hub/provider/provider.test.ts +32 -52
- package/src/hub/provider/provider.ts +6 -4
- package/src/hub/provider/types.ts +16 -1
- package/src/hub/store/mod.ts +5 -1
- package/src/hub/store/providers.ts +9 -3
- package/src/hub/store/store.test.ts +7 -9
- package/src/legacy/types.ts +2 -1
- package/src/mod.ts +3 -1
- package/src/test-utils/fixtures.ts +8 -2
|
@@ -6,7 +6,11 @@ import { beforeEach, describe, expect, test, vi } from 'vitest';
|
|
|
6
6
|
|
|
7
7
|
import { NamespaceBuilder } from '../../builders/namespace.js';
|
|
8
8
|
import { ProviderBuilder } from '../../builders/provider.js';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
garbageWalletDeepLink,
|
|
11
|
+
garbageWalletInfo,
|
|
12
|
+
garbageWalletMetaData,
|
|
13
|
+
} from '../../test-utils/fixtures.js';
|
|
10
14
|
import { createStore } from '../store/mod.js';
|
|
11
15
|
|
|
12
16
|
import { Provider } from './provider.js';
|
|
@@ -46,9 +50,7 @@ describe('check providers', () => {
|
|
|
46
50
|
});
|
|
47
51
|
|
|
48
52
|
test('Initialize providers correctly', () => {
|
|
49
|
-
const provider = new Provider('garbage', namespacesMap,
|
|
50
|
-
info: garbageWalletInfo,
|
|
51
|
-
});
|
|
53
|
+
const provider = new Provider('garbage', namespacesMap, garbageWalletInfo);
|
|
52
54
|
|
|
53
55
|
const allNamespaces = provider.getAll();
|
|
54
56
|
|
|
@@ -56,48 +58,32 @@ describe('check providers', () => {
|
|
|
56
58
|
});
|
|
57
59
|
|
|
58
60
|
test('throw error if state() is called before store initialization', () => {
|
|
59
|
-
const provider = new Provider('garbage', namespacesMap,
|
|
60
|
-
info: garbageWalletInfo,
|
|
61
|
-
});
|
|
61
|
+
const provider = new Provider('garbage', namespacesMap, garbageWalletInfo);
|
|
62
62
|
|
|
63
63
|
expect(() => provider.state()).toThrowError();
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
test('should return wallet info via info() without store initialization', () => {
|
|
67
|
-
const provider = new Provider('garbage', namespacesMap,
|
|
68
|
-
info: garbageWalletInfo,
|
|
69
|
-
});
|
|
67
|
+
const provider = new Provider('garbage', namespacesMap, garbageWalletInfo);
|
|
70
68
|
|
|
71
69
|
expect(provider.info()).toBe(garbageWalletInfo);
|
|
72
70
|
});
|
|
73
71
|
|
|
74
72
|
test('should return wallet info via info() after store initialization', () => {
|
|
75
73
|
const store = createStore();
|
|
76
|
-
const provider = new Provider(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
{
|
|
80
|
-
info: garbageWalletInfo,
|
|
81
|
-
},
|
|
82
|
-
{ store }
|
|
83
|
-
);
|
|
74
|
+
const provider = new Provider('garbage', namespacesMap, garbageWalletInfo, {
|
|
75
|
+
store,
|
|
76
|
+
});
|
|
84
77
|
|
|
85
|
-
expect(provider.info()).
|
|
86
|
-
store.getState().providers.list['garbage'].config
|
|
78
|
+
expect(provider.info()).toMatchObject(
|
|
79
|
+
store.getState().providers.list['garbage'].config
|
|
87
80
|
);
|
|
88
81
|
});
|
|
89
82
|
|
|
90
83
|
test('access state correctly', () => {
|
|
91
|
-
const provider = new Provider(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
{
|
|
95
|
-
info: garbageWalletInfo,
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
store: createStore(),
|
|
99
|
-
}
|
|
100
|
-
);
|
|
84
|
+
const provider = new Provider('garbage', namespacesMap, garbageWalletInfo, {
|
|
85
|
+
store: createStore(),
|
|
86
|
+
});
|
|
101
87
|
|
|
102
88
|
const [getState, setState] = provider.state();
|
|
103
89
|
|
|
@@ -114,16 +100,9 @@ describe('check providers', () => {
|
|
|
114
100
|
});
|
|
115
101
|
test('update state properly', () => {
|
|
116
102
|
const store = createStore();
|
|
117
|
-
const provider = new Provider(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
{
|
|
121
|
-
info: garbageWalletInfo,
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
store,
|
|
125
|
-
}
|
|
126
|
-
);
|
|
103
|
+
const provider = new Provider('garbage', namespacesMap, garbageWalletInfo, {
|
|
104
|
+
store,
|
|
105
|
+
});
|
|
127
106
|
|
|
128
107
|
const [getState, setState] = provider.state();
|
|
129
108
|
|
|
@@ -142,9 +121,7 @@ describe('check providers', () => {
|
|
|
142
121
|
testNamespaces.set('evm', evm.build());
|
|
143
122
|
testNamespaces.set('solana', solana.build());
|
|
144
123
|
|
|
145
|
-
const provider = new Provider('garbage', testNamespaces,
|
|
146
|
-
info: garbageWalletInfo,
|
|
147
|
-
});
|
|
124
|
+
const provider = new Provider('garbage', testNamespaces, garbageWalletInfo);
|
|
148
125
|
|
|
149
126
|
const result = await provider.get('solana')?.connect();
|
|
150
127
|
|
|
@@ -159,16 +136,19 @@ describe('check providers', () => {
|
|
|
159
136
|
|
|
160
137
|
test('sets config properly', () => {
|
|
161
138
|
const builder = new ProviderBuilder('garbage');
|
|
162
|
-
builder
|
|
139
|
+
builder
|
|
140
|
+
.config('metadata', garbageWalletMetaData)
|
|
141
|
+
.config('deepLink', garbageWalletDeepLink);
|
|
163
142
|
const provider = builder.build().store(store);
|
|
164
143
|
|
|
165
|
-
expect(provider.info()).toStrictEqual(
|
|
144
|
+
expect(provider.info()?.metadata).toStrictEqual(garbageWalletMetaData);
|
|
145
|
+
expect(provider.info()?.deepLink).toStrictEqual(garbageWalletDeepLink);
|
|
166
146
|
});
|
|
167
147
|
|
|
168
148
|
test('.init should works on Provider', () => {
|
|
169
149
|
const builder = new ProviderBuilder('garbage').config(
|
|
170
|
-
'
|
|
171
|
-
|
|
150
|
+
'metadata',
|
|
151
|
+
garbageWalletMetaData
|
|
172
152
|
);
|
|
173
153
|
let count = 0;
|
|
174
154
|
builder.init(() => {
|
|
@@ -184,8 +164,8 @@ describe('check providers', () => {
|
|
|
184
164
|
|
|
185
165
|
test(".init shouldn't do anything when use hasn't set anything", () => {
|
|
186
166
|
const builder = new ProviderBuilder('garbage').config(
|
|
187
|
-
'
|
|
188
|
-
|
|
167
|
+
'metadata',
|
|
168
|
+
garbageWalletMetaData
|
|
189
169
|
);
|
|
190
170
|
const provider = builder.build().store(store);
|
|
191
171
|
expect(() => {
|
|
@@ -197,8 +177,8 @@ describe('check providers', () => {
|
|
|
197
177
|
|
|
198
178
|
test('A provider can be found using its namespace', () => {
|
|
199
179
|
const builder = new ProviderBuilder('garbage', { store }).config(
|
|
200
|
-
'
|
|
201
|
-
|
|
180
|
+
'metadata',
|
|
181
|
+
garbageWalletMetaData
|
|
202
182
|
);
|
|
203
183
|
|
|
204
184
|
const { evm, solana } = namespaces;
|
|
@@ -231,7 +211,7 @@ describe('check providers', () => {
|
|
|
231
211
|
|
|
232
212
|
const builder = new ProviderBuilder('garbage', { store })
|
|
233
213
|
.add('evm', evmNamespace)
|
|
234
|
-
.config('
|
|
214
|
+
.config('metadata', garbageWalletMetaData);
|
|
235
215
|
const provider = builder.build();
|
|
236
216
|
|
|
237
217
|
const [getState] = provider.state();
|
|
@@ -9,7 +9,7 @@ import type {
|
|
|
9
9
|
} from './types.js';
|
|
10
10
|
import type { FindProxiedNamespace } from '../../builders/mod.js';
|
|
11
11
|
import type { AnyFunction, FunctionWithContext } from '../../types/actions.js';
|
|
12
|
-
import type { ProviderConfig, Store } from '../store/mod.js';
|
|
12
|
+
import type { ProviderConfig, ProviderInfo, Store } from '../store/mod.js';
|
|
13
13
|
|
|
14
14
|
const VERSION = '1.0';
|
|
15
15
|
|
|
@@ -180,12 +180,14 @@ export class Provider {
|
|
|
180
180
|
* provider.info();
|
|
181
181
|
* ```
|
|
182
182
|
*/
|
|
183
|
-
public info():
|
|
183
|
+
public info(): ProviderInfo | undefined {
|
|
184
184
|
const store = this.#store;
|
|
185
185
|
if (!store) {
|
|
186
|
-
return this.#configs
|
|
186
|
+
return this.#configs;
|
|
187
187
|
}
|
|
188
|
-
|
|
188
|
+
const config = store.getState().providers.list[this.id].config;
|
|
189
|
+
|
|
190
|
+
return { metadata: config.metadata, deepLink: config.deepLink };
|
|
189
191
|
}
|
|
190
192
|
|
|
191
193
|
/**
|
|
@@ -13,7 +13,10 @@ export type Context = {
|
|
|
13
13
|
state: () => [GetState, SetState];
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
export type State = Omit<
|
|
16
|
+
export type State = Omit<
|
|
17
|
+
LegacyState,
|
|
18
|
+
'reachable' | 'accounts' | 'network' | 'derivationPath'
|
|
19
|
+
>;
|
|
17
20
|
export type SetState = <K extends keyof Pick<State, 'installed'>>(
|
|
18
21
|
name: K,
|
|
19
22
|
value: State[K]
|
|
@@ -43,3 +46,15 @@ export type RegisteredNamespaces<K extends keyof T, T> = Map<
|
|
|
43
46
|
>;
|
|
44
47
|
|
|
45
48
|
export type ProviderBuilderOptions = { store?: Store };
|
|
49
|
+
export type GenerateDeepLink = (context: DeepLinkContext) => string;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Deeplink parameters context.
|
|
53
|
+
*
|
|
54
|
+
* @param targetUrl - URL of the widget in the app to be opened in the in-app browser.
|
|
55
|
+
* @param appHost - Domain of the app where the widget has been implemented.
|
|
56
|
+
*/
|
|
57
|
+
export type DeepLinkContext = {
|
|
58
|
+
targetUrl: string;
|
|
59
|
+
appHost: string;
|
|
60
|
+
};
|
package/src/hub/store/mod.ts
CHANGED
|
@@ -16,6 +16,10 @@ export type {
|
|
|
16
16
|
NamespaceConnectedEvent,
|
|
17
17
|
NamespaceSwitchedAccountEvent,
|
|
18
18
|
} from './events.js';
|
|
19
|
-
export type {
|
|
19
|
+
export type {
|
|
20
|
+
ProviderMetadata,
|
|
21
|
+
ProviderConfig,
|
|
22
|
+
ProviderInfo,
|
|
23
|
+
} from './providers.js';
|
|
20
24
|
export type { NamespaceConfig, NamespaceData } from './namespaces.js';
|
|
21
25
|
export { createStore } from './store.js';
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { Namespace } from '../../namespaces/common/types.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
GenerateDeepLink,
|
|
4
|
+
State as InternalProviderState,
|
|
5
|
+
} from '../provider/mod.js';
|
|
3
6
|
import type { BlockchainMeta, SignerFactory } from 'rango-types';
|
|
4
7
|
import type { StateCreator } from 'zustand';
|
|
5
8
|
|
|
@@ -50,7 +53,7 @@ type SignersProperty = Property<
|
|
|
50
53
|
}
|
|
51
54
|
>;
|
|
52
55
|
|
|
53
|
-
export type
|
|
56
|
+
export type ProviderMetadata = {
|
|
54
57
|
name: string;
|
|
55
58
|
icon: string;
|
|
56
59
|
extensions: Partial<Record<Browsers, string>>;
|
|
@@ -63,9 +66,12 @@ export type ProviderInfo = {
|
|
|
63
66
|
};
|
|
64
67
|
|
|
65
68
|
export interface ProviderConfig {
|
|
66
|
-
|
|
69
|
+
metadata: ProviderMetadata;
|
|
70
|
+
deepLink?: GenerateDeepLink;
|
|
67
71
|
}
|
|
68
72
|
|
|
73
|
+
export type ProviderInfo = ProviderConfig;
|
|
74
|
+
|
|
69
75
|
interface ProviderData {
|
|
70
76
|
installed: boolean;
|
|
71
77
|
}
|
|
@@ -14,7 +14,7 @@ describe('checking store', () => {
|
|
|
14
14
|
test('new providers can be added to store', () => {
|
|
15
15
|
const id = 'sol-or-something';
|
|
16
16
|
const info = {
|
|
17
|
-
|
|
17
|
+
metadata: {
|
|
18
18
|
name: 'sol grabage wallet',
|
|
19
19
|
icon: 'http://somewhere.world',
|
|
20
20
|
extensions: {
|
|
@@ -31,18 +31,16 @@ describe('checking store', () => {
|
|
|
31
31
|
});
|
|
32
32
|
test('provider can be removed from store', () => {
|
|
33
33
|
const id = 'sol-or-something';
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
homepage: 'http://somewhere.world',
|
|
40
|
-
},
|
|
34
|
+
const metadata = {
|
|
35
|
+
name: 'sol grabage wallet',
|
|
36
|
+
icon: 'http://somewhere.world',
|
|
37
|
+
extensions: {
|
|
38
|
+
homepage: 'http://somewhere.world',
|
|
41
39
|
},
|
|
42
40
|
};
|
|
43
41
|
|
|
44
42
|
const { getState } = hubStore;
|
|
45
|
-
getState().providers.addProvider(id,
|
|
43
|
+
getState().providers.addProvider(id, { metadata });
|
|
46
44
|
expect(getState().providers.list[id]).toBeDefined();
|
|
47
45
|
expect(Object.keys(getState().providers.list).length).toBe(1);
|
|
48
46
|
getState().providers.removeProvider(id);
|
package/src/legacy/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { State as WalletState } from './wallet.js';
|
|
2
|
+
import type { GenerateDeepLink } from '../mod.js';
|
|
2
3
|
import type { Namespace } from '../namespaces/common/mod.js';
|
|
3
4
|
import type { BlockchainMeta, SignerFactory } from 'rango-types';
|
|
4
5
|
|
|
@@ -123,7 +124,7 @@ export type WalletInfo = {
|
|
|
123
124
|
showOnMobile?: boolean;
|
|
124
125
|
isContractWallet?: boolean;
|
|
125
126
|
mobileWallet?: boolean;
|
|
126
|
-
|
|
127
|
+
generateDeepLink?: GenerateDeepLink;
|
|
127
128
|
needsDerivationPath?: NeedsDerivationPath;
|
|
128
129
|
needsNamespace?: NeedsNamespace;
|
|
129
130
|
};
|
package/src/mod.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import type { ProviderConfig } from '../hub/store/mod.js';
|
|
1
|
+
import type { ProviderConfig, ProviderInfo } from '../hub/store/mod.js';
|
|
2
2
|
|
|
3
|
-
export const
|
|
3
|
+
export const garbageWalletMetaData: ProviderConfig['metadata'] = {
|
|
4
4
|
name: 'Garbage Wallet',
|
|
5
5
|
icon: 'https://somewhereininternet.com/icon.svg',
|
|
6
6
|
extensions: {
|
|
7
7
|
homepage: 'https://app.rango.exchange',
|
|
8
8
|
},
|
|
9
9
|
};
|
|
10
|
+
export const garbageWalletDeepLink: ProviderConfig['deepLink'] = () =>
|
|
11
|
+
'garbage link';
|
|
12
|
+
export const garbageWalletInfo: ProviderInfo = {
|
|
13
|
+
metadata: garbageWalletMetaData,
|
|
14
|
+
deepLink: garbageWalletDeepLink,
|
|
15
|
+
};
|