@rango-dev/widget-embedded 0.1.10 → 0.1.11-next.4
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/App.d.ts +3 -3
- package/dist/App.d.ts.map +1 -1
- package/dist/components/AppRouter.d.ts +1 -7
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/AppRoutes.d.ts +2 -2
- package/dist/components/AppRoutes.d.ts.map +1 -1
- package/dist/components/Layout.d.ts +3 -3
- package/dist/components/Layout.d.ts.map +1 -1
- package/dist/components/PercentageChange.d.ts +9 -0
- package/dist/components/PercentageChange.d.ts.map +1 -0
- package/dist/components/TokenInfo.d.ts.map +1 -1
- package/dist/components/TokenPreview.d.ts +2 -1
- package/dist/components/TokenPreview.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap.d.ts.map +1 -1
- package/dist/hooks/useTheme.d.ts +2 -5
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/lib.d.ts +2 -2
- package/dist/lib.d.ts.map +1 -1
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts +1 -7
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/LiquiditySourcesPage.d.ts +1 -2
- package/dist/pages/LiquiditySourcesPage.d.ts.map +1 -1
- package/dist/pages/SelectChainPage.d.ts +1 -2
- package/dist/pages/SelectChainPage.d.ts.map +1 -1
- package/dist/pages/SelectTokenPage.d.ts +2 -2
- package/dist/pages/SelectTokenPage.d.ts.map +1 -1
- package/dist/pages/SettingsPage.d.ts +1 -2
- package/dist/pages/SettingsPage.d.ts.map +1 -1
- package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts +1 -1
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/store/bestRoute.d.ts +1 -0
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/store/settings.d.ts +2 -0
- package/dist/store/settings.d.ts.map +1 -1
- package/dist/types/config.d.ts +26 -29
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/routing.d.ts +14 -1
- package/dist/types/routing.d.ts.map +1 -1
- package/dist/utils/routing.d.ts +2 -2
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +2 -6
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +181 -193
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +181 -193
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +181 -193
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +6 -4
- package/readme.md +1 -1
- package/src/App.tsx +21 -13
- package/src/components/AppRouter.tsx +7 -16
- package/src/components/AppRoutes.tsx +13 -32
- package/src/components/Layout.tsx +32 -23
- package/src/components/PercentageChange.tsx +33 -0
- package/src/components/TokenInfo.tsx +20 -4
- package/src/components/TokenPreview.tsx +16 -8
- package/src/hooks/useConfirmSwap.ts +5 -4
- package/src/hooks/useTheme.ts +15 -9
- package/src/lib.tsx +30 -36
- package/src/pages/ConfirmSwapPage.tsx +14 -7
- package/src/pages/Home.tsx +10 -22
- package/src/pages/LiquiditySourcesPage.tsx +3 -6
- package/src/pages/SelectChainPage.tsx +6 -6
- package/src/pages/SelectTokenPage.tsx +16 -18
- package/src/pages/SettingsPage.tsx +8 -18
- package/src/pages/SwapDetailsPage.tsx +2 -4
- package/src/pages/WalletsPage.tsx +2 -2
- package/src/store/bestRoute.ts +38 -8
- package/src/store/settings.ts +7 -0
- package/src/types/config.ts +27 -29
- package/src/types/routing.ts +17 -1
- package/src/utils/routing.ts +29 -23
- package/src/utils/swap.ts +5 -97
package/src/types/config.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Asset } from 'rango-sdk';
|
|
2
2
|
import { WalletType } from '@rango-dev/wallets-shared';
|
|
3
|
-
export interface Source {
|
|
4
|
-
title: string;
|
|
5
|
-
type: 'BRIDGE' | 'AGGREGATOR' | 'DEX';
|
|
6
|
-
}
|
|
7
3
|
|
|
8
4
|
export type Colors = {
|
|
9
5
|
background?: string;
|
|
@@ -17,28 +13,30 @@ export type Colors = {
|
|
|
17
13
|
warning?: string;
|
|
18
14
|
};
|
|
19
15
|
|
|
20
|
-
export type
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
16
|
+
export type Theme = {
|
|
17
|
+
mode?: 'dark' | 'light' | 'auto';
|
|
18
|
+
fontFamily?: string;
|
|
19
|
+
colors?: Colors;
|
|
20
|
+
borderRadius?: number;
|
|
21
|
+
width?: number;
|
|
22
|
+
height?: number;
|
|
23
|
+
};
|
|
24
|
+
export type Support = {
|
|
25
|
+
blockchain?: string;
|
|
26
|
+
token?: Asset;
|
|
27
|
+
blockchains?: string[];
|
|
28
|
+
tokens?: Asset[];
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type WidgetConfig = {
|
|
32
|
+
affiliateRef?: string;
|
|
33
|
+
amount?: number;
|
|
34
|
+
from?: Support;
|
|
35
|
+
to?: Support;
|
|
36
|
+
liquiditySources?: string[];
|
|
37
|
+
wallets?: WalletType[];
|
|
38
|
+
multiWallets?: boolean;
|
|
39
|
+
customAddress?: boolean;
|
|
40
|
+
language?: string;
|
|
41
|
+
theme?: Theme;
|
|
44
42
|
};
|
package/src/types/routing.ts
CHANGED
|
@@ -1,17 +1,33 @@
|
|
|
1
1
|
import { RouteState } from '../store/bestRoute';
|
|
2
2
|
import { SettingsState } from '../store/settings';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
interface BestRouteStoreParams {
|
|
5
5
|
fromChain?: RouteState['fromChain'];
|
|
6
6
|
toChain?: RouteState['toChain'];
|
|
7
7
|
fromToken?: RouteState['fromToken'];
|
|
8
8
|
toToken?: RouteState['toToken'];
|
|
9
9
|
inputAmount?: RouteState['inputAmount'];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface SettingsStoreParams {
|
|
10
13
|
slippage?: SettingsState['slippage'];
|
|
11
14
|
customSlippage?: SettingsState['customSlippage'];
|
|
12
15
|
disabledLiquiditySources?: SettingsState['disabledLiquiditySources'];
|
|
16
|
+
infiniteApprove?: SettingsState['infiniteApprove'];
|
|
13
17
|
}
|
|
14
18
|
|
|
19
|
+
export type BestRouteEqualityParams =
|
|
20
|
+
| {
|
|
21
|
+
store: 'bestRoute';
|
|
22
|
+
prevState: BestRouteStoreParams;
|
|
23
|
+
currentState: BestRouteStoreParams;
|
|
24
|
+
}
|
|
25
|
+
| {
|
|
26
|
+
store: 'settings';
|
|
27
|
+
prevState: SettingsStoreParams;
|
|
28
|
+
currentState: SettingsStoreParams;
|
|
29
|
+
};
|
|
30
|
+
|
|
15
31
|
export enum ConfirmSwapErrorTypes {
|
|
16
32
|
NO_ROUTE,
|
|
17
33
|
ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS,
|
package/src/utils/routing.ts
CHANGED
|
@@ -6,7 +6,7 @@ import BigNumber from 'bignumber.js';
|
|
|
6
6
|
import { BestRouteResponse, BlockchainMeta, Token } from 'rango-sdk';
|
|
7
7
|
import { areEqual } from './common';
|
|
8
8
|
import { SelectedWallet } from './wallets';
|
|
9
|
-
import {
|
|
9
|
+
import { BestRouteEqualityParams } from '../types';
|
|
10
10
|
import { TokenMeta } from '@rango-dev/ui/dist/types/meta';
|
|
11
11
|
import { numberToString } from './numbers';
|
|
12
12
|
import { getUsdFeeOfStep } from './swap';
|
|
@@ -112,28 +112,34 @@ export function getRequiredBalanceOfWallet(
|
|
|
112
112
|
return relatedFeeStatus.requiredAssets;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
export function isRouteParametersChanged(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
115
|
+
export function isRouteParametersChanged(params: BestRouteEqualityParams) {
|
|
116
|
+
if (params.store === 'bestRoute') {
|
|
117
|
+
const { prevState, currentState } = params;
|
|
118
|
+
return (
|
|
119
|
+
!!currentState.fromToken &&
|
|
120
|
+
!!currentState.toToken &&
|
|
121
|
+
(prevState.fromChain?.name !== currentState.fromChain?.name ||
|
|
122
|
+
prevState.toChain?.name !== currentState.toChain?.name ||
|
|
123
|
+
prevState.fromToken?.symbol !== currentState.fromToken?.symbol ||
|
|
124
|
+
prevState.toToken?.symbol !== currentState.toToken?.symbol ||
|
|
125
|
+
prevState.fromToken?.blockchain !== prevState.fromToken?.blockchain ||
|
|
126
|
+
prevState.toToken?.blockchain !== currentState.toToken?.blockchain ||
|
|
127
|
+
prevState.fromToken?.address !== currentState.fromToken?.address ||
|
|
128
|
+
prevState.toToken?.address !== currentState.toToken?.address ||
|
|
129
|
+
prevState.inputAmount !== currentState.inputAmount)
|
|
130
|
+
);
|
|
131
|
+
} else if (params.store === 'settings') {
|
|
132
|
+
const { prevState, currentState } = params;
|
|
133
|
+
return (
|
|
134
|
+
prevState.slippage !== currentState.slippage ||
|
|
135
|
+
prevState.customSlippage !== currentState.customSlippage ||
|
|
136
|
+
prevState.disabledLiquiditySources?.length !==
|
|
137
|
+
currentState.disabledLiquiditySources?.length ||
|
|
138
|
+
prevState.infiniteApprove ||
|
|
139
|
+
currentState.infiniteApprove
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
137
143
|
}
|
|
138
144
|
|
|
139
145
|
export function getBestRouteWithCalculatedFees(
|
package/src/utils/swap.ts
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
WalletTypeAndAddress,
|
|
3
|
-
SwapSavedSettings,
|
|
4
|
-
} from '@rango-dev/ui/dist/types/swaps';
|
|
5
1
|
import BigNumber from 'bignumber.js';
|
|
6
2
|
import {
|
|
7
3
|
BestRouteRequest,
|
|
8
4
|
BestRouteResponse,
|
|
9
5
|
RecommendedSlippage,
|
|
10
6
|
SwapResult,
|
|
11
|
-
MetaResponse,
|
|
12
7
|
Token,
|
|
13
8
|
} from 'rango-sdk';
|
|
14
9
|
import { Account } from '../store/wallets';
|
|
@@ -140,7 +135,8 @@ export function getSwapButtonState(
|
|
|
140
135
|
if (accounts.length == 0) return { title: 'Connect Wallet', disabled: false };
|
|
141
136
|
if (loading) return { title: 'Finding Best Route...', disabled: true };
|
|
142
137
|
else if (inputIsZero) return { title: 'Enter an amount', disabled: true };
|
|
143
|
-
else if (!bestRoute
|
|
138
|
+
else if (!bestRoute || !bestRoute.result)
|
|
139
|
+
return { title: 'Swap', disabled: true };
|
|
144
140
|
else if (hasLimitError) return { title: 'Limit Error', disabled: true };
|
|
145
141
|
else if (highValueLoss)
|
|
146
142
|
return { title: 'Price impact is too high!', disabled: true };
|
|
@@ -175,96 +171,6 @@ export function canComputePriceImpact(
|
|
|
175
171
|
);
|
|
176
172
|
}
|
|
177
173
|
|
|
178
|
-
export function calculatePendingSwap(
|
|
179
|
-
inputAmount: string,
|
|
180
|
-
bestRoute: BestRouteResponse,
|
|
181
|
-
wallets: { [p: string]: WalletTypeAndAddress },
|
|
182
|
-
settings: Omit<SwapSavedSettings, 'disabledSwappersIds'>,
|
|
183
|
-
validateBalanceOrFee: boolean,
|
|
184
|
-
meta: MetaResponse
|
|
185
|
-
): PendingSwap {
|
|
186
|
-
const simulationResult = bestRoute.result;
|
|
187
|
-
if (!simulationResult) throw Error('Simulation result should not be null');
|
|
188
|
-
|
|
189
|
-
return {
|
|
190
|
-
creationTime: new Date().getTime().toString(),
|
|
191
|
-
finishTime: null,
|
|
192
|
-
requestId: bestRoute.requestId || '',
|
|
193
|
-
inputAmount: inputAmount,
|
|
194
|
-
//@ts-ignore
|
|
195
|
-
wallets,
|
|
196
|
-
status: 'running',
|
|
197
|
-
isPaused: false,
|
|
198
|
-
extraMessage: null,
|
|
199
|
-
extraMessageSeverity: null,
|
|
200
|
-
extraMessageDetail: null,
|
|
201
|
-
extraMessageErrorCode: null,
|
|
202
|
-
networkStatusExtraMessage: null,
|
|
203
|
-
networkStatusExtraMessageDetail: null,
|
|
204
|
-
lastNotificationTime: null,
|
|
205
|
-
//@ts-ignore
|
|
206
|
-
settings: settings,
|
|
207
|
-
simulationResult: simulationResult,
|
|
208
|
-
validateBalanceOrFee,
|
|
209
|
-
//@ts-ignore
|
|
210
|
-
steps:
|
|
211
|
-
bestRoute.result?.swaps?.map((swap, index) => {
|
|
212
|
-
const swapper = meta.swappers.find(
|
|
213
|
-
(swapper) => swapper.id === swap.swapperId
|
|
214
|
-
);
|
|
215
|
-
const swapperType = swapper?.types[0];
|
|
216
|
-
const fromBlockchain = meta.blockchains.find(
|
|
217
|
-
(blockchain) => blockchain.name === swap.from.blockchain
|
|
218
|
-
);
|
|
219
|
-
const toBlockchain = meta.blockchains.find(
|
|
220
|
-
(blockchain) => blockchain.name === swap.to.blockchain
|
|
221
|
-
);
|
|
222
|
-
return {
|
|
223
|
-
id: index + 1,
|
|
224
|
-
fromBlockchain: swap.from.blockchain,
|
|
225
|
-
fromSymbol: swap.from.symbol,
|
|
226
|
-
fromSymbolAddress: swap.from.address,
|
|
227
|
-
fromDecimals: swap.from.decimals,
|
|
228
|
-
fromAmountPrecision: swap.fromAmountPrecision,
|
|
229
|
-
fromAmountMinValue: swap.fromAmountMinValue,
|
|
230
|
-
fromAmountMaxValue: swap.fromAmountMaxValue,
|
|
231
|
-
toBlockchain: swap.to.blockchain,
|
|
232
|
-
fromLogo: swap.from.logo,
|
|
233
|
-
toSymbol: swap.to.symbol,
|
|
234
|
-
toSymbolAddress: swap.to.address,
|
|
235
|
-
toDecimals: swap.to.decimals,
|
|
236
|
-
toLogo: swap.to.logo,
|
|
237
|
-
startTransactionTime: new Date().getTime(),
|
|
238
|
-
swapperId: swap.swapperId,
|
|
239
|
-
feeInUsd: numberToString(getUsdFeeOfStep(swap, meta.tokens), null, 2),
|
|
240
|
-
expectedOutputAmountHumanReadable: swap.toAmount,
|
|
241
|
-
outputAmount: '',
|
|
242
|
-
status: 'created',
|
|
243
|
-
networkStatus: null,
|
|
244
|
-
executedTransactionId: null,
|
|
245
|
-
externalTransactionId: null,
|
|
246
|
-
explorerUrl: null,
|
|
247
|
-
trackingCode: null,
|
|
248
|
-
cosmosTransaction: null,
|
|
249
|
-
solanaTransaction: null,
|
|
250
|
-
starknetTransaction: null,
|
|
251
|
-
starknetApprovalTransaction: null,
|
|
252
|
-
tronTransaction: null,
|
|
253
|
-
tronApprovalTransaction: null,
|
|
254
|
-
evmTransaction: null,
|
|
255
|
-
evmApprovalTransaction: null,
|
|
256
|
-
transferTransaction: null,
|
|
257
|
-
diagnosisUrl: null,
|
|
258
|
-
internalSteps: null,
|
|
259
|
-
fromBlockchainLogo: fromBlockchain?.logo || '',
|
|
260
|
-
toBlockchainLogo: toBlockchain?.logo || '',
|
|
261
|
-
swapperLogo: swapper?.logo || '',
|
|
262
|
-
swapperType: swapperType || '',
|
|
263
|
-
};
|
|
264
|
-
}) || [],
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
|
|
268
174
|
export function requiredWallets(route: BestRouteResponse | null) {
|
|
269
175
|
const wallets: string[] = [];
|
|
270
176
|
|
|
@@ -407,7 +313,8 @@ export function createBestRouteRequestBody(
|
|
|
407
313
|
selectedWallets: SelectedWallet[],
|
|
408
314
|
disabledLiquiditySources: string[],
|
|
409
315
|
slippage: number,
|
|
410
|
-
checkPrerequisites: boolean
|
|
316
|
+
checkPrerequisites: boolean,
|
|
317
|
+
affiliateRef: string | null
|
|
411
318
|
): BestRouteRequest {
|
|
412
319
|
const selectedWalletsMap = selectedWallets.reduce(
|
|
413
320
|
(
|
|
@@ -438,6 +345,7 @@ export function createBestRouteRequestBody(
|
|
|
438
345
|
|
|
439
346
|
const requestBody: BestRouteRequest = {
|
|
440
347
|
amount: inputAmount.toString(),
|
|
348
|
+
affiliateRef,
|
|
441
349
|
checkPrerequisites,
|
|
442
350
|
from: {
|
|
443
351
|
address: fromToken.address,
|