Skip to content

Commit a85571f

Browse files
committed
fix: return provider info with optional store
1 parent 3f2dfb9 commit a85571f

File tree

4 files changed

+39
-49
lines changed

4 files changed

+39
-49
lines changed

wallets/core/src/hub/provider/provider.test.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,37 @@ describe('check providers', () => {
5454

5555
expect(allNamespaces.size).toBe(2);
5656
});
57-
test("throw an error if store hasn't set and try to access .state() and .info()", () => {
57+
58+
test('throw error if state() is called before store initialization', () => {
5859
const provider = new Provider('garbage', namespacesMap, {
5960
info: garbageWalletInfo,
6061
});
6162

6263
expect(() => provider.state()).toThrowError();
63-
expect(() => provider.info()).toThrowError();
64+
});
65+
66+
test('should return wallet info via info() without store initialization', () => {
67+
const provider = new Provider('garbage', namespacesMap, {
68+
info: garbageWalletInfo,
69+
});
70+
71+
expect(provider.info()).toBe(garbageWalletInfo);
72+
});
73+
74+
test('should return wallet info via info() after store initialization', () => {
75+
const store = createStore();
76+
const provider = new Provider(
77+
'garbage',
78+
namespacesMap,
79+
{
80+
info: garbageWalletInfo,
81+
},
82+
{ store }
83+
);
84+
85+
expect(provider.info()).toBe(
86+
store.getState().providers.list['garbage'].config.info
87+
);
6488
});
6589

6690
test('access state correctly', () => {

wallets/core/src/hub/provider/provider.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export class Provider {
4242
this.#extendInternalActions = options?.extendInternalActions || {};
4343
this.#namespaces = namespaces;
4444

45+
/**
46+
* Our assumption is that the store will be optional for the provider.
47+
* If a store is provided in the options, it will be initialized and set up.
48+
*/
4549
if (options?.store) {
4650
this.#store = options.store;
4751
this.#setupStore();
@@ -179,11 +183,8 @@ export class Provider {
179183
public info(): ProviderConfig['info'] | undefined {
180184
const store = this.#store;
181185
if (!store) {
182-
throw new Error(
183-
'You need to set your store using `.store` method first.'
184-
);
186+
return this.#configs.info;
185187
}
186-
187188
return store.getState().providers.list[this.id].config.info;
188189
}
189190

wallets/provider-slush/src/legacy/index.ts

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ import type { LegacyProviderInterface } from '@rango-dev/wallets-core/legacy';
22
import type { Connect, WalletInfo } from '@rango-dev/wallets-shared';
33

44
import { WalletTypes } from '@rango-dev/wallets-shared';
5-
import {
6-
type BlockchainMeta,
7-
type SignerFactory,
8-
type SuiBlockchainMeta,
9-
TransactionType,
10-
} from 'rango-types';
5+
import { type BlockchainMeta, type SignerFactory } from 'rango-types';
116

127
import { suiWalletInstance } from '../utils.js';
138

@@ -31,40 +26,10 @@ const connect: Connect = async () => {
3126
export const getSigners: (provider: Provider) => Promise<SignerFactory> =
3227
signer;
3328

34-
export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
35-
allBlockChains
36-
) => {
37-
const sui = allBlockChains.filter(
38-
(blockchain) => blockchain.type === TransactionType.SUI
39-
);
40-
41-
return {
42-
name: 'Slush',
43-
img: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/slush/icon.svg',
44-
installLink: {
45-
CHROME:
46-
'https://chromewebstore.google.com/detail/slush-%E2%80%94-a-sui-wallet/opcgpfmipidbgpenhmajoajpbobppdil',
47-
DEFAULT: 'https://slush.app/download',
48-
},
49-
color: '#4d40c6',
50-
// if you are adding a new namespace, don't forget to also update `properties`
51-
needsNamespace: {
52-
selection: 'multiple',
53-
data: [
54-
{
55-
label: 'Sui',
56-
value: 'Sui',
57-
id: 'SUI',
58-
getSupportedChains: (allBlockchains: BlockchainMeta[]) =>
59-
allBlockchains.filter(
60-
(chain): chain is SuiBlockchainMeta =>
61-
chain.type === TransactionType.SUI
62-
),
63-
},
64-
],
65-
},
66-
supportedChains: sui,
67-
};
29+
export const getWalletInfo: (
30+
allBlockChains: BlockchainMeta[]
31+
) => WalletInfo = () => {
32+
throw new Error('not implemented');
6833
};
6934

7035
const buildLegacyProvider: () => LegacyProviderInterface = () => ({

widget/playground/src/containers/FunctionalLayout/FunctionalLayout.utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ export function getWalletsList(
4646
const namespacesProperty = providerProperties?.find(
4747
(property) => property.name === 'namespaces'
4848
);
49-
const supportedChainsNames = namespacesProperty?.value.data
50-
.flatMap((obj) => obj.chains)
51-
.map((chain) => chain.name);
49+
const supportedChainsNames = namespacesProperty?.value.data.flatMap(
50+
(obj) => obj.id
51+
);
5252

5353
const supportedChains = blockchains?.filter((blockchain) =>
5454
supportedChainsNames?.includes(blockchain.name)

0 commit comments

Comments
 (0)