@rango-dev/widget-embedded 0.36.1-next.14 → 0.36.1-next.16
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/components/Quote/Quote.styles.d.ts +1 -1
- package/dist/components/RefreshModal/RefreshModal.styles.d.ts +1 -1
- package/dist/hooks/useWalletList.d.ts.map +1 -1
- package/dist/hooks/useWalletProviders/useWalletProviders.d.ts +1 -1
- package/dist/hooks/useWalletProviders/useWalletProviders.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/store/slices/config.d.ts +4 -0
- package/dist/store/slices/config.d.ts.map +1 -1
- package/dist/utils/providers.d.ts +6 -2
- package/dist/utils/providers.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +8 -8
- package/src/hooks/useWalletList.ts +6 -6
- package/src/hooks/useWalletProviders/useWalletProviders.ts +7 -7
- package/src/store/slices/config.ts +73 -0
- package/src/store/slices/data.test.ts +23 -1
- package/src/utils/providers.ts +35 -46
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/widget-embedded",
|
|
3
|
-
"version": "0.36.1-next.
|
|
3
|
+
"version": "0.36.1-next.16",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
"@lingui/core": "4.2.1",
|
|
26
26
|
"@lingui/react": "4.2.1",
|
|
27
27
|
"@rango-dev/logging-core": "^0.6.0",
|
|
28
|
-
"@rango-dev/provider-all": "^0.40.1-next.
|
|
28
|
+
"@rango-dev/provider-all": "^0.40.1-next.8",
|
|
29
29
|
"@rango-dev/queue-manager-core": "^0.27.0",
|
|
30
|
-
"@rango-dev/queue-manager-rango-preset": "^0.40.1-next.
|
|
30
|
+
"@rango-dev/queue-manager-rango-preset": "^0.40.1-next.6",
|
|
31
31
|
"@rango-dev/queue-manager-react": "^0.27.0",
|
|
32
32
|
"@rango-dev/signer-solana": "^0.35.1-next.0",
|
|
33
|
-
"@rango-dev/ui": "^0.42.1-next.
|
|
34
|
-
"@rango-dev/wallets-core": "^0.40.1-next.
|
|
35
|
-
"@rango-dev/wallets-react": "^0.26.1-next.
|
|
36
|
-
"@rango-dev/wallets-shared": "^0.40.1-next.
|
|
33
|
+
"@rango-dev/ui": "^0.42.1-next.11",
|
|
34
|
+
"@rango-dev/wallets-core": "^0.40.1-next.8",
|
|
35
|
+
"@rango-dev/wallets-react": "^0.26.1-next.9",
|
|
36
|
+
"@rango-dev/wallets-shared": "^0.40.1-next.6",
|
|
37
37
|
"bignumber.js": "^9.1.1",
|
|
38
38
|
"copy-to-clipboard": "^3.3.3",
|
|
39
39
|
"dayjs": "^1.11.7",
|
|
@@ -54,4 +54,4 @@
|
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|
|
56
56
|
}
|
|
57
|
-
}
|
|
57
|
+
}
|
|
@@ -22,8 +22,6 @@ import {
|
|
|
22
22
|
|
|
23
23
|
import { useStatefulConnect } from './useStatefulConnect/useStatefulConnect';
|
|
24
24
|
|
|
25
|
-
const ALL_SUPPORTED_WALLETS = Object.values(WalletTypes);
|
|
26
|
-
|
|
27
25
|
interface Params {
|
|
28
26
|
chain?: string;
|
|
29
27
|
}
|
|
@@ -42,20 +40,22 @@ interface API {
|
|
|
42
40
|
*/
|
|
43
41
|
export function useWalletList(params?: Params): API {
|
|
44
42
|
const { chain } = params || {};
|
|
45
|
-
const { config, connectedWallets } = useAppStore();
|
|
43
|
+
const { config, connectedWallets, getAvailableProviders } = useAppStore();
|
|
46
44
|
const { state, getWalletInfo } = useWallets();
|
|
47
45
|
const blockchains = useAppStore().blockchains();
|
|
48
46
|
const { handleDisconnect } = useStatefulConnect();
|
|
49
47
|
|
|
50
48
|
/** It can be what has been set by widget config or as a fallback we use all the supported wallets by our library */
|
|
51
|
-
const listAvailableWalletTypes =
|
|
52
|
-
|
|
49
|
+
const listAvailableWalletTypes = configWalletsToWalletName(
|
|
50
|
+
getAvailableProviders(),
|
|
51
|
+
{
|
|
53
52
|
trezorManifest: config?.trezorManifest,
|
|
54
53
|
walletConnectProjectId: config?.walletConnectProjectId,
|
|
55
54
|
walletConnectListedDesktopWalletLink:
|
|
56
55
|
config.__UNSTABLE_OR_INTERNAL__?.walletConnectListedDesktopWalletLink,
|
|
57
56
|
tonConnect: config.tonConnect,
|
|
58
|
-
}
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
59
|
|
|
60
60
|
let wallets = mapWalletTypesToWalletInfo(
|
|
61
61
|
state,
|
|
@@ -4,27 +4,27 @@ import type { ProvidersOptions } from '../../utils/providers';
|
|
|
4
4
|
import { useEffect } from 'react';
|
|
5
5
|
|
|
6
6
|
import { useAppStore } from '../../store/AppStore';
|
|
7
|
-
import { matchAndGenerateProviders } from '../../utils/providers';
|
|
8
7
|
|
|
9
8
|
import { hashProviders } from './useWalletProviders.helpers';
|
|
10
9
|
|
|
11
10
|
export function useWalletProviders(
|
|
12
|
-
|
|
11
|
+
configWallets: WidgetConfig['wallets'],
|
|
13
12
|
options?: ProvidersOptions
|
|
14
13
|
) {
|
|
15
|
-
const { clearConnectedWallet } =
|
|
16
|
-
|
|
14
|
+
const { clearConnectedWallet, getAvailableProviders, buildAndSetProviders } =
|
|
15
|
+
useAppStore();
|
|
16
|
+
const providers = getAvailableProviders();
|
|
17
17
|
|
|
18
18
|
useEffect(() => {
|
|
19
19
|
clearConnectedWallet();
|
|
20
|
-
|
|
20
|
+
buildAndSetProviders();
|
|
21
21
|
}, [
|
|
22
|
-
hashProviders(
|
|
22
|
+
hashProviders(configWallets ?? []),
|
|
23
23
|
options?.walletConnectProjectId,
|
|
24
24
|
options?.walletConnectListedDesktopWalletLink,
|
|
25
25
|
]);
|
|
26
26
|
|
|
27
27
|
return {
|
|
28
|
-
providers
|
|
28
|
+
providers,
|
|
29
29
|
};
|
|
30
30
|
}
|
|
@@ -3,9 +3,31 @@ import type { SettingsSlice } from './settings';
|
|
|
3
3
|
import type { WidgetConfig } from '../../types';
|
|
4
4
|
import type { StateCreatorWithInitialData } from '../app';
|
|
5
5
|
|
|
6
|
+
import { allProviders as getAllProviders } from '@rango-dev/provider-all';
|
|
7
|
+
import { type VersionedProviders } from '@rango-dev/wallets-core';
|
|
8
|
+
|
|
6
9
|
import { cacheService } from '../../services/cacheService';
|
|
10
|
+
import {
|
|
11
|
+
matchAndGenerateProviders,
|
|
12
|
+
type ProvidersOptions,
|
|
13
|
+
} from '../../utils/providers';
|
|
7
14
|
import { matchTokensFromConfigWithMeta } from '../utils';
|
|
8
15
|
|
|
16
|
+
function makeProvidersOptionsFromConfig(
|
|
17
|
+
config: WidgetConfig
|
|
18
|
+
): ProvidersOptions {
|
|
19
|
+
const options: ProvidersOptions = {
|
|
20
|
+
walletConnectProjectId: config?.walletConnectProjectId,
|
|
21
|
+
trezorManifest: config?.trezorManifest,
|
|
22
|
+
tonConnect: config?.tonConnect,
|
|
23
|
+
walletConnectListedDesktopWalletLink:
|
|
24
|
+
config.__UNSTABLE_OR_INTERNAL__?.walletConnectListedDesktopWalletLink,
|
|
25
|
+
experimentalWallet: config.features?.experimentalWallet,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return options;
|
|
29
|
+
}
|
|
30
|
+
|
|
9
31
|
export const DEFAULT_CONFIG: WidgetConfig = {
|
|
10
32
|
apiKey: '',
|
|
11
33
|
title: undefined,
|
|
@@ -61,6 +83,31 @@ export interface ConfigSlice {
|
|
|
61
83
|
name: K,
|
|
62
84
|
value: IframeConfigs[K]
|
|
63
85
|
) => void;
|
|
86
|
+
allProviders: VersionedProviders[];
|
|
87
|
+
buildAndSetProviders: () => void;
|
|
88
|
+
getAvailableProviders: () => VersionedProviders[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function generateProviders(config: WidgetConfig) {
|
|
92
|
+
const options = makeProvidersOptionsFromConfig(config);
|
|
93
|
+
const envs = {
|
|
94
|
+
walletconnect2: {
|
|
95
|
+
WC_PROJECT_ID: options?.walletConnectProjectId || '',
|
|
96
|
+
DISABLE_MODAL_AND_OPEN_LINK:
|
|
97
|
+
options?.walletConnectListedDesktopWalletLink,
|
|
98
|
+
},
|
|
99
|
+
selectedProviders: config.wallets,
|
|
100
|
+
trezor: options?.trezorManifest
|
|
101
|
+
? { manifest: options.trezorManifest }
|
|
102
|
+
: undefined,
|
|
103
|
+
tonConnect: options?.tonConnect?.manifestUrl
|
|
104
|
+
? { manifestUrl: options?.tonConnect.manifestUrl }
|
|
105
|
+
: undefined,
|
|
106
|
+
};
|
|
107
|
+
const allProviders = getAllProviders(envs);
|
|
108
|
+
const allBuiltProviders = allProviders.map((build) => build());
|
|
109
|
+
|
|
110
|
+
return allBuiltProviders;
|
|
64
111
|
}
|
|
65
112
|
|
|
66
113
|
export const createConfigSlice: StateCreatorWithInitialData<
|
|
@@ -68,10 +115,15 @@ export const createConfigSlice: StateCreatorWithInitialData<
|
|
|
68
115
|
ConfigSlice & SettingsSlice & DataSlice,
|
|
69
116
|
ConfigSlice
|
|
70
117
|
> = (initialData, set, get) => {
|
|
118
|
+
const allBuiltProviders = generateProviders({
|
|
119
|
+
...DEFAULT_CONFIG,
|
|
120
|
+
...initialData,
|
|
121
|
+
});
|
|
71
122
|
return {
|
|
72
123
|
config: { ...DEFAULT_CONFIG, ...initialData },
|
|
73
124
|
iframe: DEFAULT_IFRAME_CONFIGS,
|
|
74
125
|
campaignMode: DEFAULT_CAMPAIGN_MODE,
|
|
126
|
+
allProviders: allBuiltProviders,
|
|
75
127
|
getLiquiditySources: () => {
|
|
76
128
|
const { config, campaignMode } = get();
|
|
77
129
|
return campaignMode.liquiditySources?.length
|
|
@@ -162,5 +214,26 @@ export const createConfigSlice: StateCreatorWithInitialData<
|
|
|
162
214
|
},
|
|
163
215
|
});
|
|
164
216
|
},
|
|
217
|
+
|
|
218
|
+
buildAndSetProviders: () => {
|
|
219
|
+
const { config } = get();
|
|
220
|
+
const allBuiltProviders = generateProviders(config);
|
|
221
|
+
|
|
222
|
+
set({
|
|
223
|
+
allProviders: allBuiltProviders,
|
|
224
|
+
});
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
getAvailableProviders: () => {
|
|
228
|
+
const { allProviders, config } = get();
|
|
229
|
+
const options = makeProvidersOptionsFromConfig(config);
|
|
230
|
+
|
|
231
|
+
const availableProviders = matchAndGenerateProviders({
|
|
232
|
+
allProviders,
|
|
233
|
+
configWallets: config.wallets,
|
|
234
|
+
options,
|
|
235
|
+
});
|
|
236
|
+
return availableProviders;
|
|
237
|
+
},
|
|
165
238
|
};
|
|
166
239
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { WidgetConfig } from '../../types';
|
|
1
2
|
import type { AppStoreState } from '../app';
|
|
2
3
|
import type { EvmBlockchainMeta, Token } from 'rango-sdk';
|
|
3
4
|
|
|
@@ -17,6 +18,27 @@ let appStoreState: AppStoreState;
|
|
|
17
18
|
let customTokens: [Token, Token, Token];
|
|
18
19
|
let rangoBlockchain: EvmBlockchainMeta;
|
|
19
20
|
|
|
21
|
+
const DEFAULT_CONFIG: WidgetConfig = {
|
|
22
|
+
apiKey: '',
|
|
23
|
+
walletConnectProjectId: 'e24844c5deb5193c1c14840a7af6a40b',
|
|
24
|
+
title: undefined,
|
|
25
|
+
multiWallets: true,
|
|
26
|
+
excludeLiquiditySources: true,
|
|
27
|
+
customDestination: true,
|
|
28
|
+
variant: 'default',
|
|
29
|
+
trezorManifest: {
|
|
30
|
+
appUrl: 'https://widget.rango.exchange/',
|
|
31
|
+
email: 'hi+trezorwidget@rango.exchange',
|
|
32
|
+
},
|
|
33
|
+
tonConnect: {
|
|
34
|
+
manifestUrl:
|
|
35
|
+
'https://raw.githubusercontent.com/rango-exchange/rango-types/main/assets/manifests/tonconnect-manifest.json',
|
|
36
|
+
},
|
|
37
|
+
features: {
|
|
38
|
+
experimentalWallet: 'enabled',
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
20
42
|
beforeEach(() => {
|
|
21
43
|
cacheService.clear();
|
|
22
44
|
rangoBlockchain = createEvmBlockchain();
|
|
@@ -60,7 +82,7 @@ beforeEach(() => {
|
|
|
60
82
|
initData._tokensMapByBlockchainName[token.blockchain].push(tokenHash);
|
|
61
83
|
});
|
|
62
84
|
|
|
63
|
-
const appStore = createAppStore();
|
|
85
|
+
const appStore = createAppStore(DEFAULT_CONFIG);
|
|
64
86
|
appStore.setState(initData);
|
|
65
87
|
appStoreState = appStore.getState();
|
|
66
88
|
});
|
package/src/utils/providers.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { WidgetConfig } from '../types';
|
|
2
2
|
import type { LegacyProviderInterface } from '@rango-dev/wallets-core/legacy';
|
|
3
3
|
|
|
4
|
-
import { allProviders } from '@rango-dev/provider-all';
|
|
5
4
|
import {
|
|
6
5
|
defineVersions,
|
|
7
6
|
pickVersion,
|
|
@@ -26,42 +25,30 @@ export interface ProvidersOptions {
|
|
|
26
25
|
*
|
|
27
26
|
*/
|
|
28
27
|
type BothProvidersInterface = LegacyProviderInterface | Provider;
|
|
29
|
-
export function matchAndGenerateProviders(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
selectedProviders: providers,
|
|
40
|
-
trezor: options?.trezorManifest
|
|
41
|
-
? { manifest: options.trezorManifest }
|
|
42
|
-
: undefined,
|
|
43
|
-
tonConnect: options?.tonConnect?.manifestUrl
|
|
44
|
-
? { manifestUrl: options?.tonConnect.manifestUrl }
|
|
45
|
-
: undefined,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const all = allProviders(envs);
|
|
49
|
-
|
|
50
|
-
if (providers) {
|
|
28
|
+
export function matchAndGenerateProviders({
|
|
29
|
+
allProviders,
|
|
30
|
+
configWallets,
|
|
31
|
+
options,
|
|
32
|
+
}: {
|
|
33
|
+
allProviders: VersionedProviders[];
|
|
34
|
+
configWallets: WidgetConfig['wallets'];
|
|
35
|
+
options?: ProvidersOptions;
|
|
36
|
+
}): VersionedProviders[] {
|
|
37
|
+
if (configWallets) {
|
|
51
38
|
/*
|
|
52
39
|
* If `wallets` is included in widget config,
|
|
53
40
|
* allProviders should be filtered based on wallets list
|
|
54
41
|
*/
|
|
55
42
|
const selectedProviders: VersionedProviders[] = [];
|
|
56
43
|
|
|
57
|
-
|
|
44
|
+
configWallets.forEach((requestedWallet) => {
|
|
58
45
|
/*
|
|
59
46
|
* There are two types of provider we get, the first one is only passing the wallet name
|
|
60
47
|
* then we will match the wallet name with our providers (@rango-dev/provider-*).
|
|
61
48
|
* The second way is passing a custom provider which implemented ProviderInterface.
|
|
62
49
|
*/
|
|
63
|
-
if (typeof
|
|
64
|
-
const result =
|
|
50
|
+
if (typeof requestedWallet === 'string') {
|
|
51
|
+
const result = allProviders.find((provider) => {
|
|
65
52
|
/*
|
|
66
53
|
* To find a provider in allProviders,
|
|
67
54
|
* a version of each provider should be picked
|
|
@@ -74,9 +61,9 @@ export function matchAndGenerateProviders(
|
|
|
74
61
|
options
|
|
75
62
|
);
|
|
76
63
|
if (versionedProvider instanceof Provider) {
|
|
77
|
-
return versionedProvider.id ===
|
|
64
|
+
return versionedProvider.id === requestedWallet;
|
|
78
65
|
}
|
|
79
|
-
return versionedProvider.config.type ===
|
|
66
|
+
return versionedProvider.config.type === requestedWallet;
|
|
80
67
|
});
|
|
81
68
|
|
|
82
69
|
/*
|
|
@@ -86,20 +73,21 @@ export function matchAndGenerateProviders(
|
|
|
86
73
|
*/
|
|
87
74
|
if (result) {
|
|
88
75
|
selectedProviders.push(result);
|
|
76
|
+
} else {
|
|
77
|
+
console.warn(
|
|
78
|
+
// A provider name is included in config but was not found in allProviders
|
|
79
|
+
`Couldn't find ${requestedWallet} provider. Please make sure you are passing the correct name.`
|
|
80
|
+
);
|
|
89
81
|
}
|
|
90
|
-
console.warn(
|
|
91
|
-
// A provider name is included in config but was not found in allProviders
|
|
92
|
-
`Couldn't find ${requestedProvider} provider. Please make sure you are passing the correct name.`
|
|
93
|
-
);
|
|
94
82
|
} else {
|
|
95
83
|
// It's a custom provider so we directly push it to the list.
|
|
96
|
-
if (
|
|
84
|
+
if (requestedWallet instanceof Provider) {
|
|
97
85
|
selectedProviders.push(
|
|
98
|
-
defineVersions().version('1.0.0',
|
|
86
|
+
defineVersions().version('1.0.0', requestedWallet).build()
|
|
99
87
|
);
|
|
100
88
|
} else {
|
|
101
89
|
selectedProviders.push(
|
|
102
|
-
defineVersions().version('0.0.0',
|
|
90
|
+
defineVersions().version('0.0.0', requestedWallet).build()
|
|
103
91
|
);
|
|
104
92
|
}
|
|
105
93
|
}
|
|
@@ -108,7 +96,7 @@ export function matchAndGenerateProviders(
|
|
|
108
96
|
return selectedProviders;
|
|
109
97
|
}
|
|
110
98
|
|
|
111
|
-
return
|
|
99
|
+
return allProviders;
|
|
112
100
|
}
|
|
113
101
|
|
|
114
102
|
function pickProviderVersionWithFallbackToLegacy(
|
|
@@ -127,17 +115,18 @@ function pickProviderVersionWithFallbackToLegacy(
|
|
|
127
115
|
}
|
|
128
116
|
|
|
129
117
|
export function configWalletsToWalletName(
|
|
130
|
-
|
|
118
|
+
providers: VersionedProviders[],
|
|
131
119
|
options?: ProvidersOptions
|
|
132
120
|
): string[] {
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
121
|
+
const names = providers
|
|
122
|
+
.map((provider) =>
|
|
123
|
+
pickProviderVersionWithFallbackToLegacy(provider, options)
|
|
124
|
+
)
|
|
125
|
+
.map((provider) => {
|
|
126
|
+
if (provider instanceof Provider) {
|
|
127
|
+
return provider.id;
|
|
128
|
+
}
|
|
129
|
+
return provider.config.type;
|
|
130
|
+
});
|
|
142
131
|
return names;
|
|
143
132
|
}
|