@rango-dev/widget-embedded 0.37.1-next.2 → 0.38.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/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
- package/dist/components/Layout/Layout.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/Quote.types.d.ts +0 -2
- package/dist/components/Quote/Quote.types.d.ts.map +1 -1
- package/dist/components/Quote/QuoteCostDetails.d.ts.map +1 -1
- package/dist/components/Quote/QuoteCostDetails.styles.d.ts.map +1 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts.map +1 -1
- package/dist/components/Quotes/Quotes.d.ts.map +1 -1
- package/dist/components/RefreshModal/RefreshModal.styles.d.ts +1 -1
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsCompleteModal.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts +1 -2
- package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -1
- package/dist/constants/quote.d.ts +0 -10
- package/dist/constants/quote.d.ts.map +1 -1
- package/dist/constants/warnings.d.ts +3 -0
- package/dist/constants/warnings.d.ts.map +1 -0
- package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts.map +1 -1
- package/dist/containers/Inputs/Inputs.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.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.helpers.d.ts +1 -1
- package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts +3 -3
- package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +4 -6
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -1
- package/dist/hooks/useFetchApiConfig.d.ts.map +1 -1
- package/dist/hooks/useFetchCustomToken.d.ts.map +1 -1
- package/dist/hooks/useObserveBalanceChanges/index.d.ts +2 -0
- package/dist/hooks/useObserveBalanceChanges/index.d.ts.map +1 -0
- package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts +4 -0
- package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts.map +1 -0
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts +1 -2
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +5 -3
- package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -1
- package/dist/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.d.ts.map +1 -1
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/hooks/useWalletList.d.ts.map +1 -1
- package/dist/hooks/useWalletProviders/useWalletProviders.d.ts +3 -2
- package/dist/hooks/useWalletProviders/useWalletProviders.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
- package/dist/store/app.d.ts +4 -2
- package/dist/store/app.d.ts.map +1 -1
- package/dist/store/quote.d.ts.map +1 -1
- package/dist/store/slices/config.d.ts +0 -4
- package/dist/store/slices/config.d.ts.map +1 -1
- package/dist/store/slices/data.d.ts.map +1 -1
- package/dist/store/ui.d.ts +0 -4
- package/dist/store/ui.d.ts.map +1 -1
- package/dist/store/wallets.d.ts +66 -0
- package/dist/store/wallets.d.ts.map +1 -0
- package/dist/types/config.d.ts +9 -7
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/quote.d.ts +17 -8
- package/dist/types/quote.d.ts.map +1 -1
- package/dist/types/wallets.d.ts +7 -3
- package/dist/types/wallets.d.ts.map +1 -1
- package/dist/utils/providers.d.ts +9 -8
- package/dist/utils/providers.d.ts.map +1 -1
- package/dist/utils/quote.d.ts +6 -5
- package/dist/utils/quote.d.ts.map +1 -1
- package/dist/utils/settings.d.ts +0 -1
- package/dist/utils/settings.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +5 -5
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +14 -12
- package/dist/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +9 -9
- package/src/QueueManager.tsx +11 -17
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +24 -5
- package/src/components/ConfirmWalletsModal/WalletList.tsx +7 -10
- package/src/components/Layout/Layout.tsx +3 -1
- package/src/components/Quote/Quote.tsx +3 -22
- package/src/components/Quote/Quote.types.ts +0 -2
- package/src/components/Quote/QuoteCostDetails.styles.ts +1 -0
- package/src/components/Quote/QuoteCostDetails.tsx +4 -23
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +22 -42
- package/src/components/Quotes/Quotes.tsx +3 -2
- package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +1 -1
- package/src/components/SwapDetails/SwapDetails.tsx +6 -14
- package/src/components/SwapDetailsAlerts/SwapDetailsAlerts.types.ts +1 -1
- package/src/components/SwapDetailsModal/SwapDetailsCompleteModal.tsx +13 -26
- package/src/components/TokenList/TokenList.tsx +27 -4
- package/src/components/WalletStatefulConnect/DerivationPath.helpers.ts +1 -2
- package/src/components/WalletStatefulConnect/Namespaces.tsx +38 -31
- package/src/components/WalletStatefulConnect/Namespaces.types.tsx +1 -1
- package/src/constants/quote.ts +0 -25
- package/src/constants/warnings.ts +26 -0
- package/src/containers/ExpandedQuotes/ExpandedQuotes.styles.ts +0 -1
- package/src/containers/ExpandedQuotes/ExpandedQuotes.tsx +1 -1
- package/src/containers/Inputs/Inputs.tsx +7 -20
- package/src/containers/QuoteInfo/QuoteInfo.tsx +9 -3
- package/src/containers/Wallets/Wallets.tsx +16 -82
- package/src/containers/WidgetInfo/WidgetInfo.helpers.ts +2 -2
- package/src/containers/WidgetInfo/WidgetInfo.tsx +8 -10
- package/src/containers/WidgetInfo/WidgetInfo.types.ts +3 -3
- package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +66 -29
- package/src/hooks/useConfirmSwap/useConfirmSwap.ts +15 -10
- package/src/hooks/useFetchApiConfig.ts +1 -5
- package/src/hooks/useFetchCustomToken.ts +0 -5
- package/src/hooks/useObserveBalanceChanges/index.ts +1 -0
- package/src/hooks/useObserveBalanceChanges/useObserveBalanceChanges.ts +68 -0
- package/src/hooks/useStatefulConnect/useStatefulConnect.ts +17 -50
- package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +5 -3
- package/src/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.ts +6 -7
- package/src/hooks/useSwapInput.ts +11 -3
- package/src/hooks/useWalletList.ts +8 -6
- package/src/hooks/useWalletProviders/useWalletProviders.ts +12 -8
- package/src/index.ts +1 -1
- package/src/pages/ConfirmSwapPage.tsx +15 -7
- package/src/pages/Home.tsx +3 -5
- package/src/pages/SelectSwapItemsPage.tsx +2 -1
- package/src/store/app.ts +4 -4
- package/src/store/quote.ts +13 -3
- package/src/store/slices/config.ts +0 -76
- package/src/store/slices/data.test.ts +1 -23
- package/src/store/slices/data.ts +2 -3
- package/src/store/ui.ts +0 -6
- package/src/store/wallets.ts +268 -0
- package/src/types/config.ts +9 -8
- package/src/types/quote.ts +24 -10
- package/src/types/wallets.ts +7 -3
- package/src/utils/providers.ts +36 -88
- package/src/utils/quote.ts +45 -57
- package/src/utils/settings.ts +0 -4
- package/src/utils/swap.ts +37 -56
- package/src/utils/wallets.ts +141 -79
- package/dist/store/slices/types.d.ts +0 -6
- package/dist/store/slices/types.d.ts.map +0 -1
- package/dist/store/slices/wallets.d.ts +0 -80
- package/dist/store/slices/wallets.d.ts.map +0 -1
- package/dist/store/utils/wallets.d.ts +0 -17
- package/dist/store/utils/wallets.d.ts.map +0 -1
- package/src/store/slices/types.ts +0 -9
- package/src/store/slices/wallets.ts +0 -577
- package/src/store/utils/wallets.ts +0 -111
|
@@ -13,6 +13,7 @@ import { navigationRoutes } from '../constants/navigationRoutes';
|
|
|
13
13
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
14
14
|
import { useAppStore } from '../store/AppStore';
|
|
15
15
|
import { useQuoteStore } from '../store/quote';
|
|
16
|
+
import { useWalletsStore } from '../store/wallets';
|
|
16
17
|
|
|
17
18
|
interface PropTypes {
|
|
18
19
|
type: 'source' | 'destination';
|
|
@@ -30,7 +31,7 @@ export function SelectSwapItemsPage(props: PropTypes) {
|
|
|
30
31
|
setFromBlockchain,
|
|
31
32
|
setToBlockchain,
|
|
32
33
|
} = useQuoteStore();
|
|
33
|
-
const
|
|
34
|
+
const getBalanceFor = useWalletsStore.use.getBalanceFor();
|
|
34
35
|
const [searchedFor, setSearchedFor] = useState<string>('');
|
|
35
36
|
|
|
36
37
|
const selectedBlockchain = type === 'source' ? fromBlockchain : toBlockchain;
|
package/src/store/app.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ConfigSlice } from './slices/config';
|
|
2
|
+
import type { DataSlice } from './slices/data';
|
|
3
|
+
import type { SettingsSlice } from './slices/settings';
|
|
2
4
|
import type { WidgetConfig } from '../types';
|
|
3
5
|
import type { StateCreator } from 'zustand';
|
|
4
6
|
|
|
@@ -8,7 +10,6 @@ import { persist } from 'zustand/middleware';
|
|
|
8
10
|
import { createConfigSlice } from './slices/config';
|
|
9
11
|
import { createDataSlice } from './slices/data';
|
|
10
12
|
import { createSettingsSlice } from './slices/settings';
|
|
11
|
-
import { createWalletsSlice } from './slices/wallets';
|
|
12
13
|
|
|
13
14
|
export type StateCreatorWithInitialData<
|
|
14
15
|
T extends Partial<WidgetConfig>,
|
|
@@ -19,13 +20,12 @@ export type StateCreatorWithInitialData<
|
|
|
19
20
|
...rest: Parameters<StateCreator<R, [], [], V>>
|
|
20
21
|
) => ReturnType<StateCreator<R, [], [], V>>;
|
|
21
22
|
|
|
22
|
-
export type
|
|
23
|
+
export type AppStoreState = DataSlice & ConfigSlice & SettingsSlice;
|
|
23
24
|
|
|
24
25
|
export function createAppStore(initialData?: WidgetConfig) {
|
|
25
26
|
return create<AppStoreState>()(
|
|
26
27
|
persist(
|
|
27
28
|
(...a) => ({
|
|
28
|
-
...createWalletsSlice(...a),
|
|
29
29
|
...createDataSlice(...a),
|
|
30
30
|
...createSettingsSlice(...a),
|
|
31
31
|
...createConfigSlice(initialData, ...a),
|
package/src/store/quote.ts
CHANGED
|
@@ -21,7 +21,11 @@ import {
|
|
|
21
21
|
WidgetEvents,
|
|
22
22
|
} from '../types';
|
|
23
23
|
import { isPositiveNumber } from '../utils/numbers';
|
|
24
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
getQuoteFromTokenUsdPrice,
|
|
26
|
+
getQuoteToTokenUsdPrice,
|
|
27
|
+
} from '../utils/quote';
|
|
28
|
+
import { calcOutputUsdValue } from '../utils/swap';
|
|
25
29
|
|
|
26
30
|
import createSelectors from './selectors';
|
|
27
31
|
|
|
@@ -133,8 +137,14 @@ export const useQuoteStore = createSelectors(
|
|
|
133
137
|
outputAmount = !!quote?.outputAmount
|
|
134
138
|
? new BigNumber(quote?.outputAmount)
|
|
135
139
|
: null;
|
|
136
|
-
inputUsdValue =
|
|
137
|
-
|
|
140
|
+
inputUsdValue = calcOutputUsdValue(
|
|
141
|
+
state.inputAmount,
|
|
142
|
+
getQuoteFromTokenUsdPrice(quote) || state.fromToken?.usdPrice
|
|
143
|
+
);
|
|
144
|
+
outputUsdValue = calcOutputUsdValue(
|
|
145
|
+
quote.outputAmount,
|
|
146
|
+
getQuoteToTokenUsdPrice(quote) || state.toToken?.usdPrice
|
|
147
|
+
);
|
|
138
148
|
}
|
|
139
149
|
return {
|
|
140
150
|
selectedQuote: quote,
|
|
@@ -3,31 +3,9 @@ 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
|
-
|
|
9
6
|
import { cacheService } from '../../services/cacheService';
|
|
10
|
-
import {
|
|
11
|
-
matchAndGenerateProviders,
|
|
12
|
-
type ProvidersOptions,
|
|
13
|
-
} from '../../utils/providers';
|
|
14
7
|
import { matchTokensFromConfigWithMeta } from '../utils';
|
|
15
8
|
|
|
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
|
-
|
|
31
9
|
export const DEFAULT_CONFIG: WidgetConfig = {
|
|
32
10
|
apiKey: '',
|
|
33
11
|
title: undefined,
|
|
@@ -43,9 +21,6 @@ export const DEFAULT_CONFIG: WidgetConfig = {
|
|
|
43
21
|
manifestUrl:
|
|
44
22
|
'https://raw.githubusercontent.com/rango-exchange/rango-types/main/assets/manifests/tonconnect-manifest.json',
|
|
45
23
|
},
|
|
46
|
-
features: {
|
|
47
|
-
experimentalWallet: 'enabled',
|
|
48
|
-
},
|
|
49
24
|
};
|
|
50
25
|
|
|
51
26
|
interface IframeConfigs {
|
|
@@ -83,31 +58,6 @@ export interface ConfigSlice {
|
|
|
83
58
|
name: K,
|
|
84
59
|
value: IframeConfigs[K]
|
|
85
60
|
) => 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;
|
|
111
61
|
}
|
|
112
62
|
|
|
113
63
|
export const createConfigSlice: StateCreatorWithInitialData<
|
|
@@ -115,15 +65,10 @@ export const createConfigSlice: StateCreatorWithInitialData<
|
|
|
115
65
|
ConfigSlice & SettingsSlice & DataSlice,
|
|
116
66
|
ConfigSlice
|
|
117
67
|
> = (initialData, set, get) => {
|
|
118
|
-
const allBuiltProviders = generateProviders({
|
|
119
|
-
...DEFAULT_CONFIG,
|
|
120
|
-
...initialData,
|
|
121
|
-
});
|
|
122
68
|
return {
|
|
123
69
|
config: { ...DEFAULT_CONFIG, ...initialData },
|
|
124
70
|
iframe: DEFAULT_IFRAME_CONFIGS,
|
|
125
71
|
campaignMode: DEFAULT_CAMPAIGN_MODE,
|
|
126
|
-
allProviders: allBuiltProviders,
|
|
127
72
|
getLiquiditySources: () => {
|
|
128
73
|
const { config, campaignMode } = get();
|
|
129
74
|
return campaignMode.liquiditySources?.length
|
|
@@ -214,26 +159,5 @@ export const createConfigSlice: StateCreatorWithInitialData<
|
|
|
214
159
|
},
|
|
215
160
|
});
|
|
216
161
|
},
|
|
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
|
-
},
|
|
238
162
|
};
|
|
239
163
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { WidgetConfig } from '../../types';
|
|
2
1
|
import type { AppStoreState } from '../app';
|
|
3
2
|
import type { EvmBlockchainMeta, Token } from 'rango-sdk';
|
|
4
3
|
|
|
@@ -18,27 +17,6 @@ let appStoreState: AppStoreState;
|
|
|
18
17
|
let customTokens: [Token, Token, Token];
|
|
19
18
|
let rangoBlockchain: EvmBlockchainMeta;
|
|
20
19
|
|
|
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
|
-
|
|
42
20
|
beforeEach(() => {
|
|
43
21
|
cacheService.clear();
|
|
44
22
|
rangoBlockchain = createEvmBlockchain();
|
|
@@ -82,7 +60,7 @@ beforeEach(() => {
|
|
|
82
60
|
initData._tokensMapByBlockchainName[token.blockchain].push(tokenHash);
|
|
83
61
|
});
|
|
84
62
|
|
|
85
|
-
const appStore = createAppStore(
|
|
63
|
+
const appStore = createAppStore();
|
|
86
64
|
appStore.setState(initData);
|
|
87
65
|
appStoreState = appStore.getState();
|
|
88
66
|
});
|
package/src/store/slices/data.ts
CHANGED
|
@@ -348,9 +348,8 @@ export const createDataSlice: StateCreator<
|
|
|
348
348
|
{};
|
|
349
349
|
const tokens: Token[] = [];
|
|
350
350
|
const popularTokens: Token[] = response.popularTokens;
|
|
351
|
-
const swappers: SwapperMeta[] = response.swappers
|
|
352
|
-
|
|
353
|
-
);
|
|
351
|
+
const swappers: SwapperMeta[] = response.swappers;
|
|
352
|
+
|
|
354
353
|
const blockchainsWithAtLeastOneToken = new Set();
|
|
355
354
|
|
|
356
355
|
response.tokens.forEach((token) => {
|
package/src/store/ui.ts
CHANGED
|
@@ -12,14 +12,12 @@ interface UiState {
|
|
|
12
12
|
tabManagerInitiated: boolean;
|
|
13
13
|
showActivateTabModal: boolean;
|
|
14
14
|
watermark: Watermark;
|
|
15
|
-
showProfileBanner: boolean;
|
|
16
15
|
activateCurrentTab: (
|
|
17
16
|
setCurrentTabAsActive: () => void,
|
|
18
17
|
hasRunningSwaps: boolean
|
|
19
18
|
) => void;
|
|
20
19
|
setShowActivateTabModal: (flag: boolean) => void;
|
|
21
20
|
setWatermark: (watermark: Watermark) => void;
|
|
22
|
-
setShowProfileBanner: (showProfileBanner: boolean) => void;
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
export const useUiStore = createSelectors(
|
|
@@ -28,7 +26,6 @@ export const useUiStore = createSelectors(
|
|
|
28
26
|
tabManagerInitiated: false,
|
|
29
27
|
showActivateTabModal: false,
|
|
30
28
|
watermark: 'NONE',
|
|
31
|
-
showProfileBanner: false,
|
|
32
29
|
fetchingApiConfig: false,
|
|
33
30
|
activateCurrentTab: (setCurrentTabAsActive, hasRunningSwaps) => {
|
|
34
31
|
const { showActivateTabModal } = get();
|
|
@@ -45,9 +42,6 @@ export const useUiStore = createSelectors(
|
|
|
45
42
|
setWatermark: (watermark) => {
|
|
46
43
|
set({ watermark });
|
|
47
44
|
},
|
|
48
|
-
setShowProfileBanner: (showProfileBanner) => {
|
|
49
|
-
set({ showProfileBanner });
|
|
50
|
-
},
|
|
51
45
|
}))
|
|
52
46
|
);
|
|
53
47
|
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import type { FindToken } from './slices/data';
|
|
2
|
+
import type { Balance, TokensBalance, Wallet } from '../types';
|
|
3
|
+
import type { WalletType } from '@rango-dev/wallets-shared';
|
|
4
|
+
import type { Token } from 'rango-sdk';
|
|
5
|
+
|
|
6
|
+
import { create } from 'zustand';
|
|
7
|
+
import { subscribeWithSelector } from 'zustand/middleware';
|
|
8
|
+
|
|
9
|
+
import { eventEmitter } from '../services/eventEmitter';
|
|
10
|
+
import { httpService } from '../services/httpService';
|
|
11
|
+
import { WalletEventTypes, WidgetEvents } from '../types';
|
|
12
|
+
import { createTokenHash } from '../utils/meta';
|
|
13
|
+
import {
|
|
14
|
+
isAccountAndWalletMatched,
|
|
15
|
+
makeBalanceFor,
|
|
16
|
+
makeTokensBalance,
|
|
17
|
+
resetConnectedWalletState,
|
|
18
|
+
} from '../utils/wallets';
|
|
19
|
+
|
|
20
|
+
import createSelectors from './selectors';
|
|
21
|
+
|
|
22
|
+
export type TokenBalance = {
|
|
23
|
+
chain: string;
|
|
24
|
+
symbol: string;
|
|
25
|
+
ticker: string;
|
|
26
|
+
address: string | null;
|
|
27
|
+
rawAmount: string;
|
|
28
|
+
decimal: number | null;
|
|
29
|
+
amount: string;
|
|
30
|
+
logo: string | null;
|
|
31
|
+
usdPrice: number | null;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export interface ConnectedWallet extends Wallet {
|
|
35
|
+
balances: TokenBalance[] | null;
|
|
36
|
+
explorerUrl: string | null;
|
|
37
|
+
selected: boolean;
|
|
38
|
+
loading: boolean;
|
|
39
|
+
error: boolean;
|
|
40
|
+
}
|
|
41
|
+
interface WalletsStore {
|
|
42
|
+
connectedWallets: ConnectedWallet[];
|
|
43
|
+
balances: TokensBalance;
|
|
44
|
+
loading: boolean;
|
|
45
|
+
connectWallet: (accounts: Wallet[], findToken: FindToken) => void;
|
|
46
|
+
disconnectWallet: (walletType: WalletType) => void;
|
|
47
|
+
selectWallets: (wallets: { walletType: string; chain: string }[]) => void;
|
|
48
|
+
clearConnectedWallet: () => void;
|
|
49
|
+
getWalletsDetails: (
|
|
50
|
+
accounts: Wallet[],
|
|
51
|
+
findToken: FindToken,
|
|
52
|
+
shouldRetry?: boolean
|
|
53
|
+
) => void;
|
|
54
|
+
getBalanceFor: (token: Token) => Balance | null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const useWalletsStore = createSelectors(
|
|
58
|
+
create<WalletsStore>()(
|
|
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
|
|
131
|
+
);
|
|
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
|
|
161
|
+
);
|
|
162
|
+
if (walletSelected) {
|
|
163
|
+
return { ...connectedWallet, selected: false };
|
|
164
|
+
} else if (walletNotSelected) {
|
|
165
|
+
return { ...connectedWallet, selected: true };
|
|
166
|
+
}
|
|
167
|
+
|
|
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
|
+
}),
|
|
187
|
+
}));
|
|
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
|
+
error: false,
|
|
224
|
+
}
|
|
225
|
+
: connectedWallet;
|
|
226
|
+
}
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
const balances = makeTokensBalance(connectedWallets);
|
|
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
|
+
});
|
|
248
|
+
|
|
249
|
+
const balances = makeTokensBalance(connectedWallets);
|
|
250
|
+
|
|
251
|
+
return {
|
|
252
|
+
loading: false,
|
|
253
|
+
balances,
|
|
254
|
+
connectedWallets,
|
|
255
|
+
};
|
|
256
|
+
});
|
|
257
|
+
}
|
|
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
|
+
})
|
|
267
|
+
)
|
|
268
|
+
);
|
package/src/types/config.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Language, theme } from '@rango-dev/ui';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ProviderInterface } from '@rango-dev/wallets-react';
|
|
3
3
|
import type { WalletType } from '@rango-dev/wallets-shared';
|
|
4
4
|
import type { Asset } from 'rango-sdk';
|
|
5
5
|
|
|
@@ -108,8 +108,13 @@ export type BlockchainAndTokenConfig = {
|
|
|
108
108
|
tokens?: Asset[] | { [blockchain: string]: Tokens };
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
+
/**
|
|
112
|
+
* `SignersConfig`
|
|
113
|
+
*
|
|
114
|
+
* @property {string | string[]} customSolanaRPC - This is an optional property that can be used to set custom Solana RPCs.
|
|
115
|
+
*/
|
|
111
116
|
export type SignersConfig = {
|
|
112
|
-
customSolanaRPC?: string;
|
|
117
|
+
customSolanaRPC?: string | string[];
|
|
113
118
|
};
|
|
114
119
|
|
|
115
120
|
/**
|
|
@@ -129,9 +134,6 @@ export type SignersConfig = {
|
|
|
129
134
|
*
|
|
130
135
|
* @property {'visible' | 'hidden'} [liquiditySource]
|
|
131
136
|
* - The visibility state for the liquiditySource feature. Optional property.
|
|
132
|
-
*
|
|
133
|
-
* @property {'disabled' | 'enabled'} [experimentalWallet]
|
|
134
|
-
* - Enable our experimental version of wallets. Default: disable on production, enabled on dev.
|
|
135
137
|
*/
|
|
136
138
|
export type Features = Partial<
|
|
137
139
|
Record<
|
|
@@ -143,8 +145,7 @@ export type Features = Partial<
|
|
|
143
145
|
| 'customTokens',
|
|
144
146
|
'visible' | 'hidden'
|
|
145
147
|
>
|
|
146
|
-
|
|
147
|
-
Partial<Record<'experimentalWallet', 'disabled' | 'enabled'>>;
|
|
148
|
+
>;
|
|
148
149
|
|
|
149
150
|
/**
|
|
150
151
|
* `Routing`
|
|
@@ -257,7 +258,7 @@ export type WidgetConfig = {
|
|
|
257
258
|
from?: BlockchainAndTokenConfig;
|
|
258
259
|
to?: BlockchainAndTokenConfig;
|
|
259
260
|
liquiditySources?: string[];
|
|
260
|
-
wallets?: (WalletType |
|
|
261
|
+
wallets?: (WalletType | ProviderInterface)[];
|
|
261
262
|
multiWallets?: boolean;
|
|
262
263
|
customDestination?: boolean;
|
|
263
264
|
defaultCustomDestinations?: { [blockchain: string]: string };
|
package/src/types/quote.ts
CHANGED
|
@@ -51,9 +51,29 @@ export enum QuoteWarningType {
|
|
|
51
51
|
UNKNOWN_PRICE,
|
|
52
52
|
INSUFFICIENT_SLIPPAGE,
|
|
53
53
|
HIGH_SLIPPAGE,
|
|
54
|
-
EXCESSIVE_OUTPUT_AMOUNT_CHANGE,
|
|
55
54
|
}
|
|
56
55
|
|
|
56
|
+
export enum QuoteUpdateType {
|
|
57
|
+
QUOTE_UPDATED,
|
|
58
|
+
QUOTE_SWAPPERS_UPDATED,
|
|
59
|
+
QUOTE_COINS_UPDATED,
|
|
60
|
+
QUOTE_AND_OUTPUT_AMOUNT_UPDATED,
|
|
61
|
+
QUOTE_UPDATED_WITH_HIGH_VALUE_LOSS,
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type QuoteUpdateWarning =
|
|
65
|
+
| {
|
|
66
|
+
type: QuoteUpdateType.QUOTE_AND_OUTPUT_AMOUNT_UPDATED;
|
|
67
|
+
newOutputAmount: string;
|
|
68
|
+
percentageChange: string;
|
|
69
|
+
}
|
|
70
|
+
| {
|
|
71
|
+
type: Exclude<
|
|
72
|
+
QuoteUpdateType,
|
|
73
|
+
QuoteUpdateType.QUOTE_AND_OUTPUT_AMOUNT_UPDATED
|
|
74
|
+
>;
|
|
75
|
+
};
|
|
76
|
+
|
|
57
77
|
export type RecommendedSlippages = Map<number, string>;
|
|
58
78
|
|
|
59
79
|
export type InsufficientSlippageWarning = {
|
|
@@ -80,21 +100,15 @@ export type UnknownPriceWarning = {
|
|
|
80
100
|
type: QuoteWarningType.UNKNOWN_PRICE;
|
|
81
101
|
};
|
|
82
102
|
|
|
83
|
-
export type ExcessiveOutputAmountChange = {
|
|
84
|
-
type: QuoteWarningType.EXCESSIVE_OUTPUT_AMOUNT_CHANGE;
|
|
85
|
-
usdValueChange: string;
|
|
86
|
-
percentageChange: string;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
103
|
export type QuoteWarning =
|
|
90
104
|
| HighValueLossWarning
|
|
91
|
-
| ExcessiveOutputAmountChange
|
|
92
|
-
| UnknownPriceWarning
|
|
93
105
|
| InsufficientSlippageWarning
|
|
94
|
-
| HighSlippageWarning
|
|
106
|
+
| HighSlippageWarning
|
|
107
|
+
| UnknownPriceWarning;
|
|
95
108
|
|
|
96
109
|
export type ConfirmSwapWarnings = {
|
|
97
110
|
quote: QuoteWarning | null;
|
|
111
|
+
quoteUpdate: QuoteUpdateWarning | null;
|
|
98
112
|
balance: { messages: string[] } | null;
|
|
99
113
|
};
|
|
100
114
|
|
package/src/types/wallets.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { WalletInfo } from '@rango-dev/ui';
|
|
2
|
-
import type { WalletType } from '@rango-dev/wallets-shared';
|
|
2
|
+
import type { Namespace, WalletType } from '@rango-dev/wallets-shared';
|
|
3
3
|
|
|
4
4
|
export interface Wallet {
|
|
5
5
|
chain: string;
|
|
@@ -10,7 +10,7 @@ export interface Wallet {
|
|
|
10
10
|
export type Balance = {
|
|
11
11
|
amount: string;
|
|
12
12
|
decimals: number;
|
|
13
|
-
usdValue: string
|
|
13
|
+
usdValue: string;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export type Blockchain = string;
|
|
@@ -24,4 +24,8 @@ export type TokensBalance = {
|
|
|
24
24
|
[key: TokenHash]: Balance;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
export type WalletInfoWithExtra = WalletInfo
|
|
27
|
+
export type WalletInfoWithExtra = WalletInfo & {
|
|
28
|
+
namespaces?: Namespace[];
|
|
29
|
+
singleNamespace?: boolean;
|
|
30
|
+
needsDerivationPath?: boolean;
|
|
31
|
+
};
|