@rango-dev/widget-embedded 0.29.1-next.1 → 0.29.1-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/NotificationContent/NotificationContent.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/containers/WidgetInfo/WidgetInfo.d.ts.map +1 -1
- package/dist/containers/WidgetInfo/WidgetInfo.helpers.d.ts +4 -2
- package/dist/containers/WidgetInfo/WidgetInfo.helpers.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +2 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -1
- package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -1
- package/dist/hooks/useSyncUrlAndStore/useSyncUrlAndStore.d.ts.map +1 -1
- package/dist/hooks/useSyncUrlAndStore/useSyncUrlAndStore.helpers.d.ts +2 -2
- package/dist/hooks/useSyncUrlAndStore/useSyncUrlAndStore.helpers.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/store/quote.d.ts +9 -3
- package/dist/store/quote.d.ts.map +1 -1
- package/dist/store/selectors.d.ts +1 -1
- package/dist/store/selectors.d.ts.map +1 -1
- package/dist/store/slices/data.d.ts +5 -3
- package/dist/store/slices/data.d.ts.map +1 -1
- package/dist/store/wallets.d.ts +5 -4
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/test-utils/fixtures.d.ts +1 -1
- package/dist/test-utils/fixtures.d.ts.map +1 -1
- package/dist/utils/meta.d.ts +2 -1
- package/dist/utils/meta.d.ts.map +1 -1
- package/dist/utils/quote.d.ts +4 -8
- package/dist/utils/quote.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +3 -4
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +4 -5
- package/dist/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +2 -2
- package/src/components/NotificationContent/NotificationContent.tsx +3 -8
- package/src/components/Quote/Quote.tsx +3 -3
- package/src/components/Quotes/Quotes.tsx +2 -2
- package/src/components/SwapDetails/SwapDetails.tsx +8 -3
- package/src/containers/Wallets/Wallets.tsx +2 -2
- package/src/containers/WidgetInfo/WidgetInfo.helpers.ts +12 -3
- package/src/containers/WidgetInfo/WidgetInfo.tsx +4 -2
- package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +4 -2
- package/src/hooks/useConfirmSwap/useConfirmSwap.ts +3 -1
- package/src/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.ts +3 -3
- package/src/hooks/useSwapInput.ts +2 -2
- package/src/hooks/useSyncStoresWithConfig.ts +6 -7
- package/src/hooks/useSyncUrlAndStore/useSyncUrlAndStore.helpers.ts +12 -26
- package/src/hooks/useSyncUrlAndStore/useSyncUrlAndStore.ts +19 -12
- package/src/store/quote.ts +12 -7
- package/src/store/selectors.ts +6 -4
- package/src/store/slices/data.test.ts +9 -5
- package/src/store/slices/data.ts +26 -7
- package/src/store/wallets.ts +9 -8
- package/src/test-utils/fixtures.ts +9 -2
- package/src/utils/meta.ts +5 -6
- package/src/utils/quote.ts +12 -20
- package/src/utils/swap.ts +5 -25
- package/src/utils/wallets.ts +4 -28
package/src/store/wallets.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FindToken } from './slices/data';
|
|
1
2
|
import type { Balance, TokensBalance, Wallet } from '../types';
|
|
2
3
|
import type { WalletType } from '@rango-dev/wallets-shared';
|
|
3
4
|
import type { Token } from 'rango-sdk';
|
|
@@ -6,8 +7,8 @@ import { create } from 'zustand';
|
|
|
6
7
|
import { subscribeWithSelector } from 'zustand/middleware';
|
|
7
8
|
|
|
8
9
|
import { httpService } from '../services/httpService';
|
|
10
|
+
import { createTokenHash } from '../utils/meta';
|
|
9
11
|
import {
|
|
10
|
-
createTokenHash,
|
|
11
12
|
isAccountAndWalletMatched,
|
|
12
13
|
makeBalanceFor,
|
|
13
14
|
makeTokensBalance,
|
|
@@ -39,13 +40,13 @@ interface WalletsStore {
|
|
|
39
40
|
connectedWallets: ConnectedWallet[];
|
|
40
41
|
balances: TokensBalance;
|
|
41
42
|
loading: boolean;
|
|
42
|
-
connectWallet: (accounts: Wallet[],
|
|
43
|
+
connectWallet: (accounts: Wallet[], findToken: FindToken) => void;
|
|
43
44
|
disconnectWallet: (walletType: WalletType) => void;
|
|
44
45
|
selectWallets: (wallets: { walletType: string; chain: string }[]) => void;
|
|
45
46
|
clearConnectedWallet: () => void;
|
|
46
47
|
getWalletsDetails: (
|
|
47
48
|
accounts: Wallet[],
|
|
48
|
-
|
|
49
|
+
findToken: FindToken,
|
|
49
50
|
shouldRetry?: boolean
|
|
50
51
|
) => void;
|
|
51
52
|
getBalanceFor: (token: Token) => Balance | null;
|
|
@@ -57,7 +58,7 @@ export const useWalletsStore = createSelectors(
|
|
|
57
58
|
connectedWallets: [],
|
|
58
59
|
balances: {},
|
|
59
60
|
loading: false,
|
|
60
|
-
connectWallet: (accounts,
|
|
61
|
+
connectWallet: (accounts, findToken) => {
|
|
61
62
|
const getWalletsDetails = get().getWalletsDetails;
|
|
62
63
|
set((state) => ({
|
|
63
64
|
loading: true,
|
|
@@ -88,7 +89,7 @@ export const useWalletsStore = createSelectors(
|
|
|
88
89
|
})
|
|
89
90
|
),
|
|
90
91
|
}));
|
|
91
|
-
getWalletsDetails(accounts,
|
|
92
|
+
getWalletsDetails(accounts, findToken);
|
|
92
93
|
},
|
|
93
94
|
disconnectWallet: (walletType) => {
|
|
94
95
|
set((state) => {
|
|
@@ -152,7 +153,7 @@ export const useWalletsStore = createSelectors(
|
|
|
152
153
|
connectedWallets: [],
|
|
153
154
|
selectedWallets: [],
|
|
154
155
|
})),
|
|
155
|
-
getWalletsDetails: async (accounts,
|
|
156
|
+
getWalletsDetails: async (accounts, findToken, shouldRetry = true) => {
|
|
156
157
|
const getWalletsDetails = get().getWalletsDetails;
|
|
157
158
|
set((state) => ({
|
|
158
159
|
loading: true,
|
|
@@ -188,7 +189,7 @@ export const useWalletsStore = createSelectors(
|
|
|
188
189
|
matchedAccount &&
|
|
189
190
|
shouldRetry
|
|
190
191
|
) {
|
|
191
|
-
getWalletsDetails([matchedAccount],
|
|
192
|
+
getWalletsDetails([matchedAccount], findToken, false);
|
|
192
193
|
}
|
|
193
194
|
return matchedAccount && retrievedBalanceAccount
|
|
194
195
|
? {
|
|
@@ -196,7 +197,7 @@ export const useWalletsStore = createSelectors(
|
|
|
196
197
|
explorerUrl: retrievedBalanceAccount.explorerUrl,
|
|
197
198
|
balances: makeBalanceFor(
|
|
198
199
|
retrievedBalanceAccount,
|
|
199
|
-
|
|
200
|
+
findToken
|
|
200
201
|
),
|
|
201
202
|
loading: false,
|
|
202
203
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { AppStoreState } from '../store/app';
|
|
2
|
-
import type { WidgetConfig } from '../types';
|
|
2
|
+
import type { TokenHash, WidgetConfig } from '../types';
|
|
3
3
|
import type { BlockchainMeta, EvmBlockchainMeta, Token } from 'rango-sdk';
|
|
4
4
|
|
|
5
5
|
import { faker } from '@faker-js/faker';
|
|
6
6
|
import { TransactionType } from 'rango-sdk';
|
|
7
7
|
|
|
8
|
+
import { createTokenHash } from '../utils/meta';
|
|
9
|
+
|
|
8
10
|
const TOKENS_COUNT = 20;
|
|
9
11
|
const BLOCKCHAINS_COUNT = 20;
|
|
10
12
|
|
|
@@ -230,7 +232,12 @@ export function createInitialAppStore() {
|
|
|
230
232
|
});
|
|
231
233
|
|
|
232
234
|
return {
|
|
233
|
-
|
|
235
|
+
_tokensMapByTokenHash: new Map<TokenHash, Token>(
|
|
236
|
+
tokens.map((token) => {
|
|
237
|
+
const tokenHash = createTokenHash(token);
|
|
238
|
+
return [tokenHash, token];
|
|
239
|
+
})
|
|
240
|
+
),
|
|
234
241
|
_blockchainsMapByName: new Map<string, BlockchainMeta>(
|
|
235
242
|
blockchains.map((meta) => [meta.name, meta])
|
|
236
243
|
),
|
package/src/utils/meta.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import type { TokenHash } from '../types';
|
|
1
2
|
import type { Asset, BlockchainMeta, SwapperMeta, Token } from 'rango-sdk';
|
|
2
3
|
|
|
3
|
-
import { areTokensEqual } from './wallets';
|
|
4
|
-
|
|
5
4
|
export function getBlockchainDisplayNameFor(
|
|
6
5
|
blockchainName: string,
|
|
7
6
|
blockchains: BlockchainMeta[]
|
|
@@ -24,10 +23,6 @@ export function getSwapperDisplayName(
|
|
|
24
23
|
return swappers.find((swapper) => swapper.id === swapperId)?.title;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
export function findToken(t: Asset, tokens: Token[]) {
|
|
28
|
-
return tokens.find((token) => areTokensEqual(token, t)) ?? null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
26
|
export function findBlockchain(name: string, blockchains: BlockchainMeta[]) {
|
|
32
27
|
return blockchains.find((blockchain) => blockchain.name === name) ?? null;
|
|
33
28
|
}
|
|
@@ -52,3 +47,7 @@ export function isTokenNative(
|
|
|
52
47
|
|
|
53
48
|
return false;
|
|
54
49
|
}
|
|
50
|
+
|
|
51
|
+
export function createTokenHash(asset: Asset): TokenHash {
|
|
52
|
+
return `${asset.blockchain}-${asset.symbol}-${asset.address ?? ''}`;
|
|
53
|
+
}
|
package/src/utils/quote.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
+
import type { RetryQuote } from '../store/quote';
|
|
3
|
+
import type { FindToken } from '../store/slices/data';
|
|
2
4
|
import type { QuoteWarning, SelectedQuote, Wallet } from '../types';
|
|
3
5
|
import type {
|
|
4
6
|
PriceImpactWarningLevel,
|
|
@@ -27,7 +29,7 @@ import { getUsdValue } from '../store/quote';
|
|
|
27
29
|
import { QuoteWarningType } from '../types';
|
|
28
30
|
|
|
29
31
|
import { areEqual } from './common';
|
|
30
|
-
import {
|
|
32
|
+
import { createTokenHash, findBlockchain } from './meta';
|
|
31
33
|
import {
|
|
32
34
|
checkSlippageWarnings,
|
|
33
35
|
getMinRequiredSlippage,
|
|
@@ -130,27 +132,18 @@ export function findCommonTokens<T extends Asset[], R extends Asset[]>(
|
|
|
130
132
|
listA: T,
|
|
131
133
|
listB: R
|
|
132
134
|
) {
|
|
133
|
-
const tokenToString = (token: Asset): string =>
|
|
134
|
-
`${token.symbol}-${token.blockchain}-${token.address ?? ''}`;
|
|
135
|
-
|
|
136
135
|
const set = new Set();
|
|
137
136
|
|
|
138
|
-
listA.forEach((token) => set.add(
|
|
137
|
+
listA.forEach((token) => set.add(createTokenHash(token)));
|
|
139
138
|
|
|
140
|
-
return listB.filter((token) => set.has(
|
|
139
|
+
return listB.filter((token) => set.has(createTokenHash(token))) as R;
|
|
141
140
|
}
|
|
142
141
|
|
|
143
142
|
export function createRetryQuote(
|
|
144
143
|
pendingSwap: PendingSwap,
|
|
145
144
|
blockchains: BlockchainMeta[],
|
|
146
|
-
|
|
147
|
-
): {
|
|
148
|
-
fromBlockchain: BlockchainMeta | null;
|
|
149
|
-
fromToken: Token | null;
|
|
150
|
-
toBlockchain: BlockchainMeta | null;
|
|
151
|
-
toToken: Token | null;
|
|
152
|
-
inputAmount: string;
|
|
153
|
-
} {
|
|
145
|
+
findToken: FindToken
|
|
146
|
+
): RetryQuote {
|
|
154
147
|
const firstStep = pendingSwap.steps[0];
|
|
155
148
|
const lastStep = pendingSwap.steps[pendingSwap.steps.length - 1];
|
|
156
149
|
const lastSuccessfulStep = getLastSuccessfulStep(pendingSwap.steps);
|
|
@@ -179,10 +172,9 @@ export function createRetryQuote(
|
|
|
179
172
|
blockchain: fromBlockchainMeta?.name ?? '',
|
|
180
173
|
symbol: firstStep.fromSymbol,
|
|
181
174
|
address: firstStep.fromSymbolAddress,
|
|
182
|
-
}
|
|
183
|
-
tokens
|
|
175
|
+
}
|
|
184
176
|
);
|
|
185
|
-
const toTokenMeta = findToken(toToken
|
|
177
|
+
const toTokenMeta = findToken(toToken);
|
|
186
178
|
const inputAmount = lastSuccessfulStep
|
|
187
179
|
? lastSuccessfulStep.outputAmount ?? ''
|
|
188
180
|
: pendingSwap.inputAmount;
|
|
@@ -201,11 +193,11 @@ export function generateQuoteWarnings(
|
|
|
201
193
|
params: {
|
|
202
194
|
fromToken: Token;
|
|
203
195
|
toToken: Token;
|
|
204
|
-
|
|
196
|
+
findToken: FindToken;
|
|
205
197
|
userSlippage: number;
|
|
206
198
|
}
|
|
207
199
|
): QuoteWarning | null {
|
|
208
|
-
const { fromToken, toToken,
|
|
200
|
+
const { fromToken, toToken, findToken, userSlippage } = params;
|
|
209
201
|
const inputUsdValue = getUsdValue(fromToken, quote.requestAmount);
|
|
210
202
|
const outputUsdValue = getUsdValue(toToken, quote?.outputAmount ?? '');
|
|
211
203
|
|
|
@@ -218,7 +210,7 @@ export function generateQuoteWarnings(
|
|
|
218
210
|
!!priceImpact && hasHighValueLoss(inputUsdValue, priceImpact);
|
|
219
211
|
|
|
220
212
|
if (highValueLoss) {
|
|
221
|
-
const totalFee = getTotalFeeInUsd(quote?.swaps,
|
|
213
|
+
const totalFee = getTotalFeeInUsd(quote?.swaps, findToken);
|
|
222
214
|
const warningLevel = getPriceImpactLevel(priceImpact);
|
|
223
215
|
return {
|
|
224
216
|
type: QuoteWarningType.HIGH_VALUE_LOSS,
|
package/src/utils/swap.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
2
|
import type { FeesGroup, NameOfFees } from '../constants/quote';
|
|
3
|
-
import type { FetchStatus } from '../store/slices/data';
|
|
3
|
+
import type { FetchStatus, FindToken } from '../store/slices/data';
|
|
4
4
|
import type { ConnectedWallet } from '../store/wallets';
|
|
5
5
|
import type {
|
|
6
6
|
ConvertedToken,
|
|
@@ -260,24 +260,9 @@ export function canComputePriceImpact(
|
|
|
260
260
|
);
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
-
export const getUsdPrice = (
|
|
264
|
-
blockchain: string,
|
|
265
|
-
symbol: string,
|
|
266
|
-
address: string | null,
|
|
267
|
-
allTokens: Token[]
|
|
268
|
-
): number | null => {
|
|
269
|
-
const token = allTokens?.find(
|
|
270
|
-
(t) =>
|
|
271
|
-
t.blockchain === blockchain &&
|
|
272
|
-
t.symbol?.toUpperCase() === symbol?.toUpperCase() &&
|
|
273
|
-
t.address === address
|
|
274
|
-
);
|
|
275
|
-
return token?.usdPrice || null;
|
|
276
|
-
};
|
|
277
|
-
|
|
278
263
|
export function getUsdFeeOfStep(
|
|
279
264
|
step: SwapResult,
|
|
280
|
-
|
|
265
|
+
findToken: FindToken
|
|
281
266
|
): BigNumber {
|
|
282
267
|
let totalFeeInUsd = ZERO;
|
|
283
268
|
for (let i = 0; i < step.fee.length; i++) {
|
|
@@ -286,12 +271,7 @@ export function getUsdFeeOfStep(
|
|
|
286
271
|
continue;
|
|
287
272
|
}
|
|
288
273
|
|
|
289
|
-
const unitPrice =
|
|
290
|
-
fee.asset.blockchain,
|
|
291
|
-
fee.asset.symbol,
|
|
292
|
-
fee.asset.address,
|
|
293
|
-
allTokens
|
|
294
|
-
);
|
|
274
|
+
const unitPrice = findToken(fee.asset)?.usdPrice || null;
|
|
295
275
|
totalFeeInUsd = totalFeeInUsd.plus(
|
|
296
276
|
new BigNumber(fee.amount).multipliedBy(unitPrice || 0)
|
|
297
277
|
);
|
|
@@ -302,11 +282,11 @@ export function getUsdFeeOfStep(
|
|
|
302
282
|
|
|
303
283
|
export function getTotalFeeInUsd(
|
|
304
284
|
swaps: SwapResult[],
|
|
305
|
-
|
|
285
|
+
findToken: FindToken
|
|
306
286
|
): BigNumber {
|
|
307
287
|
return swaps.reduce(
|
|
308
288
|
(totalFee: BigNumber, step) =>
|
|
309
|
-
totalFee.plus(getUsdFeeOfStep(step,
|
|
289
|
+
totalFee.plus(getUsdFeeOfStep(step, findToken)),
|
|
310
290
|
ZERO
|
|
311
291
|
);
|
|
312
292
|
}
|
package/src/utils/wallets.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
+
import type { FindToken } from '../store/slices/data';
|
|
1
2
|
import type { ConnectedWallet, TokenBalance } from '../store/wallets';
|
|
2
3
|
import type {
|
|
3
4
|
Balance,
|
|
4
5
|
SelectedQuote,
|
|
5
|
-
TokenHash,
|
|
6
6
|
TokensBalance,
|
|
7
7
|
Wallet,
|
|
8
8
|
WalletInfoWithNamespaces,
|
|
9
9
|
} from '../types';
|
|
10
10
|
import type { WalletInfo as ModalWalletInfo } from '@rango-dev/ui';
|
|
11
11
|
import type {
|
|
12
|
-
Asset,
|
|
13
12
|
Network,
|
|
14
13
|
WalletInfo,
|
|
15
14
|
WalletState,
|
|
@@ -48,6 +47,7 @@ import {
|
|
|
48
47
|
import { EXCLUDED_WALLETS } from '../constants/wallets';
|
|
49
48
|
|
|
50
49
|
import { isBlockchainTypeInCategory, removeDuplicateFrom } from './common';
|
|
50
|
+
import { createTokenHash } from './meta';
|
|
51
51
|
import { numberToString } from './numbers';
|
|
52
52
|
|
|
53
53
|
export function mapStatusToWalletState(state: WalletState): WalletStatus {
|
|
@@ -278,7 +278,7 @@ export function isAccountAndWalletMatched(
|
|
|
278
278
|
|
|
279
279
|
export function makeBalanceFor(
|
|
280
280
|
retrievedBalance: WalletDetail,
|
|
281
|
-
|
|
281
|
+
findToken: FindToken
|
|
282
282
|
): TokenBalance[] {
|
|
283
283
|
const { blockChain: chain, balances = [] } = retrievedBalance;
|
|
284
284
|
return (
|
|
@@ -293,13 +293,7 @@ export function makeBalanceFor(
|
|
|
293
293
|
.shiftedBy(-tokenBalance.amount.decimals)
|
|
294
294
|
.toFixed(),
|
|
295
295
|
logo: '',
|
|
296
|
-
usdPrice:
|
|
297
|
-
getUsdPrice(
|
|
298
|
-
chain,
|
|
299
|
-
tokenBalance.asset.symbol,
|
|
300
|
-
tokenBalance.asset.address,
|
|
301
|
-
tokens
|
|
302
|
-
) || null,
|
|
296
|
+
usdPrice: findToken(tokenBalance.asset)?.usdPrice || null,
|
|
303
297
|
})) || []
|
|
304
298
|
);
|
|
305
299
|
}
|
|
@@ -358,20 +352,6 @@ function numberWithThousandSeparator(number: string | number): string {
|
|
|
358
352
|
return parts.join('.');
|
|
359
353
|
}
|
|
360
354
|
|
|
361
|
-
export const getUsdPrice = (
|
|
362
|
-
blockchain: string,
|
|
363
|
-
symbol: string,
|
|
364
|
-
address: string | null,
|
|
365
|
-
allTokens: Token[]
|
|
366
|
-
): number | null => {
|
|
367
|
-
const token = allTokens?.find(
|
|
368
|
-
(t) =>
|
|
369
|
-
t.blockchain === blockchain &&
|
|
370
|
-
t.symbol?.toUpperCase() === symbol?.toUpperCase() &&
|
|
371
|
-
t.address === address
|
|
372
|
-
);
|
|
373
|
-
return token?.usdPrice || null;
|
|
374
|
-
};
|
|
375
355
|
export const isExperimentalChain = (
|
|
376
356
|
blockchains: BlockchainMeta[],
|
|
377
357
|
wallet: string
|
|
@@ -502,10 +482,6 @@ export function getAddress({
|
|
|
502
482
|
)?.address;
|
|
503
483
|
}
|
|
504
484
|
|
|
505
|
-
export function createTokenHash(token: Asset): TokenHash {
|
|
506
|
-
return `${token.blockchain}-${token.symbol}-${token.address ?? ''}`;
|
|
507
|
-
}
|
|
508
|
-
|
|
509
485
|
export function makeTokensBalance(connectedWallets: ConnectedWallet[]) {
|
|
510
486
|
return connectedWallets
|
|
511
487
|
.flatMap((wallet) => wallet.balances)
|