@rango-dev/widget-embedded 0.36.1-next.8 → 0.37.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/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/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.types.d.ts +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -1
- package/dist/constants/quote.d.ts +0 -2
- package/dist/constants/quote.d.ts.map +1 -1
- package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts.map +1 -1
- package/dist/containers/Inputs/Inputs.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 +2 -2
- package/dist/containers/WidgetInfo/WidgetInfo.types.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 +1 -1
- 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 +2 -1
- 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/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/slices/config.d.ts.map +1 -1
- package/dist/store/slices/data.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 +3 -6
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/wallets.d.ts +2 -3
- package/dist/types/wallets.d.ts.map +1 -1
- package/dist/utils/providers.d.ts +8 -3
- package/dist/utils/providers.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 +1 -1
- 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 +7 -7
- package/src/QueueManager.tsx +7 -12
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +5 -3
- 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/StatefulConnectModal/StatefulConnectModal.tsx +1 -1
- package/src/components/SwapDetails/SwapDetails.tsx +1 -6
- package/src/components/SwapDetailsAlerts/SwapDetailsAlerts.types.ts +1 -1
- package/src/components/TokenList/TokenList.tsx +27 -4
- package/src/components/WalletStatefulConnect/DerivationPath.helpers.ts +1 -2
- package/src/components/WalletStatefulConnect/Namespaces.tsx +1 -1
- package/src/components/WalletStatefulConnect/Namespaces.types.tsx +1 -1
- package/src/constants/quote.ts +0 -2
- 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/Wallets/Wallets.tsx +14 -20
- package/src/containers/WidgetInfo/WidgetInfo.tsx +8 -10
- package/src/containers/WidgetInfo/WidgetInfo.types.ts +2 -2
- 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 +7 -42
- package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +1 -1
- package/src/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.ts +6 -7
- package/src/hooks/useSwapInput.ts +2 -1
- package/src/hooks/useWalletList.ts +3 -1
- package/src/hooks/useWalletProviders/useWalletProviders.ts +7 -3
- package/src/index.ts +1 -1
- package/src/pages/Home.tsx +3 -5
- package/src/pages/SelectSwapItemsPage.tsx +2 -1
- package/src/store/app.ts +4 -4
- package/src/store/slices/config.ts +0 -3
- package/src/store/slices/data.ts +2 -3
- package/src/store/wallets.ts +268 -0
- package/src/types/config.ts +3 -7
- package/src/types/wallets.ts +2 -3
- package/src/utils/providers.ts +12 -68
- package/src/utils/settings.ts +0 -4
- package/src/utils/swap.ts +1 -1
- package/src/utils/wallets.ts +137 -74
- 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 -58
- 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/dist/utils/hub.d.ts +0 -4
- package/dist/utils/hub.d.ts.map +0 -1
- package/src/store/slices/types.ts +0 -9
- package/src/store/slices/wallets.ts +0 -477
- package/src/store/utils/wallets.ts +0 -108
- package/src/utils/hub.ts +0 -21
|
@@ -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
|
|
|
@@ -129,9 +129,6 @@ export type SignersConfig = {
|
|
|
129
129
|
*
|
|
130
130
|
* @property {'visible' | 'hidden'} [liquiditySource]
|
|
131
131
|
* - 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
132
|
*/
|
|
136
133
|
export type Features = Partial<
|
|
137
134
|
Record<
|
|
@@ -143,8 +140,7 @@ export type Features = Partial<
|
|
|
143
140
|
| 'customTokens',
|
|
144
141
|
'visible' | 'hidden'
|
|
145
142
|
>
|
|
146
|
-
|
|
147
|
-
Partial<Record<'experimentalWallet', 'disabled' | 'enabled'>>;
|
|
143
|
+
>;
|
|
148
144
|
|
|
149
145
|
/**
|
|
150
146
|
* `Routing`
|
|
@@ -257,7 +253,7 @@ export type WidgetConfig = {
|
|
|
257
253
|
from?: BlockchainAndTokenConfig;
|
|
258
254
|
to?: BlockchainAndTokenConfig;
|
|
259
255
|
liquiditySources?: string[];
|
|
260
|
-
wallets?: (WalletType |
|
|
256
|
+
wallets?: (WalletType | ProviderInterface)[];
|
|
261
257
|
multiWallets?: boolean;
|
|
262
258
|
customDestination?: boolean;
|
|
263
259
|
defaultCustomDestinations?: { [blockchain: string]: string };
|
package/src/types/wallets.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { WalletInfo } from '@rango-dev/ui';
|
|
2
|
-
import type { Namespace } from '@rango-dev/wallets-
|
|
3
|
-
import type { WalletType } from '@rango-dev/wallets-shared';
|
|
2
|
+
import type { Namespace, WalletType } from '@rango-dev/wallets-shared';
|
|
4
3
|
|
|
5
4
|
export interface Wallet {
|
|
6
5
|
chain: string;
|
|
@@ -11,7 +10,7 @@ export interface Wallet {
|
|
|
11
10
|
export type Balance = {
|
|
12
11
|
amount: string;
|
|
13
12
|
decimals: number;
|
|
14
|
-
usdValue: string
|
|
13
|
+
usdValue: string;
|
|
15
14
|
};
|
|
16
15
|
|
|
17
16
|
export type Blockchain = string;
|
package/src/utils/providers.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import type { WidgetConfig } from '../types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ProviderInterface } from '@rango-dev/wallets-react';
|
|
3
3
|
|
|
4
4
|
import { allProviders } from '@rango-dev/provider-all';
|
|
5
|
-
import {
|
|
6
|
-
defineVersions,
|
|
7
|
-
pickVersion,
|
|
8
|
-
Provider,
|
|
9
|
-
type VersionedProviders,
|
|
10
|
-
} from '@rango-dev/wallets-core';
|
|
11
5
|
|
|
12
6
|
export interface ProvidersOptions {
|
|
13
7
|
walletConnectProjectId?: WidgetConfig['walletConnectProjectId'];
|
|
@@ -16,21 +10,19 @@ export interface ProvidersOptions {
|
|
|
16
10
|
>['walletConnectListedDesktopWalletLink'];
|
|
17
11
|
trezorManifest: WidgetConfig['trezorManifest'];
|
|
18
12
|
tonConnect: WidgetConfig['tonConnect'];
|
|
19
|
-
experimentalWallet?: 'enabled' | 'disabled';
|
|
20
13
|
}
|
|
21
14
|
|
|
22
15
|
/**
|
|
23
16
|
*
|
|
24
17
|
* Generate a list of providers by passing a provider name (e.g. metamask) or a custom provider which implemented ProviderInterface.
|
|
25
|
-
* @returns
|
|
18
|
+
* @returns ProviderInterface[] a list of ProviderInterface
|
|
26
19
|
*
|
|
27
20
|
*/
|
|
28
|
-
type BothProvidersInterface = LegacyProviderInterface | Provider;
|
|
29
21
|
export function matchAndGenerateProviders(
|
|
30
22
|
providers: WidgetConfig['wallets'],
|
|
31
23
|
options?: ProvidersOptions
|
|
32
|
-
):
|
|
33
|
-
const
|
|
24
|
+
): ProviderInterface[] {
|
|
25
|
+
const all = allProviders({
|
|
34
26
|
walletconnect2: {
|
|
35
27
|
WC_PROJECT_ID: options?.walletConnectProjectId || '',
|
|
36
28
|
DISABLE_MODAL_AND_OPEN_LINK:
|
|
@@ -43,12 +35,10 @@ export function matchAndGenerateProviders(
|
|
|
43
35
|
tonConnect: options?.tonConnect?.manifestUrl
|
|
44
36
|
? { manifestUrl: options?.tonConnect.manifestUrl }
|
|
45
37
|
: undefined,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const all = allProviders(envs);
|
|
38
|
+
});
|
|
49
39
|
|
|
50
40
|
if (providers) {
|
|
51
|
-
const selectedProviders:
|
|
41
|
+
const selectedProviders: ProviderInterface[] = [];
|
|
52
42
|
|
|
53
43
|
providers.forEach((requestedProvider) => {
|
|
54
44
|
/*
|
|
@@ -57,24 +47,11 @@ export function matchAndGenerateProviders(
|
|
|
57
47
|
* The second way is passing a custom provider which implemented ProviderInterface.
|
|
58
48
|
*/
|
|
59
49
|
if (typeof requestedProvider === 'string') {
|
|
60
|
-
const result:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return provider.id === requestedProvider;
|
|
64
|
-
}
|
|
65
|
-
return provider.config.type === requestedProvider;
|
|
66
|
-
});
|
|
67
|
-
|
|
50
|
+
const result: ProviderInterface | undefined = all.find((provider) => {
|
|
51
|
+
return provider.config.type === requestedProvider;
|
|
52
|
+
});
|
|
68
53
|
if (result) {
|
|
69
|
-
|
|
70
|
-
selectedProviders.push(
|
|
71
|
-
defineVersions().version('1.0.0', result).build()
|
|
72
|
-
);
|
|
73
|
-
} else {
|
|
74
|
-
selectedProviders.push(
|
|
75
|
-
defineVersions().version('0.0.0', result).build()
|
|
76
|
-
);
|
|
77
|
-
}
|
|
54
|
+
selectedProviders.push(result);
|
|
78
55
|
} else {
|
|
79
56
|
console.warn(
|
|
80
57
|
`Couldn't find ${requestedProvider} provider. Please make sure you are passing the correct name.`
|
|
@@ -82,54 +59,21 @@ export function matchAndGenerateProviders(
|
|
|
82
59
|
}
|
|
83
60
|
} else {
|
|
84
61
|
// It's a custom provider so we directly push it to the list.
|
|
85
|
-
|
|
86
|
-
selectedProviders.push(
|
|
87
|
-
defineVersions().version('1.0.0', requestedProvider).build()
|
|
88
|
-
);
|
|
89
|
-
} else {
|
|
90
|
-
selectedProviders.push(
|
|
91
|
-
defineVersions().version('0.0.0', requestedProvider).build()
|
|
92
|
-
);
|
|
93
|
-
}
|
|
62
|
+
selectedProviders.push(requestedProvider);
|
|
94
63
|
}
|
|
95
64
|
});
|
|
96
|
-
|
|
97
65
|
return selectedProviders;
|
|
98
66
|
}
|
|
99
67
|
|
|
100
68
|
return all;
|
|
101
69
|
}
|
|
102
70
|
|
|
103
|
-
// TODO: this is a duplication with what we do in core.
|
|
104
|
-
function pickVersionWithFallbackToLegacy(
|
|
105
|
-
providers: VersionedProviders[],
|
|
106
|
-
options?: ProvidersOptions
|
|
107
|
-
): BothProvidersInterface[] {
|
|
108
|
-
const { experimentalWallet = 'enabled' } = options || {};
|
|
109
|
-
|
|
110
|
-
return providers.map((provider) => {
|
|
111
|
-
const version = experimentalWallet == 'disabled' ? '0.0.0' : '1.0.0';
|
|
112
|
-
try {
|
|
113
|
-
return pickVersion(provider, version)[1];
|
|
114
|
-
} catch {
|
|
115
|
-
// Fallback to legacy version, if target version doesn't exists.
|
|
116
|
-
return pickVersion(provider, '0.0.0')[1];
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
71
|
export function configWalletsToWalletName(
|
|
122
72
|
config: WidgetConfig['wallets'],
|
|
123
73
|
options?: ProvidersOptions
|
|
124
74
|
): string[] {
|
|
125
|
-
const providers =
|
|
126
|
-
matchAndGenerateProviders(config, options),
|
|
127
|
-
options
|
|
128
|
-
);
|
|
75
|
+
const providers = matchAndGenerateProviders(config, options);
|
|
129
76
|
const names = providers.map((provider) => {
|
|
130
|
-
if (provider instanceof Provider) {
|
|
131
|
-
return provider.id;
|
|
132
|
-
}
|
|
133
77
|
return provider.config.type;
|
|
134
78
|
});
|
|
135
79
|
return names;
|
package/src/utils/settings.ts
CHANGED
|
@@ -72,10 +72,6 @@ export function isFeatureHidden(feature: keyof Features, features?: Features) {
|
|
|
72
72
|
return features?.[feature] === 'hidden';
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
export function isFeatureEnabled(feature: keyof Features, features?: Features) {
|
|
76
|
-
return features?.[feature] === 'enabled';
|
|
77
|
-
}
|
|
78
|
-
|
|
79
75
|
export function isRoutingEnabled(item: keyof Routing, routing?: Routing) {
|
|
80
76
|
return routing?.[item] === 'enabled';
|
|
81
77
|
}
|
package/src/utils/swap.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
2
|
import type { FeesGroup, NameOfFees } from '../constants/quote';
|
|
3
3
|
import type { FetchStatus, FindToken } from '../store/slices/data';
|
|
4
|
-
import type { ConnectedWallet } from '../store/
|
|
4
|
+
import type { ConnectedWallet } from '../store/wallets';
|
|
5
5
|
import type {
|
|
6
6
|
ConvertedToken,
|
|
7
7
|
QuoteError,
|