@rango-dev/widget-embedded 0.63.1-next.7 → 0.63.1-next.8
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/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
- package/dist/components/CustomDestination/CustomDestination.styles.d.ts +4 -4
- package/dist/components/CustomDestination/CustomDestination.styles.d.ts.map +1 -1
- package/dist/components/CustomTokenModal/CustomTokenModal.styles.d.ts +169 -169
- package/dist/components/CustomTokenModal/CustomTokenModal.styles.d.ts.map +1 -1
- package/dist/components/FilterSelector/FilterSelector.style.d.ts +1 -1
- package/dist/components/FilterSelector/FilterSelector.style.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
- package/dist/components/NamespaceItem/NamespaceItem.styles.d.ts +1 -1
- package/dist/components/NamespaceItem/NamespaceItem.styles.d.ts.map +1 -1
- package/dist/components/NamespaceItem/NamespaceItem.types.d.ts +3 -3
- package/dist/components/NamespaceItem/NamespaceItem.types.d.ts.map +1 -1
- package/dist/components/Quote/Quote.styles.d.ts +171 -171
- package/dist/components/Quote/Quote.styles.d.ts.map +1 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts +169 -169
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts.map +1 -1
- package/dist/components/RefreshModal/RefreshModal.styles.d.ts +168 -168
- package/dist/components/RefreshModal/RefreshModal.styles.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts +1 -1
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.ConnectWallet.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts +3 -3
- package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts.map +1 -1
- package/dist/components/SwapMetrics/SwapMetrics.styles.d.ts +1 -1
- package/dist/components/SwapMetrics/SwapMetrics.styles.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.styles.d.ts +2 -2
- package/dist/components/TokenList/TokenList.styles.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/DerivationPath.styles.d.ts +169 -169
- package/dist/components/WalletStatefulConnect/DerivationPath.styles.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.styles.d.ts +168 -168
- package/dist/components/WalletStatefulConnect/Namespaces.styles.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +3 -3
- package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.helpers.d.ts +2 -2
- package/dist/containers/Wallets/Wallets.helpers.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.types.d.ts +4 -4
- package/dist/containers/Wallets/Wallets.types.d.ts.map +1 -1
- package/dist/containers/Wallets/useUpdates.d.ts +1 -1
- package/dist/containers/Wallets/useUpdates.d.ts.map +1 -1
- package/dist/containers/WidgetProvider/WidgetProvider.d.ts.map +1 -1
- package/dist/containers/WidgetProvider/WidgetProvider.helpers.d.ts +5 -0
- package/dist/containers/WidgetProvider/WidgetProvider.helpers.d.ts.map +1 -0
- package/dist/containers/WidgetProvider/WidgetProvider.types.d.ts +1 -1
- package/dist/containers/WidgetProvider/WidgetProvider.types.d.ts.map +1 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
- package/dist/hooks/useWalletProviders/useWalletProviders.d.ts +2 -2
- package/dist/hooks/useWalletProviders/useWalletProviders.d.ts.map +1 -1
- package/dist/hooks/useWalletProviders/useWalletProviders.helpers.d.ts +2 -3
- package/dist/hooks/useWalletProviders/useWalletProviders.helpers.d.ts.map +1 -1
- package/dist/index.d.ts +10 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +4 -4
- package/dist/store/AppStore.d.ts +2 -2
- package/dist/store/AppStore.d.ts.map +1 -1
- package/dist/store/app.d.ts +2 -2
- package/dist/store/app.d.ts.map +1 -1
- package/dist/store/slices/config.d.ts +5 -5
- package/dist/store/slices/config.d.ts.map +1 -1
- package/dist/test-utils/fixtures.d.ts +2 -2
- package/dist/test-utils/fixtures.d.ts.map +1 -1
- package/dist/types/config.d.ts +10 -3
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/wallets.d.ts +1 -1
- package/dist/types/wallets.d.ts.map +1 -1
- package/dist/utils/providers.d.ts +3 -6
- package/dist/utils/providers.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +1 -1
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +2 -1
- package/dist/utils/wallets.d.ts.map +1 -1
- package/package.json +6 -7
- package/src/QueueManager.tsx +1 -1
- package/src/components/NamespaceItem/NamespaceItem.types.ts +3 -3
- package/src/components/SwapDetailsModal/SwapDetailsModal.ConnectWallet.tsx +5 -10
- package/src/components/SwapDetailsModal/SwapDetailsModal.types.ts +3 -3
- package/src/components/WalletStatefulConnect/Detached.tsx +2 -2
- package/src/components/WalletStatefulConnect/Namespaces.tsx +2 -7
- package/src/components/WalletStatefulConnect/Namespaces.types.tsx +3 -3
- package/src/containers/Wallets/Wallets.helpers.ts +4 -4
- package/src/containers/Wallets/Wallets.tsx +2 -2
- package/src/containers/Wallets/Wallets.types.ts +4 -7
- package/src/containers/Wallets/useUpdates.ts +4 -119
- package/src/containers/WidgetProvider/WidgetProvider.helpers.ts +10 -0
- package/src/containers/WidgetProvider/WidgetProvider.tsx +12 -1
- package/src/containers/WidgetProvider/WidgetProvider.types.ts +1 -1
- package/src/hooks/useStatefulConnect/useStatefulConnect.ts +16 -21
- package/src/hooks/useWalletProviders/useWalletProviders.helpers.ts +3 -10
- package/src/hooks/useWalletProviders/useWalletProviders.ts +2 -2
- package/src/index.ts +12 -10
- package/src/store/AppStore.tsx +4 -2
- package/src/store/app.ts +7 -2
- package/src/store/slices/config.ts +16 -8
- package/src/store/slices/data.test.ts +2 -2
- package/src/test-utils/fixtures.ts +6 -2
- package/src/types/config.ts +15 -6
- package/src/types/wallets.ts +1 -1
- package/src/utils/providers.ts +16 -50
- package/src/utils/swap.ts +1 -1
- package/src/utils/wallets.ts +5 -9
|
@@ -2,17 +2,10 @@ import type {
|
|
|
2
2
|
OnWalletConnectHandler,
|
|
3
3
|
OnWalletDisconnectHandler,
|
|
4
4
|
} from './Wallets.types';
|
|
5
|
+
import type { Network } from '@rango-dev/internal-blockchains';
|
|
5
6
|
import type { LastConnectedWallet } from '@rango-dev/queue-manager-rango-preset';
|
|
6
|
-
import type {
|
|
7
|
-
LegacyEventHandler as EventHandler,
|
|
8
|
-
LegacyEventHandler,
|
|
9
|
-
LegacyNetwork as Network,
|
|
10
|
-
} from '@rango-dev/wallets-core/legacy';
|
|
7
|
+
import type { EventHandler } from '@rango-dev/wallets-react';
|
|
11
8
|
|
|
12
|
-
import {
|
|
13
|
-
legacyFormatAddressWithNetwork as formatAddressWithNetwork,
|
|
14
|
-
legacyReadAccountAddress as readAccountAddress,
|
|
15
|
-
} from '@rango-dev/wallets-core/legacy';
|
|
16
9
|
import { Events } from '@rango-dev/wallets-react';
|
|
17
10
|
import { isEvmBlockchain } from 'rango-sdk';
|
|
18
11
|
|
|
@@ -39,8 +32,6 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
|
|
|
39
32
|
newWalletConnected,
|
|
40
33
|
disconnectWallet,
|
|
41
34
|
disconnectNamespaces,
|
|
42
|
-
connectedWallets,
|
|
43
|
-
removeBalancesForWallet,
|
|
44
35
|
blockchains,
|
|
45
36
|
} = useAppStore();
|
|
46
37
|
|
|
@@ -50,7 +41,7 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
|
|
|
50
41
|
.map((chain) => chain.name);
|
|
51
42
|
|
|
52
43
|
const onAccountsEvent = (
|
|
53
|
-
event: Parameters<
|
|
44
|
+
event: Parameters<EventHandler>,
|
|
54
45
|
params: {
|
|
55
46
|
supportedChainNames: Network[] | null;
|
|
56
47
|
}
|
|
@@ -83,13 +74,7 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
|
|
|
83
74
|
}
|
|
84
75
|
};
|
|
85
76
|
|
|
86
|
-
const
|
|
87
|
-
type,
|
|
88
|
-
event,
|
|
89
|
-
value,
|
|
90
|
-
state,
|
|
91
|
-
info
|
|
92
|
-
) => {
|
|
77
|
+
const handler: EventHandler = (type, event, value, state, info) => {
|
|
93
78
|
if (event === Events.ACCOUNTS) {
|
|
94
79
|
const supportedChainNames: Network[] | null =
|
|
95
80
|
walletAndSupportedChainsNames(info.supportedBlockchains);
|
|
@@ -116,97 +101,7 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
|
|
|
116
101
|
if (event === Events.NAMESPACE_DISCONNECTED) {
|
|
117
102
|
disconnectNamespaces(type, value);
|
|
118
103
|
}
|
|
119
|
-
};
|
|
120
104
|
|
|
121
|
-
const handleUpdatesForLegacy: EventHandler = (
|
|
122
|
-
type,
|
|
123
|
-
event,
|
|
124
|
-
value,
|
|
125
|
-
state,
|
|
126
|
-
info
|
|
127
|
-
) => {
|
|
128
|
-
if (event === Events.ACCOUNTS) {
|
|
129
|
-
const supportedChainNames: Network[] | null =
|
|
130
|
-
walletAndSupportedChainsNames(info.supportedBlockchains);
|
|
131
|
-
|
|
132
|
-
/*
|
|
133
|
-
* When a wallet is connecting to an evm account, we will consider it as the account exists on other evm-compatible blockchains
|
|
134
|
-
* To get their balances.
|
|
135
|
-
*
|
|
136
|
-
* The logic here is for handling switching account functionality in wallets. when a wallet is switching to another account
|
|
137
|
-
* we need to clean the balances for old accounts.
|
|
138
|
-
*
|
|
139
|
-
* Note: hub will do the cleanup on namespace diconnected event.
|
|
140
|
-
*/
|
|
141
|
-
const evmAccounts: string[] = [];
|
|
142
|
-
const nonEvmAccounts: string[] = [];
|
|
143
|
-
|
|
144
|
-
value?.forEach((account: string) => {
|
|
145
|
-
const { network } = readAccountAddress(account);
|
|
146
|
-
if (evmBasedChainNames.includes(network)) {
|
|
147
|
-
evmAccounts.push(account);
|
|
148
|
-
} else {
|
|
149
|
-
nonEvmAccounts.push(account);
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
const previousAccounts = connectedWallets
|
|
154
|
-
.filter((wallet) => wallet.walletType === type)
|
|
155
|
-
.map((wallet) =>
|
|
156
|
-
formatAddressWithNetwork(wallet.address, wallet.chain)
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
if (previousAccounts.length > 0) {
|
|
160
|
-
if (evmAccounts.length > 0) {
|
|
161
|
-
// We use same logic for removing as we use for adding.
|
|
162
|
-
const data = prepareAccountsForWalletStore(
|
|
163
|
-
type,
|
|
164
|
-
evmAccounts,
|
|
165
|
-
evmBasedChainNames,
|
|
166
|
-
supportedChainNames,
|
|
167
|
-
info.isContractWallet
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
removeBalancesForWallet(type, {
|
|
171
|
-
chains: data.map((account) => account.chain),
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (nonEvmAccounts.length > 0) {
|
|
176
|
-
removeBalancesForWallet(type, {
|
|
177
|
-
chains: nonEvmAccounts.map((account) => {
|
|
178
|
-
const { network } = readAccountAddress(account);
|
|
179
|
-
return network;
|
|
180
|
-
}),
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// After cleaning up balances, it's time to add new accounts.
|
|
186
|
-
if (value) {
|
|
187
|
-
onAccountsEvent([type, event, value, state, info], {
|
|
188
|
-
supportedChainNames,
|
|
189
|
-
});
|
|
190
|
-
} else {
|
|
191
|
-
disconnectWallet(type);
|
|
192
|
-
if (!!onDisconnectWalletHandler.current) {
|
|
193
|
-
onDisconnectWalletHandler.current(type);
|
|
194
|
-
} else {
|
|
195
|
-
console.warn(
|
|
196
|
-
`onDisconnectWallet handler hasn't been set. Are you sure?`
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
const handleUpdatesForBoth: EventHandler = (
|
|
204
|
-
type,
|
|
205
|
-
event,
|
|
206
|
-
value,
|
|
207
|
-
state,
|
|
208
|
-
_info
|
|
209
|
-
) => {
|
|
210
105
|
if (event === Events.CONNECTED && value) {
|
|
211
106
|
const walletFromEvent: LastConnectedWallet = {
|
|
212
107
|
walletType: type,
|
|
@@ -234,16 +129,6 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
|
|
|
234
129
|
}
|
|
235
130
|
};
|
|
236
131
|
|
|
237
|
-
const handler: EventHandler = (type, event, value, state, info) => {
|
|
238
|
-
if (info.isHub) {
|
|
239
|
-
handleUpdatesForHub(type, event, value, state, info);
|
|
240
|
-
} else {
|
|
241
|
-
handleUpdatesForLegacy(type, event, value, state, info);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
handleUpdatesForBoth(type, event, value, state, info);
|
|
245
|
-
};
|
|
246
|
-
|
|
247
132
|
return {
|
|
248
133
|
handler,
|
|
249
134
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WalletType } from '@hub3js/core';
|
|
2
|
+
import type { ProviderInterface } from '@rango-dev/wallets-react';
|
|
3
|
+
|
|
4
|
+
import { Provider } from '@hub3js/core';
|
|
5
|
+
|
|
6
|
+
export function isHubWallet(
|
|
7
|
+
wallet: WalletType | ProviderInterface | Provider
|
|
8
|
+
): wallet is WalletType | Provider {
|
|
9
|
+
return typeof wallet === 'string' || wallet instanceof Provider;
|
|
10
|
+
}
|
|
@@ -13,9 +13,18 @@ import { getApiKeyFromEnvOrThrow } from '../../utils/env';
|
|
|
13
13
|
import { WidgetWallets } from '../Wallets';
|
|
14
14
|
import { WidgetInfo } from '../WidgetInfo';
|
|
15
15
|
|
|
16
|
+
import { isHubWallet } from './WidgetProvider.helpers';
|
|
17
|
+
|
|
16
18
|
export function WidgetProvider(props: PropsWithChildren<PropTypes>) {
|
|
17
19
|
const { onUpdateState, config } = props;
|
|
18
20
|
|
|
21
|
+
const wallets = config?.wallets;
|
|
22
|
+
if (wallets && !wallets.every(isHubWallet)) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
"Legacy providers aren't supported anymore. Expected a provider with version '1.0.0'."
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
19
28
|
const fontFamily = props.config?.theme?.fontFamily;
|
|
20
29
|
|
|
21
30
|
const { fetchApiConfig } = useFetchApiConfig();
|
|
@@ -45,7 +54,9 @@ export function WidgetProvider(props: PropsWithChildren<PropTypes>) {
|
|
|
45
54
|
}, [props.config?.signers?.customSolanaRPC]);
|
|
46
55
|
|
|
47
56
|
return (
|
|
48
|
-
<WidgetWallets
|
|
57
|
+
<WidgetWallets
|
|
58
|
+
config={{ ...config, wallets }}
|
|
59
|
+
onUpdateState={onUpdateState}>
|
|
49
60
|
<QueueManager apiKey={config.apiKey}>
|
|
50
61
|
<WidgetInfo>{props.children}</WidgetInfo>
|
|
51
62
|
</QueueManager>
|
|
@@ -117,16 +117,13 @@ export function useStatefulConnect(): UseStatefulConnect {
|
|
|
117
117
|
* 3. Target wallet contains only one namespace, in this situation we should check if that namespace needs derivation path and based on that, try to connect to the related provider or display derivation path modal.
|
|
118
118
|
*/
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
? wallet.properties?.find((item) => item.name === 'namespaces')?.value
|
|
124
|
-
: wallet.needsNamespace;
|
|
120
|
+
const needsNamespace = wallet.properties?.find(
|
|
121
|
+
(item) => item.name === 'namespaces'
|
|
122
|
+
)?.value;
|
|
125
123
|
|
|
126
|
-
const needsDerivationPath =
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
: wallet.needsDerivationPath;
|
|
124
|
+
const needsDerivationPath = wallet.properties?.find(
|
|
125
|
+
(item) => item.name === 'derivationPath'
|
|
126
|
+
)?.value;
|
|
130
127
|
|
|
131
128
|
// Forced namespaces are used to bypass namespace selection flow.
|
|
132
129
|
if (forceConnectToNamespaces) {
|
|
@@ -216,7 +213,7 @@ export function useStatefulConnect(): UseStatefulConnect {
|
|
|
216
213
|
* and forced namespaces are not enabled,
|
|
217
214
|
* we should display detached modal
|
|
218
215
|
*/
|
|
219
|
-
if (
|
|
216
|
+
if (!options?.forceConnectToNamespaces) {
|
|
220
217
|
const needsNamespace = wallet.properties?.find(
|
|
221
218
|
(item) => item.name === 'namespaces'
|
|
222
219
|
)?.value;
|
|
@@ -244,14 +241,13 @@ export function useStatefulConnect(): UseStatefulConnect {
|
|
|
244
241
|
wallet: ExtendedModalWalletInfo,
|
|
245
242
|
selectedNamespaces: Namespace[]
|
|
246
243
|
): Promise<Result> => {
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
: wallet.needsNamespace;
|
|
244
|
+
const needsNamespace = wallet.properties?.find(
|
|
245
|
+
(item) => item.name === 'namespaces'
|
|
246
|
+
)?.value;
|
|
251
247
|
|
|
252
|
-
const needsDerivationPath =
|
|
253
|
-
|
|
254
|
-
|
|
248
|
+
const needsDerivationPath = wallet.properties?.find(
|
|
249
|
+
(item) => item.name === 'derivationPath'
|
|
250
|
+
)?.value;
|
|
255
251
|
|
|
256
252
|
const isSingleNamespace = needsNamespace?.selection === 'single';
|
|
257
253
|
const firstSelectedNamespace = selectedNamespaces[0];
|
|
@@ -327,10 +323,9 @@ export function useStatefulConnect(): UseStatefulConnect {
|
|
|
327
323
|
const selectedNamespace = connectState.derivationPath.namespace;
|
|
328
324
|
const namespaces = [{ namespace: selectedNamespace, derivationPath }];
|
|
329
325
|
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
: wallet.needsNamespace;
|
|
326
|
+
const needsNamespace = wallet.properties?.find(
|
|
327
|
+
(item) => item.name === 'namespaces'
|
|
328
|
+
)?.value;
|
|
334
329
|
|
|
335
330
|
const namespaceIsAvailable =
|
|
336
331
|
!!needsNamespace?.data && needsNamespace.data.length > 1;
|
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Provider } from '@hub3js/core';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export function hashProviders(
|
|
6
|
-
providers: (string | ProviderInterface | Provider)[]
|
|
7
|
-
): string {
|
|
3
|
+
export function hashProviders(providers: (string | Provider)[]): string {
|
|
8
4
|
return providers
|
|
9
5
|
.map((provider) => {
|
|
10
6
|
if (typeof provider === 'string') {
|
|
11
7
|
return provider;
|
|
12
8
|
}
|
|
13
|
-
|
|
14
|
-
return provider.id;
|
|
15
|
-
}
|
|
16
|
-
return provider.config.type;
|
|
9
|
+
return provider.id;
|
|
17
10
|
})
|
|
18
11
|
.join('-');
|
|
19
12
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WidgetConfigWithoutLegacyProviders } from '../../types';
|
|
2
2
|
import type { ProvidersOptions } from '../../utils/providers';
|
|
3
3
|
|
|
4
4
|
import { useEffect } from 'react';
|
|
@@ -8,7 +8,7 @@ import { useAppStore } from '../../store/AppStore';
|
|
|
8
8
|
import { hashProviders } from './useWalletProviders.helpers';
|
|
9
9
|
|
|
10
10
|
export function useWalletProviders(
|
|
11
|
-
configWallets:
|
|
11
|
+
configWallets: WidgetConfigWithoutLegacyProviders['wallets'],
|
|
12
12
|
options?: ProvidersOptions
|
|
13
13
|
) {
|
|
14
14
|
const { clearConnectedWallet, getAvailableProviders, buildAndSetProviders } =
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type {
|
|
|
14
14
|
WidgetTheme,
|
|
15
15
|
WidgetVariant,
|
|
16
16
|
} from './types';
|
|
17
|
+
import type { WalletType } from '@hub3js/core';
|
|
17
18
|
import type {
|
|
18
19
|
PendingSwapWithQueueID,
|
|
19
20
|
Route,
|
|
@@ -36,15 +37,14 @@ import type {
|
|
|
36
37
|
StepTxExecutionUpdatedEvent,
|
|
37
38
|
} from '@rango-dev/queue-manager-rango-preset';
|
|
38
39
|
import type {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
} from '@rango-dev/wallets-core/legacy';
|
|
40
|
+
EventHandler as HandleWalletsUpdate,
|
|
41
|
+
ProviderInterface,
|
|
42
|
+
WalletInfo,
|
|
43
|
+
WalletState,
|
|
44
|
+
} from '@rango-dev/wallets-react';
|
|
45
45
|
import type { PendingSwap, PendingSwapStep } from 'rango-types';
|
|
46
46
|
|
|
47
|
-
import { Networks } from '@rango-dev/internal-blockchains';
|
|
47
|
+
import { Networks, readAccountAddress } from '@rango-dev/internal-blockchains';
|
|
48
48
|
import {
|
|
49
49
|
EventSeverity,
|
|
50
50
|
RouteEventType,
|
|
@@ -52,7 +52,6 @@ import {
|
|
|
52
52
|
StepExecutionBlockedEventStatus,
|
|
53
53
|
StepExecutionEventStatus,
|
|
54
54
|
} from '@rango-dev/queue-manager-rango-preset';
|
|
55
|
-
import { legacyReadAccountAddress as readAccountAddress } from '@rango-dev/wallets-core/legacy';
|
|
56
55
|
import { useWallets, Events as WalletEvents } from '@rango-dev/wallets-react';
|
|
57
56
|
import { PendingSwapNetworkStatus } from 'rango-types';
|
|
58
57
|
|
|
@@ -85,7 +84,7 @@ import {
|
|
|
85
84
|
WalletEventTypes,
|
|
86
85
|
WidgetEvents,
|
|
87
86
|
} from './types';
|
|
88
|
-
import {
|
|
87
|
+
import { pickProviderVersion } from './utils/providers';
|
|
89
88
|
import { customizedThemeTokens } from './utils/ui';
|
|
90
89
|
|
|
91
90
|
export const StatefulConnect = {
|
|
@@ -103,6 +102,9 @@ export type {
|
|
|
103
102
|
WidgetTheme,
|
|
104
103
|
WidgetColors,
|
|
105
104
|
WidgetColorsKeys,
|
|
105
|
+
/**
|
|
106
|
+
* @deprecated Pass a hub `Provider` instead. This type will be removed in future versions.
|
|
107
|
+
*/
|
|
106
108
|
ProviderInterface,
|
|
107
109
|
BlockchainAndTokenConfig,
|
|
108
110
|
WidgetProps,
|
|
@@ -181,7 +183,7 @@ export type {
|
|
|
181
183
|
// Internal function and enum exports for Rango
|
|
182
184
|
export {
|
|
183
185
|
readAccountAddress,
|
|
184
|
-
|
|
186
|
+
pickProviderVersion,
|
|
185
187
|
Networks,
|
|
186
188
|
WalletEvents,
|
|
187
189
|
PendingSwapNetworkStatus,
|
package/src/store/AppStore.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WidgetConfigWithoutLegacyProviders } from '../types';
|
|
2
2
|
import type { PropsWithChildren } from 'react';
|
|
3
3
|
|
|
4
4
|
import React, { createContext, useContext, useEffect, useRef } from 'react';
|
|
@@ -6,7 +6,9 @@ import React, { createContext, useContext, useEffect, useRef } from 'react';
|
|
|
6
6
|
import { createAppStore } from './app';
|
|
7
7
|
|
|
8
8
|
type AppStore = ReturnType<typeof createAppStore>;
|
|
9
|
-
type AppStoreProviderProps = PropsWithChildren<{
|
|
9
|
+
type AppStoreProviderProps = PropsWithChildren<{
|
|
10
|
+
config?: WidgetConfigWithoutLegacyProviders;
|
|
11
|
+
}>;
|
|
10
12
|
|
|
11
13
|
export const AppStoreContext = createContext<AppStore | null>(null);
|
|
12
14
|
|
package/src/store/app.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
WidgetConfig,
|
|
3
|
+
WidgetConfigWithoutLegacyProviders,
|
|
4
|
+
} from '../types';
|
|
2
5
|
import type { AppStoreState } from './slices/types';
|
|
3
6
|
import type { StateCreator } from 'zustand';
|
|
4
7
|
|
|
@@ -21,7 +24,9 @@ export type StateCreatorWithInitialData<
|
|
|
21
24
|
|
|
22
25
|
export type { AppStoreState };
|
|
23
26
|
|
|
24
|
-
export function createAppStore(
|
|
27
|
+
export function createAppStore(
|
|
28
|
+
initialData?: WidgetConfigWithoutLegacyProviders
|
|
29
|
+
) {
|
|
25
30
|
return create<AppStoreState>()(
|
|
26
31
|
persist(
|
|
27
32
|
(...a) => ({
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { DataSlice } from './data';
|
|
2
2
|
import type { SettingsSlice } from './settings';
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
WidgetConfig,
|
|
5
|
+
WidgetConfigWithoutLegacyProviders,
|
|
6
|
+
} from '../../types';
|
|
4
7
|
import type { StateCreatorWithInitialData } from '../app';
|
|
5
8
|
import type { VersionedProviders } from '@hub3js/core/utils';
|
|
6
9
|
|
|
@@ -31,7 +34,7 @@ function makeProvidersOptionsFromConfig(
|
|
|
31
34
|
return options;
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
export const DEFAULT_CONFIG:
|
|
37
|
+
export const DEFAULT_CONFIG: WidgetConfigWithoutLegacyProviders = {
|
|
35
38
|
apiKey: '',
|
|
36
39
|
title: undefined,
|
|
37
40
|
multiWallets: true,
|
|
@@ -66,13 +69,13 @@ const DEFAULT_CAMPAIGN_MODE: CampaignMode = {
|
|
|
66
69
|
|
|
67
70
|
export interface ConfigSlice {
|
|
68
71
|
// What user can set directly.
|
|
69
|
-
config:
|
|
72
|
+
config: WidgetConfigWithoutLegacyProviders;
|
|
70
73
|
campaignMode: CampaignMode;
|
|
71
74
|
isInCampaignMode: () => boolean;
|
|
72
75
|
getLiquiditySources: () => string[];
|
|
73
76
|
getDisabledLiquiditySources: () => string[];
|
|
74
77
|
excludeLiquiditySources: () => boolean;
|
|
75
|
-
updateConfig: (config:
|
|
78
|
+
updateConfig: (config: WidgetConfigWithoutLegacyProviders) => void;
|
|
76
79
|
updateCampaignMode: <K extends keyof CampaignMode>(
|
|
77
80
|
name: K,
|
|
78
81
|
value: CampaignMode[K]
|
|
@@ -88,7 +91,9 @@ export interface ConfigSlice {
|
|
|
88
91
|
getAvailableProviders: () => VersionedProviders[];
|
|
89
92
|
}
|
|
90
93
|
|
|
91
|
-
function generateProviders(
|
|
94
|
+
function generateProviders(
|
|
95
|
+
config: WidgetConfigWithoutLegacyProviders
|
|
96
|
+
): VersionedProviders[] {
|
|
92
97
|
const allProviders = getAllProviders();
|
|
93
98
|
const allBuiltProviders = allProviders.map((build) => build());
|
|
94
99
|
|
|
@@ -109,11 +114,14 @@ function generateProviders(config: WidgetConfig): VersionedProviders[] {
|
|
|
109
114
|
}
|
|
110
115
|
|
|
111
116
|
export const createConfigSlice: StateCreatorWithInitialData<
|
|
112
|
-
|
|
117
|
+
WidgetConfigWithoutLegacyProviders,
|
|
113
118
|
ConfigSlice & SettingsSlice & DataSlice,
|
|
114
119
|
ConfigSlice
|
|
115
120
|
> = (initialData, set, get) => {
|
|
116
|
-
const config:
|
|
121
|
+
const config: WidgetConfigWithoutLegacyProviders = {
|
|
122
|
+
...DEFAULT_CONFIG,
|
|
123
|
+
...initialData,
|
|
124
|
+
};
|
|
117
125
|
const allBuiltProviders = generateProviders(config);
|
|
118
126
|
return {
|
|
119
127
|
config,
|
|
@@ -144,7 +152,7 @@ export const createConfigSlice: StateCreatorWithInitialData<
|
|
|
144
152
|
},
|
|
145
153
|
|
|
146
154
|
// Actions
|
|
147
|
-
updateConfig: (nextConfig:
|
|
155
|
+
updateConfig: (nextConfig: WidgetConfigWithoutLegacyProviders) => {
|
|
148
156
|
const currentConfig = get().config;
|
|
149
157
|
const {
|
|
150
158
|
_tokensMapByTokenHash: tokensMapByTokenHash,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WidgetConfigWithoutLegacyProviders } from '../../types';
|
|
2
2
|
import type { AppStoreState } from '../app';
|
|
3
3
|
import type { EvmBlockchainMeta, Token } from 'rango-sdk';
|
|
4
4
|
|
|
@@ -18,7 +18,7 @@ let appStoreState: AppStoreState;
|
|
|
18
18
|
let customTokens: [Token, Token, Token];
|
|
19
19
|
let rangoBlockchain: EvmBlockchainMeta;
|
|
20
20
|
|
|
21
|
-
const DEFAULT_CONFIG:
|
|
21
|
+
const DEFAULT_CONFIG: WidgetConfigWithoutLegacyProviders = {
|
|
22
22
|
apiKey: '',
|
|
23
23
|
walletConnectProjectId: 'e24844c5deb5193c1c14840a7af6a40b',
|
|
24
24
|
title: undefined,
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { AppStoreState } from '../store/app';
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
Blockchain,
|
|
4
|
+
TokenHash,
|
|
5
|
+
WidgetConfigWithoutLegacyProviders,
|
|
6
|
+
} from '../types';
|
|
3
7
|
import type { BlockchainMeta, EvmBlockchainMeta, Token } from 'rango-sdk';
|
|
4
8
|
|
|
5
9
|
import { faker } from '@faker-js/faker';
|
|
@@ -216,7 +220,7 @@ export function createInitialAppStore() {
|
|
|
216
220
|
|
|
217
221
|
export function updateAppStoreConfig(
|
|
218
222
|
appStoreState: AppStoreState,
|
|
219
|
-
config: Partial<
|
|
223
|
+
config: Partial<WidgetConfigWithoutLegacyProviders>
|
|
220
224
|
): AppStoreState {
|
|
221
225
|
appStoreState.config = {
|
|
222
226
|
...appStoreState.config,
|
package/src/types/config.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import type { Provider } from '@hub3js/core';
|
|
1
|
+
import type { Provider, WalletType } from '@hub3js/core';
|
|
2
2
|
import type { Language, theme } from '@rango-dev/ui';
|
|
3
|
-
import type {
|
|
4
|
-
LegacyProviderInterface,
|
|
5
|
-
LegacyWalletType as WalletType,
|
|
6
|
-
} from '@rango-dev/wallets-core/legacy';
|
|
3
|
+
import type { ProviderInterface } from '@rango-dev/wallets-react';
|
|
7
4
|
import type { Asset } from 'rango-sdk';
|
|
8
5
|
import type { ReactElement } from 'react';
|
|
9
6
|
|
|
@@ -278,7 +275,11 @@ export type WidgetConfig = {
|
|
|
278
275
|
from?: BlockchainAndTokenConfig;
|
|
279
276
|
to?: BlockchainAndTokenConfig;
|
|
280
277
|
liquiditySources?: string[];
|
|
281
|
-
|
|
278
|
+
/**
|
|
279
|
+
* Passing a `ProviderInterface` is deprecated. Pass a hub `Provider` instead.
|
|
280
|
+
* Legacy providers will be removed in future versions.
|
|
281
|
+
*/
|
|
282
|
+
wallets?: (WalletType | ProviderInterface | Provider)[];
|
|
282
283
|
multiWallets?: boolean;
|
|
283
284
|
customDestination?: boolean;
|
|
284
285
|
defaultCustomDestinations?: { [blockchain: string]: string };
|
|
@@ -307,3 +308,11 @@ export type WidgetConfig = {
|
|
|
307
308
|
};
|
|
308
309
|
routing?: Routing;
|
|
309
310
|
};
|
|
311
|
+
|
|
312
|
+
// TODO: remove this when ProviderInterface gets removed
|
|
313
|
+
export type WidgetConfigWithoutLegacyProviders = WidgetConfig & {
|
|
314
|
+
wallets?: Exclude<
|
|
315
|
+
NonNullable<WidgetConfig['wallets']>[number],
|
|
316
|
+
ProviderInterface
|
|
317
|
+
>[];
|
|
318
|
+
};
|
package/src/types/wallets.ts
CHANGED