@rango-dev/widget-embedded 0.1.15 → 0.1.16-next.1
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/RoutesOverview.d.ts.map +1 -1
- package/dist/components/TokenPreview.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/store/wallets.d.ts +6 -15
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/wallets.d.ts +7 -0
- package/dist/types/wallets.d.ts.map +1 -0
- package/dist/utils/routing.d.ts +2 -3
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +8 -9
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +11 -12
- package/dist/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +67 -73
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +67 -73
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +67 -73
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/QueueManager.tsx +4 -5
- package/src/components/Layout.tsx +5 -5
- package/src/components/RoutesOverview.tsx +1 -4
- package/src/components/TokenInfo.tsx +5 -5
- package/src/components/TokenPreview.tsx +8 -3
- package/src/hooks/useConfirmSwap.ts +2 -2
- package/src/pages/ConfirmSwapPage.tsx +2 -2
- package/src/pages/Home.tsx +5 -3
- package/src/store/bestRoute.ts +7 -7
- package/src/store/wallets.ts +32 -46
- package/src/types/index.ts +1 -0
- package/src/types/wallets.ts +7 -0
- package/src/utils/routing.ts +2 -3
- package/src/utils/swap.ts +12 -11
- package/src/utils/wallets.ts +59 -52
package/src/utils/wallets.ts
CHANGED
|
@@ -22,11 +22,12 @@ import {
|
|
|
22
22
|
} from 'rango-sdk';
|
|
23
23
|
import { isCosmosBlockchain } from 'rango-types';
|
|
24
24
|
import { readAccountAddress } from '@rango-dev/wallets-core';
|
|
25
|
-
import {
|
|
25
|
+
import { ConnectedWallet, TokenBalance } from '../store/wallets';
|
|
26
26
|
import { numberToString } from './numbers';
|
|
27
27
|
import BigNumber from 'bignumber.js';
|
|
28
28
|
import { TokenWithBalance } from '../pages/SelectTokenPage';
|
|
29
29
|
import { ZERO } from '../constants/numbers';
|
|
30
|
+
import { Wallet } from '../types';
|
|
30
31
|
|
|
31
32
|
export function getStateWallet(state: WalletState): WalletStatus {
|
|
32
33
|
switch (true) {
|
|
@@ -96,11 +97,11 @@ export function prepareAccountsForWalletStore(
|
|
|
96
97
|
accounts: string[],
|
|
97
98
|
evmBasedChains: string[],
|
|
98
99
|
supportedChainNames: Network[] | null
|
|
99
|
-
):
|
|
100
|
-
const result:
|
|
100
|
+
): Wallet[] {
|
|
101
|
+
const result: Wallet[] = [];
|
|
101
102
|
|
|
102
103
|
function addAccount(network: Network, address: string) {
|
|
103
|
-
const newAccount:
|
|
104
|
+
const newAccount: Wallet = {
|
|
104
105
|
address,
|
|
105
106
|
chain: network,
|
|
106
107
|
walletType: wallet,
|
|
@@ -171,56 +172,57 @@ export function getRequiredChains(route: BestRouteResponse | null) {
|
|
|
171
172
|
return wallets;
|
|
172
173
|
}
|
|
173
174
|
|
|
174
|
-
|
|
175
|
-
type Blockchain = { name: string; accounts: Balance[] };
|
|
175
|
+
type Blockchain = { name: string; accounts: ConnectedWallet[] };
|
|
176
176
|
|
|
177
177
|
export function getSelectableWallets(
|
|
178
|
-
|
|
179
|
-
selectedWallets:
|
|
178
|
+
connectedWallets: ConnectedWallet[],
|
|
179
|
+
selectedWallets: Wallet[],
|
|
180
180
|
getWalletInfo: (type: WalletType) => WalletInfo
|
|
181
181
|
): SelectableWallet[] {
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
182
|
+
const selectableWallets: SelectableWallet[] = connectedWallets.map(
|
|
183
|
+
(connectedWallet) => ({
|
|
184
|
+
address: connectedWallet.address,
|
|
185
|
+
walletType: connectedWallet.walletType,
|
|
186
|
+
chain: connectedWallet.chain,
|
|
187
|
+
image: getWalletInfo(connectedWallet.walletType).img,
|
|
188
|
+
name: getWalletInfo(connectedWallet.walletType).name,
|
|
189
|
+
selected: !!selectedWallets.find(
|
|
190
|
+
(selectedWallet) =>
|
|
191
|
+
selectedWallet.chain === connectedWallet.chain &&
|
|
192
|
+
selectedWallet.walletType === connectedWallet.walletType
|
|
193
|
+
),
|
|
194
|
+
})
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
return selectableWallets;
|
|
196
198
|
}
|
|
197
199
|
|
|
198
200
|
export function getBalanceFromWallet(
|
|
199
|
-
|
|
201
|
+
connectedWallets: ConnectedWallet[],
|
|
200
202
|
chain: string,
|
|
201
203
|
symbol: string,
|
|
202
204
|
address: string | null
|
|
203
205
|
): TokenBalance | null {
|
|
204
|
-
if (
|
|
206
|
+
if (connectedWallets.length === 0) return null;
|
|
205
207
|
|
|
206
|
-
const
|
|
207
|
-
(
|
|
208
|
+
const selectedChainWallets = connectedWallets.filter(
|
|
209
|
+
(wallet) => wallet.chain === chain
|
|
208
210
|
);
|
|
209
|
-
if (
|
|
211
|
+
if (selectedChainWallets.length === 0) return null;
|
|
210
212
|
|
|
211
213
|
return (
|
|
212
|
-
|
|
214
|
+
selectedChainWallets
|
|
213
215
|
.map(
|
|
214
|
-
(
|
|
215
|
-
|
|
216
|
-
(
|
|
217
|
-
(address !== null &&
|
|
216
|
+
(wallet) =>
|
|
217
|
+
wallet.balances?.find(
|
|
218
|
+
(balance) =>
|
|
219
|
+
(address !== null && balance.address === address) ||
|
|
218
220
|
(address === null &&
|
|
219
|
-
|
|
220
|
-
|
|
221
|
+
balance.address === address &&
|
|
222
|
+
balance.symbol === symbol)
|
|
221
223
|
) || null
|
|
222
224
|
)
|
|
223
|
-
.filter((
|
|
225
|
+
.filter((balance) => balance !== null)
|
|
224
226
|
.sort(
|
|
225
227
|
(a, b) => parseFloat(b?.amount || '0') - parseFloat(a?.amount || '1')
|
|
226
228
|
)
|
|
@@ -228,19 +230,22 @@ export function getBalanceFromWallet(
|
|
|
228
230
|
);
|
|
229
231
|
}
|
|
230
232
|
|
|
231
|
-
export function
|
|
233
|
+
export function isAccountAndWalletMatched(
|
|
234
|
+
account: Wallet,
|
|
235
|
+
connectedWallet: ConnectedWallet
|
|
236
|
+
) {
|
|
232
237
|
return (
|
|
233
|
-
account.address ===
|
|
234
|
-
account.chain ===
|
|
235
|
-
account.walletType ===
|
|
238
|
+
account.address === connectedWallet.address &&
|
|
239
|
+
account.chain === connectedWallet.chain &&
|
|
240
|
+
account.walletType === connectedWallet.walletType
|
|
236
241
|
);
|
|
237
242
|
}
|
|
238
243
|
|
|
239
244
|
export function makeBalanceFor(
|
|
240
|
-
|
|
245
|
+
wallet: Wallet,
|
|
241
246
|
retrivedBalance: WalletDetail,
|
|
242
247
|
tokens: Token[]
|
|
243
|
-
):
|
|
248
|
+
): ConnectedWallet {
|
|
244
249
|
const {
|
|
245
250
|
address,
|
|
246
251
|
blockChain: chain,
|
|
@@ -253,7 +258,7 @@ export function makeBalanceFor(
|
|
|
253
258
|
loading: false,
|
|
254
259
|
error: false,
|
|
255
260
|
explorerUrl,
|
|
256
|
-
walletType:
|
|
261
|
+
walletType: wallet.walletType,
|
|
257
262
|
balances:
|
|
258
263
|
balances?.map((tokenBalance) => ({
|
|
259
264
|
chain,
|
|
@@ -277,14 +282,16 @@ export function makeBalanceFor(
|
|
|
277
282
|
};
|
|
278
283
|
}
|
|
279
284
|
|
|
280
|
-
export function
|
|
281
|
-
|
|
285
|
+
export function resetConnectedWalletState(
|
|
286
|
+
connectedWallet: ConnectedWallet
|
|
287
|
+
): ConnectedWallet {
|
|
288
|
+
return { ...connectedWallet, loading: false, error: true };
|
|
282
289
|
}
|
|
283
290
|
|
|
284
|
-
export const calculateWalletUsdValue = (
|
|
291
|
+
export const calculateWalletUsdValue = (connectedWallet: ConnectedWallet[]) => {
|
|
285
292
|
const uniqueAccountAddresses = new Set<string | null>();
|
|
286
|
-
const uniqueBalane:
|
|
287
|
-
(acc:
|
|
293
|
+
const uniqueBalane: ConnectedWallet[] = connectedWallet?.reduce(
|
|
294
|
+
(acc: ConnectedWallet[], current: ConnectedWallet) => {
|
|
288
295
|
return acc.findIndex(
|
|
289
296
|
(i) => i.address === current.address && i.chain === current.chain
|
|
290
297
|
) === -1
|
|
@@ -391,13 +398,13 @@ export const getKeplrCompatibleConnectedWallets = (
|
|
|
391
398
|
|
|
392
399
|
export function getTokensWithBalance(
|
|
393
400
|
tokens: TokenWithBalance[],
|
|
394
|
-
|
|
401
|
+
connectedWallets: ConnectedWallet[]
|
|
395
402
|
): TokenWithBalance[] {
|
|
396
403
|
return tokens.map(({ balance, ...otherProps }) => {
|
|
397
404
|
const tokenAmount = numberToString(
|
|
398
405
|
new BigNumber(
|
|
399
406
|
getBalanceFromWallet(
|
|
400
|
-
|
|
407
|
+
connectedWallets,
|
|
401
408
|
otherProps.blockchain,
|
|
402
409
|
otherProps.symbol,
|
|
403
410
|
otherProps.address
|
|
@@ -410,7 +417,7 @@ export function getTokensWithBalance(
|
|
|
410
417
|
tokenUsdValue = numberToString(
|
|
411
418
|
new BigNumber(
|
|
412
419
|
getBalanceFromWallet(
|
|
413
|
-
|
|
420
|
+
connectedWallets,
|
|
414
421
|
otherProps.blockchain,
|
|
415
422
|
otherProps.symbol,
|
|
416
423
|
otherProps.address
|
|
@@ -430,7 +437,7 @@ export function getTokensWithBalance(
|
|
|
430
437
|
export function getSortedTokens(
|
|
431
438
|
chain: BlockchainMeta | null,
|
|
432
439
|
tokens: Token[],
|
|
433
|
-
|
|
440
|
+
connectedWallets: ConnectedWallet[],
|
|
434
441
|
otherChainTokens: TokenWithBalance[]
|
|
435
442
|
): TokenWithBalance[] {
|
|
436
443
|
const fromChainEqueulsToToChain = chain?.name === otherChainTokens[0]?.name;
|
|
@@ -438,7 +445,7 @@ export function getSortedTokens(
|
|
|
438
445
|
const filteredTokens = tokens.filter(
|
|
439
446
|
(token) => token.blockchain === chain?.name
|
|
440
447
|
);
|
|
441
|
-
return sortTokens(getTokensWithBalance(filteredTokens,
|
|
448
|
+
return sortTokens(getTokensWithBalance(filteredTokens, connectedWallets));
|
|
442
449
|
}
|
|
443
450
|
|
|
444
451
|
export function tokensAreEqual(
|