@rango-dev/widget-embedded 0.29.1-next.9 → 0.30.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/dist/QueueManager.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +6 -0
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
- package/dist/components/NotificationContent/NotificationContent.d.ts.map +1 -1
- package/dist/components/Quote/Quote.d.ts.map +1 -1
- package/dist/components/Quote/Quote.styles.d.ts +1 -1
- package/dist/components/Quote/QuoteCostDetails.d.ts.map +1 -1
- package/dist/components/RefreshModal/RefreshModal.styles.d.ts +1 -1
- package/dist/components/SearchInput/SearchInput.types.d.ts +2 -0
- package/dist/components/SearchInput/SearchInput.types.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.helpers.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.d.ts +4 -0
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.d.ts.map +1 -0
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.styles.d.ts +325 -0
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.styles.d.ts.map +1 -0
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.types.d.ts +10 -0
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.types.d.ts.map +1 -0
- package/dist/components/WalletDerivationPathModal/index.d.ts +2 -0
- package/dist/components/WalletDerivationPathModal/index.d.ts.map +1 -0
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.d.ts.map +1 -1
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.types.d.ts +1 -1
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.types.d.ts.map +1 -1
- package/dist/constants/namespaces.d.ts +8 -0
- package/dist/constants/namespaces.d.ts.map +1 -0
- package/dist/constants/quote.d.ts +2 -1
- package/dist/constants/quote.d.ts.map +1 -1
- package/dist/constants/routing.d.ts +0 -1
- package/dist/constants/routing.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
- package/dist/containers/WidgetInfo/WidgetInfo.d.ts.map +1 -1
- package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts +3 -1
- package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts.map +1 -1
- package/dist/hooks/useBootstrap/useBootstrap.d.ts.map +1 -1
- package/dist/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.d.ts.map +1 -1
- package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -1
- package/dist/hooks/useWalletList.d.ts +4 -3
- package/dist/hooks/useWalletList.d.ts.map +1 -1
- package/dist/hooks/useWalletProviders/index.d.ts +2 -0
- package/dist/hooks/useWalletProviders/index.d.ts.map +1 -0
- package/dist/hooks/{useWalletProviders.d.ts → useWalletProviders/useWalletProviders.d.ts} +2 -2
- package/dist/hooks/useWalletProviders/useWalletProviders.d.ts.map +1 -0
- package/dist/hooks/useWalletProviders/useWalletProviders.helpers.d.ts +3 -0
- package/dist/hooks/useWalletProviders/useWalletProviders.helpers.d.ts.map +1 -0
- package/dist/hooks/useWidgetEvents/index.d.ts +2 -0
- package/dist/hooks/useWidgetEvents/index.d.ts.map +1 -0
- package/dist/hooks/useWidgetEvents/useWidgetEvents.d.ts +3 -0
- package/dist/hooks/useWidgetEvents/useWidgetEvents.d.ts.map +1 -0
- package/dist/index.d.ts +16 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/services/eventEmitter.d.ts +4 -0
- package/dist/services/eventEmitter.d.ts.map +1 -0
- package/dist/store/notification.d.ts.map +1 -1
- package/dist/store/quote.d.ts +2 -1
- package/dist/store/quote.d.ts.map +1 -1
- package/dist/store/slices/config.d.ts.map +1 -1
- package/dist/store/slices/settings.d.ts.map +1 -1
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/config.d.ts +7 -2
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/event.d.ts +68 -0
- package/dist/types/event.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/wallets.d.ts +2 -1
- package/dist/types/wallets.d.ts.map +1 -1
- package/dist/utils/common.d.ts +2 -2
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/meta.d.ts +1 -0
- package/dist/utils/meta.d.ts.map +1 -1
- package/dist/utils/numbers.d.ts +0 -1
- package/dist/utils/numbers.d.ts.map +1 -1
- package/dist/utils/providers.d.ts +1 -0
- package/dist/utils/providers.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +4 -4
- package/dist/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +8 -8
- package/src/QueueManager.tsx +4 -0
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +19 -9
- package/src/components/ConfirmWalletsModal/WalletList.tsx +81 -14
- package/src/components/HistoryGroupedList/HistoryGroupedList.tsx +5 -5
- package/src/components/NotificationContent/NotificationContent.tsx +12 -113
- package/src/components/Quote/Quote.tsx +24 -34
- package/src/components/Quote/QuoteCostDetails.tsx +10 -9
- package/src/components/SearchInput/SearchInput.types.ts +2 -0
- package/src/components/SwapDetails/SwapDetails.Placeholder.tsx +1 -1
- package/src/components/SwapDetails/SwapDetails.helpers.tsx +8 -10
- package/src/components/SwapDetails/SwapDetails.tsx +10 -11
- package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +77 -11
- package/src/components/TokenList/TokenList.tsx +5 -5
- package/src/components/WalletDerivationPathModal/WalletDerivationPathModal.styles.ts +17 -0
- package/src/components/WalletDerivationPathModal/WalletDerivationPathModal.tsx +154 -0
- package/src/components/WalletDerivationPathModal/WalletDerivationPathModal.types.tsx +10 -0
- package/src/components/WalletDerivationPathModal/index.ts +1 -0
- package/src/components/WalletNamespacesModal/WalletNamespacesModal.tsx +9 -6
- package/src/components/WalletNamespacesModal/WalletNamespacesModal.types.tsx +1 -1
- package/src/constants/namespaces.ts +62 -0
- package/src/constants/quote.ts +11 -9
- package/src/constants/routing.ts +0 -2
- package/src/containers/Inputs/Inputs.tsx +5 -5
- package/src/containers/Wallets/Wallets.tsx +1 -0
- package/src/containers/WidgetInfo/WidgetInfo.tsx +3 -0
- package/src/containers/WidgetInfo/WidgetInfo.types.ts +3 -1
- package/src/hooks/useBootstrap/useBootstrap.ts +4 -0
- package/src/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.ts +8 -10
- package/src/hooks/useSyncStoresWithConfig.ts +3 -1
- package/src/hooks/useWalletList.ts +12 -5
- package/src/hooks/useWalletProviders/index.ts +1 -0
- package/src/hooks/useWalletProviders/useWalletProviders.helpers.ts +14 -0
- package/src/hooks/{useWalletProviders.ts → useWalletProviders/useWalletProviders.ts} +11 -5
- package/src/hooks/useWidgetEvents/index.ts +1 -0
- package/src/hooks/useWidgetEvents/useWidgetEvents.ts +9 -0
- package/src/index.ts +26 -2
- package/src/pages/WalletsPage.tsx +85 -19
- package/src/services/eventEmitter.ts +11 -0
- package/src/store/notification.ts +3 -1
- package/src/store/quote.ts +70 -5
- package/src/store/slices/config.ts +4 -0
- package/src/store/slices/settings.ts +4 -1
- package/src/store/wallets.ts +194 -173
- package/src/types/config.ts +8 -4
- package/src/types/event.ts +89 -0
- package/src/types/index.ts +1 -0
- package/src/types/wallets.ts +2 -1
- package/src/utils/common.ts +2 -2
- package/src/utils/meta.ts +8 -0
- package/src/utils/numbers.ts +0 -12
- package/src/utils/providers.ts +4 -0
- package/src/utils/wallets.ts +7 -5
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts +0 -1559
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +0 -1
- package/dist/components/NotificationContent/NotificationNotFound.d.ts +0 -3
- package/dist/components/NotificationContent/NotificationNotFound.d.ts.map +0 -1
- package/dist/hooks/useWalletProviders.d.ts.map +0 -1
- package/src/components/NotificationContent/NotificationContent.styles.ts +0 -63
- package/src/components/NotificationContent/NotificationNotFound.tsx +0 -17
package/src/store/quote.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { QuoteError, QuoteWarning, SelectedQuote, Wallet } from '../types';
|
|
2
1
|
import type {
|
|
3
2
|
BlockchainMeta,
|
|
4
3
|
MetaResponse,
|
|
@@ -12,6 +11,15 @@ import { create } from 'zustand';
|
|
|
12
11
|
import { subscribeWithSelector } from 'zustand/middleware';
|
|
13
12
|
|
|
14
13
|
import { ZERO } from '../constants/numbers';
|
|
14
|
+
import { eventEmitter } from '../services/eventEmitter';
|
|
15
|
+
import {
|
|
16
|
+
type QuoteError,
|
|
17
|
+
QuoteEventTypes,
|
|
18
|
+
type QuoteWarning,
|
|
19
|
+
type SelectedQuote,
|
|
20
|
+
type Wallet,
|
|
21
|
+
WidgetEvents,
|
|
22
|
+
} from '../types';
|
|
15
23
|
import { isPositiveNumber } from '../utils/numbers';
|
|
16
24
|
import { getQuoteToTokenUsdPrice } from '../utils/quote';
|
|
17
25
|
import { calcOutputUsdValue } from '../utils/swap';
|
|
@@ -160,11 +168,12 @@ export const useQuoteStore = createSelectors(
|
|
|
160
168
|
|
|
161
169
|
return {
|
|
162
170
|
fromBlockchain: chain,
|
|
171
|
+
inputUsdValue: new BigNumber(0),
|
|
163
172
|
...(state.fromToken && {
|
|
164
173
|
selectedQuote: null,
|
|
165
174
|
fromToken: null,
|
|
166
175
|
outputAmount: null,
|
|
167
|
-
outputUsdValue:
|
|
176
|
+
outputUsdValue: new BigNumber(0),
|
|
168
177
|
}),
|
|
169
178
|
};
|
|
170
179
|
});
|
|
@@ -195,7 +204,7 @@ export const useQuoteStore = createSelectors(
|
|
|
195
204
|
selectedQuote: null,
|
|
196
205
|
toToken: null,
|
|
197
206
|
outputAmount: null,
|
|
198
|
-
outputUsdValue:
|
|
207
|
+
outputUsdValue: new BigNumber(0),
|
|
199
208
|
}),
|
|
200
209
|
};
|
|
201
210
|
});
|
|
@@ -260,8 +269,10 @@ export const useQuoteStore = createSelectors(
|
|
|
260
269
|
set(() => ({
|
|
261
270
|
fromToken: null,
|
|
262
271
|
fromBlockchain: null,
|
|
272
|
+
outputUsdValue: new BigNumber(0),
|
|
273
|
+
inputUsdValue: new BigNumber(0),
|
|
274
|
+
inputAmount: '',
|
|
263
275
|
outputAmount: null,
|
|
264
|
-
outputUsdValue: null,
|
|
265
276
|
selectedQuote: null,
|
|
266
277
|
})),
|
|
267
278
|
resetToBlockchain: () =>
|
|
@@ -269,7 +280,7 @@ export const useQuoteStore = createSelectors(
|
|
|
269
280
|
toToken: null,
|
|
270
281
|
toBlockchain: null,
|
|
271
282
|
outputAmount: null,
|
|
272
|
-
outputUsdValue:
|
|
283
|
+
outputUsdValue: new BigNumber(0),
|
|
273
284
|
selectedQuote: null,
|
|
274
285
|
})),
|
|
275
286
|
setQuoteWalletConfirmed: (flag) =>
|
|
@@ -289,3 +300,57 @@ export const useQuoteStore = createSelectors(
|
|
|
289
300
|
}))
|
|
290
301
|
)
|
|
291
302
|
);
|
|
303
|
+
|
|
304
|
+
export const unsubscribeQuoteStore = useQuoteStore.subscribe(
|
|
305
|
+
(selectedState, previousSelectedState) => {
|
|
306
|
+
if (
|
|
307
|
+
selectedState.fromBlockchain !== previousSelectedState.fromBlockchain ||
|
|
308
|
+
selectedState.fromToken !== previousSelectedState.fromToken ||
|
|
309
|
+
selectedState.toBlockchain !== previousSelectedState.toBlockchain ||
|
|
310
|
+
selectedState.toToken !== previousSelectedState.toToken ||
|
|
311
|
+
selectedState.inputAmount !== previousSelectedState.inputAmount
|
|
312
|
+
) {
|
|
313
|
+
// useEffect hook can not be used in Zustand subscribe
|
|
314
|
+
eventEmitter.emit(WidgetEvents.QuoteEvent, {
|
|
315
|
+
type: QuoteEventTypes.QUOTE_INPUT_UPDATE,
|
|
316
|
+
payload: {
|
|
317
|
+
fromBlockchain: selectedState.fromBlockchain?.name,
|
|
318
|
+
toBlockchain: selectedState.toBlockchain?.name,
|
|
319
|
+
fromToken: selectedState.fromToken
|
|
320
|
+
? {
|
|
321
|
+
symbol: selectedState.fromToken.symbol,
|
|
322
|
+
name: selectedState.fromToken.name,
|
|
323
|
+
address: selectedState.fromToken.address,
|
|
324
|
+
}
|
|
325
|
+
: undefined,
|
|
326
|
+
toToken: selectedState.toToken
|
|
327
|
+
? {
|
|
328
|
+
symbol: selectedState.toToken.symbol,
|
|
329
|
+
name: selectedState.toToken.name,
|
|
330
|
+
address: selectedState.toToken.address,
|
|
331
|
+
}
|
|
332
|
+
: undefined,
|
|
333
|
+
requestAmount: selectedState.inputAmount,
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (
|
|
339
|
+
selectedState.selectedQuote?.requestId !==
|
|
340
|
+
previousSelectedState.selectedQuote?.requestId
|
|
341
|
+
) {
|
|
342
|
+
eventEmitter.emit(WidgetEvents.QuoteEvent, {
|
|
343
|
+
type: QuoteEventTypes.QUOTE_OUTPUT_UPDATE,
|
|
344
|
+
payload: selectedState.selectedQuote
|
|
345
|
+
? {
|
|
346
|
+
requestAmount: selectedState.selectedQuote.requestAmount,
|
|
347
|
+
swaps: selectedState.selectedQuote.swaps,
|
|
348
|
+
outputAmount: selectedState.selectedQuote.outputAmount,
|
|
349
|
+
resultType: selectedState.selectedQuote.resultType,
|
|
350
|
+
tags: selectedState.selectedQuote.tags,
|
|
351
|
+
}
|
|
352
|
+
: null,
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
);
|
|
@@ -9,6 +9,10 @@ export const DEFAULT_CONFIG: WidgetConfig = {
|
|
|
9
9
|
excludeLiquiditySources: true,
|
|
10
10
|
customDestination: true,
|
|
11
11
|
variant: 'default',
|
|
12
|
+
trezorManifest: {
|
|
13
|
+
appUrl: 'https://widget.rango.exchange/',
|
|
14
|
+
email: 'hi+trezorwidget@rango.exchange',
|
|
15
|
+
},
|
|
12
16
|
};
|
|
13
17
|
|
|
14
18
|
interface IframeConfigs {
|
|
@@ -159,6 +159,8 @@ export const createSettingsSlice: StateCreator<
|
|
|
159
159
|
const isLanguageHidden = isFeatureHidden('language', features);
|
|
160
160
|
const isLiquidityHidden = isFeatureHidden('liquiditySource', features);
|
|
161
161
|
const singleTheme = theme?.singleTheme;
|
|
162
|
+
const autoUpdateSettings =
|
|
163
|
+
nextConfig?.__UNSTABLE_OR_INTERNAL__?.autoUpdateSettings;
|
|
162
164
|
|
|
163
165
|
set({
|
|
164
166
|
...(isThemeHidden && { theme: nextConfig.theme?.mode || 'auto' }),
|
|
@@ -169,7 +171,8 @@ export const createSettingsSlice: StateCreator<
|
|
|
169
171
|
...(isLiquidityHidden && {
|
|
170
172
|
disabledLiquiditySources: nextConfig.liquiditySources || [],
|
|
171
173
|
}),
|
|
172
|
-
...(
|
|
174
|
+
...(autoUpdateSettings && {
|
|
175
|
+
// For the time being, we have added the language; if more are needed later, we can add other parameters.
|
|
173
176
|
language: nextConfig.language || DEFAULT_LANGUAGE,
|
|
174
177
|
}),
|
|
175
178
|
});
|
package/src/store/wallets.ts
CHANGED
|
@@ -6,7 +6,9 @@ import type { Token } from 'rango-sdk';
|
|
|
6
6
|
import { create } from 'zustand';
|
|
7
7
|
import { subscribeWithSelector } from 'zustand/middleware';
|
|
8
8
|
|
|
9
|
+
import { eventEmitter } from '../services/eventEmitter';
|
|
9
10
|
import { httpService } from '../services/httpService';
|
|
11
|
+
import { WalletEventTypes, WidgetEvents } from '../types';
|
|
10
12
|
import { createTokenHash } from '../utils/meta';
|
|
11
13
|
import {
|
|
12
14
|
isAccountAndWalletMatched,
|
|
@@ -54,156 +56,195 @@ interface WalletsStore {
|
|
|
54
56
|
|
|
55
57
|
export const useWalletsStore = createSelectors(
|
|
56
58
|
create<WalletsStore>()(
|
|
57
|
-
subscribeWithSelector((set, get) =>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
59
|
+
subscribeWithSelector((set, get) => {
|
|
60
|
+
return {
|
|
61
|
+
connectedWallets: [],
|
|
62
|
+
balances: {},
|
|
63
|
+
loading: false,
|
|
64
|
+
connectWallet: (accounts, findToken) => {
|
|
65
|
+
eventEmitter.emit(WidgetEvents.WalletEvent, {
|
|
66
|
+
type: WalletEventTypes.CONNECT,
|
|
67
|
+
payload: { walletType: accounts[0].walletType, accounts },
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const getWalletsDetails = get().getWalletsDetails;
|
|
71
|
+
set((state) => ({
|
|
72
|
+
loading: true,
|
|
73
|
+
connectedWallets: state.connectedWallets
|
|
74
|
+
.filter((wallet) => wallet.walletType !== accounts[0].walletType)
|
|
75
|
+
.concat(
|
|
76
|
+
accounts.map((account) => {
|
|
77
|
+
const shouldMarkWalletAsSelected =
|
|
78
|
+
!state.connectedWallets.some(
|
|
79
|
+
(connectedWallet) =>
|
|
80
|
+
connectedWallet.chain === account.chain &&
|
|
81
|
+
connectedWallet.selected &&
|
|
82
|
+
/**
|
|
83
|
+
* Sometimes, the connect function can be called multiple times for a particular wallet type when using the auto-connect feature.
|
|
84
|
+
* This check is there to make sure the chosen wallet doesn't end up unselected.
|
|
85
|
+
*/
|
|
86
|
+
connectedWallet.walletType !== account.walletType
|
|
87
|
+
);
|
|
88
|
+
return {
|
|
89
|
+
balances: [],
|
|
90
|
+
address: account.address,
|
|
91
|
+
chain: account.chain,
|
|
92
|
+
explorerUrl: null,
|
|
93
|
+
walletType: account.walletType,
|
|
94
|
+
selected: shouldMarkWalletAsSelected,
|
|
95
|
+
loading: true,
|
|
96
|
+
error: false,
|
|
97
|
+
};
|
|
98
|
+
})
|
|
99
|
+
),
|
|
100
|
+
}));
|
|
101
|
+
getWalletsDetails(accounts, findToken);
|
|
102
|
+
},
|
|
103
|
+
disconnectWallet: (walletType) => {
|
|
104
|
+
set((state) => {
|
|
105
|
+
if (
|
|
106
|
+
state.connectedWallets.find(
|
|
107
|
+
(wallet) => wallet.walletType === walletType
|
|
108
|
+
)
|
|
109
|
+
) {
|
|
110
|
+
eventEmitter.emit(WidgetEvents.WalletEvent, {
|
|
111
|
+
type: WalletEventTypes.DISCONNECT,
|
|
112
|
+
payload: { walletType },
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const selectedWallets = state.connectedWallets
|
|
117
|
+
.filter(
|
|
118
|
+
(connectedWallet) =>
|
|
119
|
+
connectedWallet.selected &&
|
|
120
|
+
connectedWallet.walletType !== walletType
|
|
121
|
+
)
|
|
122
|
+
.map((selectedWallet) => selectedWallet.chain);
|
|
123
|
+
|
|
124
|
+
const connectedWallets = state.connectedWallets
|
|
125
|
+
.filter(
|
|
126
|
+
(connectedWallet) => connectedWallet.walletType !== walletType
|
|
127
|
+
)
|
|
128
|
+
.map((connectedWallet) => {
|
|
129
|
+
const anyWalletSelectedForBlockchain = selectedWallets.includes(
|
|
130
|
+
connectedWallet.chain
|
|
78
131
|
);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
.map((connectedWallet) => {
|
|
109
|
-
const anyWalletSelectedForBlockchain = selectedWallets.includes(
|
|
110
|
-
connectedWallet.chain
|
|
132
|
+
if (anyWalletSelectedForBlockchain) {
|
|
133
|
+
return connectedWallet;
|
|
134
|
+
}
|
|
135
|
+
selectedWallets.push(connectedWallet.chain);
|
|
136
|
+
return { ...connectedWallet, selected: true };
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const balances = makeTokensBalance(connectedWallets);
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
balances,
|
|
143
|
+
connectedWallets,
|
|
144
|
+
};
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
selectWallets: (wallets) =>
|
|
148
|
+
set((state) => ({
|
|
149
|
+
connectedWallets: state.connectedWallets.map((connectedWallet) => {
|
|
150
|
+
const walletSelected = !!wallets.find(
|
|
151
|
+
(wallet) =>
|
|
152
|
+
wallet.chain === connectedWallet.chain &&
|
|
153
|
+
wallet.walletType !== connectedWallet.walletType &&
|
|
154
|
+
connectedWallet.selected
|
|
155
|
+
);
|
|
156
|
+
const walletNotSelected = !!wallets.find(
|
|
157
|
+
(wallet) =>
|
|
158
|
+
wallet.chain === connectedWallet.chain &&
|
|
159
|
+
wallet.walletType === connectedWallet.walletType &&
|
|
160
|
+
!connectedWallet.selected
|
|
111
161
|
);
|
|
112
|
-
if (
|
|
113
|
-
return connectedWallet;
|
|
162
|
+
if (walletSelected) {
|
|
163
|
+
return { ...connectedWallet, selected: false };
|
|
164
|
+
} else if (walletNotSelected) {
|
|
165
|
+
return { ...connectedWallet, selected: true };
|
|
114
166
|
}
|
|
115
|
-
selectedWallets.push(connectedWallet.chain);
|
|
116
|
-
return { ...connectedWallet, selected: true };
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
const balances = makeTokensBalance(connectedWallets);
|
|
120
|
-
|
|
121
|
-
return {
|
|
122
|
-
balances,
|
|
123
|
-
connectedWallets,
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
},
|
|
127
|
-
selectWallets: (wallets) =>
|
|
128
|
-
set((state) => ({
|
|
129
|
-
connectedWallets: state.connectedWallets.map((connectedWallet) => {
|
|
130
|
-
const walletSelected = !!wallets.find(
|
|
131
|
-
(wallet) =>
|
|
132
|
-
wallet.chain === connectedWallet.chain &&
|
|
133
|
-
wallet.walletType !== connectedWallet.walletType &&
|
|
134
|
-
connectedWallet.selected
|
|
135
|
-
);
|
|
136
|
-
const walletNotSelected = !!wallets.find(
|
|
137
|
-
(wallet) =>
|
|
138
|
-
wallet.chain === connectedWallet.chain &&
|
|
139
|
-
wallet.walletType === connectedWallet.walletType &&
|
|
140
|
-
!connectedWallet.selected
|
|
141
|
-
);
|
|
142
|
-
if (walletSelected) {
|
|
143
|
-
return { ...connectedWallet, selected: false };
|
|
144
|
-
} else if (walletNotSelected) {
|
|
145
|
-
return { ...connectedWallet, selected: true };
|
|
146
|
-
}
|
|
147
167
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}));
|
|
168
|
-
try {
|
|
169
|
-
const data = accounts.map(({ address, chain }) => ({
|
|
170
|
-
address,
|
|
171
|
-
blockchain: chain,
|
|
168
|
+
return connectedWallet;
|
|
169
|
+
}),
|
|
170
|
+
})),
|
|
171
|
+
clearConnectedWallet: () =>
|
|
172
|
+
set(() => ({
|
|
173
|
+
connectedWallets: [],
|
|
174
|
+
selectedWallets: [],
|
|
175
|
+
})),
|
|
176
|
+
getWalletsDetails: async (accounts, findToken, shouldRetry = true) => {
|
|
177
|
+
const getWalletsDetails = get().getWalletsDetails;
|
|
178
|
+
set((state) => ({
|
|
179
|
+
loading: true,
|
|
180
|
+
connectedWallets: state.connectedWallets.map((wallet) => {
|
|
181
|
+
return accounts.find((account) =>
|
|
182
|
+
isAccountAndWalletMatched(account, wallet)
|
|
183
|
+
)
|
|
184
|
+
? { ...wallet, loading: true }
|
|
185
|
+
: wallet;
|
|
186
|
+
}),
|
|
172
187
|
}));
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
188
|
+
try {
|
|
189
|
+
const data = accounts.map(({ address, chain }) => ({
|
|
190
|
+
address,
|
|
191
|
+
blockchain: chain,
|
|
192
|
+
}));
|
|
193
|
+
const response = await httpService().getWalletsDetails(data);
|
|
194
|
+
const retrievedBalance = response.wallets;
|
|
195
|
+
if (retrievedBalance) {
|
|
196
|
+
set((state) => {
|
|
197
|
+
const connectedWallets = state.connectedWallets.map(
|
|
198
|
+
(connectedWallet) => {
|
|
199
|
+
const matchedAccount = accounts.find((account) =>
|
|
200
|
+
isAccountAndWalletMatched(account, connectedWallet)
|
|
201
|
+
);
|
|
202
|
+
const retrievedBalanceAccount = retrievedBalance.find(
|
|
203
|
+
(balance) =>
|
|
204
|
+
balance.address === connectedWallet.address &&
|
|
205
|
+
balance.blockChain === connectedWallet.chain
|
|
206
|
+
);
|
|
207
|
+
if (
|
|
208
|
+
retrievedBalanceAccount?.failed &&
|
|
209
|
+
matchedAccount &&
|
|
210
|
+
shouldRetry
|
|
211
|
+
) {
|
|
212
|
+
getWalletsDetails([matchedAccount], findToken, false);
|
|
213
|
+
}
|
|
214
|
+
return matchedAccount && retrievedBalanceAccount
|
|
215
|
+
? {
|
|
216
|
+
...connectedWallet,
|
|
217
|
+
explorerUrl: retrievedBalanceAccount.explorerUrl,
|
|
218
|
+
balances: makeBalanceFor(
|
|
219
|
+
retrievedBalanceAccount,
|
|
220
|
+
findToken
|
|
221
|
+
),
|
|
222
|
+
loading: false,
|
|
223
|
+
}
|
|
224
|
+
: connectedWallet;
|
|
193
225
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
const balances = makeTokensBalance(connectedWallets);
|
|
229
|
+
|
|
230
|
+
return {
|
|
231
|
+
loading: false,
|
|
232
|
+
balances,
|
|
233
|
+
connectedWallets,
|
|
234
|
+
};
|
|
235
|
+
});
|
|
236
|
+
} else {
|
|
237
|
+
throw new Error('Wallet not found');
|
|
238
|
+
}
|
|
239
|
+
} catch (error) {
|
|
240
|
+
set((state) => {
|
|
241
|
+
const connectedWallets = state.connectedWallets.map((balance) => {
|
|
242
|
+
return accounts.find((account) =>
|
|
243
|
+
isAccountAndWalletMatched(account, balance)
|
|
244
|
+
)
|
|
245
|
+
? resetConnectedWalletState(balance)
|
|
246
|
+
: balance;
|
|
247
|
+
});
|
|
207
248
|
|
|
208
249
|
const balances = makeTokensBalance(connectedWallets);
|
|
209
250
|
|
|
@@ -213,35 +254,15 @@ export const useWalletsStore = createSelectors(
|
|
|
213
254
|
connectedWallets,
|
|
214
255
|
};
|
|
215
256
|
});
|
|
216
|
-
} else {
|
|
217
|
-
throw new Error('Wallet not found');
|
|
218
257
|
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const balances = makeTokensBalance(connectedWallets);
|
|
230
|
-
|
|
231
|
-
return {
|
|
232
|
-
loading: false,
|
|
233
|
-
balances,
|
|
234
|
-
connectedWallets,
|
|
235
|
-
};
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
getBalanceFor: (token) => {
|
|
240
|
-
const { balances } = get();
|
|
241
|
-
const tokenHash = createTokenHash(token);
|
|
242
|
-
const balance = balances[tokenHash];
|
|
243
|
-
return balance ?? null;
|
|
244
|
-
},
|
|
245
|
-
}))
|
|
258
|
+
},
|
|
259
|
+
getBalanceFor: (token) => {
|
|
260
|
+
const { balances } = get();
|
|
261
|
+
const tokenHash = createTokenHash(token);
|
|
262
|
+
const balance = balances[tokenHash];
|
|
263
|
+
return balance ?? null;
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
})
|
|
246
267
|
)
|
|
247
268
|
);
|
package/src/types/config.ts
CHANGED
|
@@ -145,6 +145,11 @@ export type Features = Partial<
|
|
|
145
145
|
> &
|
|
146
146
|
Partial<Record<'experimentalRoute', 'disabled' | 'enabled'>>;
|
|
147
147
|
|
|
148
|
+
export type TrezorManifest = {
|
|
149
|
+
appUrl: string;
|
|
150
|
+
email: string;
|
|
151
|
+
};
|
|
152
|
+
|
|
148
153
|
/**
|
|
149
154
|
* The type WidgetConfig defines the configuration options for a widget, including API key, affiliate
|
|
150
155
|
* reference, amount, blockchain and token configurations, liquidity sources, wallet types, language,
|
|
@@ -158,6 +163,8 @@ export type Features = Partial<
|
|
|
158
163
|
* @property {BlockchainAndTokenConfig} from - The `from` property is an optional property of type
|
|
159
164
|
* `BlockchainAndTokenConfig` that specifies the default blockchain and token from which the user wants to
|
|
160
165
|
* exchange.It can also used to limit source swap blockchains/tokens to some limited ones.
|
|
166
|
+
* @property {TrezorManifest} trezorManifest - Trezor Connect Manifest requires that you,
|
|
167
|
+
* as a Trezor Connect integrator,share your e-mail and application url.
|
|
161
168
|
* @property {BlockchainAndTokenConfig} to - The "to" property is an optional property of type
|
|
162
169
|
* "BlockchainAndTokenConfig" that specifies the default blockchain and token to which the user wants to
|
|
163
170
|
* exchange.It can also used to limit destination swap blockchains/tokens to some limited ones.
|
|
@@ -203,6 +210,7 @@ export type WidgetConfig = {
|
|
|
203
210
|
apiUrl?: string;
|
|
204
211
|
title?: string;
|
|
205
212
|
walletConnectProjectId?: string;
|
|
213
|
+
trezorManifest?: TrezorManifest;
|
|
206
214
|
affiliate?: WidgetAffiliate;
|
|
207
215
|
amount?: number;
|
|
208
216
|
from?: BlockchainAndTokenConfig;
|
|
@@ -223,10 +231,6 @@ export type WidgetConfig = {
|
|
|
223
231
|
// These are likely to change or remove at anytime. Please use with a caution.
|
|
224
232
|
__UNSTABLE_OR_INTERNAL__?: {
|
|
225
233
|
walletConnectListedDesktopWalletLink?: string;
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
// Internal configuration options. Not intended for public use or modification.
|
|
229
|
-
_INTERNAL_SETTINGS_?: {
|
|
230
234
|
autoUpdateSettings?: boolean; // If true, settings will be updated automatically based on the configuration.
|
|
231
235
|
};
|
|
232
236
|
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { SelectedQuote } from './quote';
|
|
2
|
+
import type { Wallet } from './wallets';
|
|
3
|
+
import type {
|
|
4
|
+
RouteEventData,
|
|
5
|
+
StepEventData,
|
|
6
|
+
} from '@rango-dev/queue-manager-rango-preset';
|
|
7
|
+
|
|
8
|
+
import { WidgetEvents as QueueManagerEvents } from '@rango-dev/queue-manager-rango-preset';
|
|
9
|
+
|
|
10
|
+
type Account = Wallet;
|
|
11
|
+
|
|
12
|
+
export enum QuoteEventTypes {
|
|
13
|
+
QUOTE_INPUT_UPDATE = 'quoteInputUpdate',
|
|
14
|
+
QUOTE_OUTPUT_UPDATE = 'quoteOutputUpdate',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export enum WalletEventTypes {
|
|
18
|
+
CONNECT = 'connect',
|
|
19
|
+
DISCONNECT = 'disconnect',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type QuoteInputUpdateEventPayload = {
|
|
23
|
+
fromBlockchain?: string;
|
|
24
|
+
toBlockchain?: string;
|
|
25
|
+
fromToken?: { symbol: string; name: string | null; address: string | null };
|
|
26
|
+
toToken?: { symbol: string; name: string | null; address: string | null };
|
|
27
|
+
requestAmount?: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type QuoteUpdateEventPayload = Pick<
|
|
31
|
+
SelectedQuote,
|
|
32
|
+
'requestAmount' | 'swaps' | 'outputAmount' | 'resultType' | 'tags'
|
|
33
|
+
> | null;
|
|
34
|
+
|
|
35
|
+
export type ConnectWalletEventPayload = {
|
|
36
|
+
walletType: string;
|
|
37
|
+
accounts: Account[];
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type DisconnectWalletEventPayload = {
|
|
41
|
+
walletType: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type QuoteEventData =
|
|
45
|
+
| {
|
|
46
|
+
type: QuoteEventTypes.QUOTE_INPUT_UPDATE;
|
|
47
|
+
payload: QuoteInputUpdateEventPayload;
|
|
48
|
+
}
|
|
49
|
+
| {
|
|
50
|
+
type: QuoteEventTypes.QUOTE_OUTPUT_UPDATE;
|
|
51
|
+
payload: QuoteUpdateEventPayload;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type WalletEventData =
|
|
55
|
+
| {
|
|
56
|
+
type: WalletEventTypes.CONNECT;
|
|
57
|
+
payload: ConnectWalletEventPayload;
|
|
58
|
+
}
|
|
59
|
+
| {
|
|
60
|
+
type: WalletEventTypes.DISCONNECT;
|
|
61
|
+
payload: DisconnectWalletEventPayload;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export enum WidgetEvents {
|
|
65
|
+
RouteEvent = QueueManagerEvents.RouteEvent,
|
|
66
|
+
StepEvent = QueueManagerEvents.StepEvent,
|
|
67
|
+
QuoteEvent = 'quoteEvent',
|
|
68
|
+
WalletEvent = 'walletEvent',
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type Events = {
|
|
72
|
+
[WidgetEvents.RouteEvent]: RouteEventData;
|
|
73
|
+
[WidgetEvents.StepEvent]: StepEventData;
|
|
74
|
+
[WidgetEvents.QuoteEvent]: QuoteEventData;
|
|
75
|
+
[WidgetEvents.WalletEvent]: WalletEventData;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
declare type EventHandler<T = unknown> = (event: T) => void;
|
|
79
|
+
|
|
80
|
+
export type WidgetEventEmitter = {
|
|
81
|
+
on<Key extends WidgetEvents>(
|
|
82
|
+
type: Key,
|
|
83
|
+
handler: EventHandler<Events[Key]>
|
|
84
|
+
): void;
|
|
85
|
+
off<Key extends WidgetEvents>(
|
|
86
|
+
type: Key,
|
|
87
|
+
handler?: EventHandler<Events[Key]>
|
|
88
|
+
): void;
|
|
89
|
+
};
|