@rango-dev/widget-embedded 0.1.11-next.0 → 0.1.11-next.11
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/QueueManager.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/TokenInfo.d.ts.map +1 -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/services/httpService.d.ts +2 -1
- package/dist/services/httpService.d.ts.map +1 -1
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/store/meta.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 +27 -29
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/configs.d.ts +7 -0
- package/dist/utils/configs.d.ts.map +1 -0
- package/dist/utils/swap.d.ts +3 -7
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +144 -195
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +144 -195
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +144 -195
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +6 -4
- package/readme.md +1 -1
- package/src/App.tsx +36 -14
- package/src/QueueManager.tsx +9 -3
- package/src/components/AppRouter.tsx +7 -16
- package/src/components/AppRoutes.tsx +13 -32
- package/src/components/HeaderButtons.tsx +1 -1
- package/src/components/Layout.tsx +37 -27
- package/src/components/TokenInfo.tsx +9 -13
- package/src/components/TokenPreview.tsx +3 -7
- package/src/hooks/useConfirmSwap.ts +6 -5
- package/src/hooks/useTheme.ts +21 -9
- package/src/lib.tsx +30 -36
- package/src/pages/ConfirmSwapPage.tsx +2 -0
- package/src/pages/Home.tsx +3 -10
- 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/services/httpService.ts +12 -3
- package/src/store/bestRoute.ts +5 -4
- package/src/store/meta.ts +6 -4
- package/src/store/settings.ts +7 -0
- package/src/store/wallets.ts +2 -2
- package/src/types/config.ts +28 -29
- package/src/utils/configs.ts +24 -0
- package/src/utils/swap.ts +17 -99
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';
|
|
@@ -24,6 +19,7 @@ import {
|
|
|
24
19
|
PendingSwapStep,
|
|
25
20
|
} from '@rango-dev/queue-manager-rango-preset';
|
|
26
21
|
import { PendingSwap } from '@rango-dev/queue-manager-rango-preset';
|
|
22
|
+
import { removeDuplicateFrom } from './common';
|
|
27
23
|
|
|
28
24
|
export function getOutputRatio(
|
|
29
25
|
inputUsdValue: BigNumber,
|
|
@@ -133,13 +129,14 @@ export function getSwapButtonState(
|
|
|
133
129
|
highValueLoss: boolean,
|
|
134
130
|
priceImpactCanNotBeComputed: boolean,
|
|
135
131
|
needsToWarnEthOnPath: boolean,
|
|
136
|
-
|
|
132
|
+
inputAmount: string
|
|
137
133
|
): SwapButtonState {
|
|
138
134
|
if (loadingMetaStatus !== 'success')
|
|
139
135
|
return { title: 'Connect Wallet', disabled: true };
|
|
140
136
|
if (accounts.length == 0) return { title: 'Connect Wallet', disabled: false };
|
|
141
137
|
if (loading) return { title: 'Finding Best Route...', disabled: true };
|
|
142
|
-
else if (
|
|
138
|
+
else if (!inputAmount || inputAmount === '0')
|
|
139
|
+
return { title: 'Enter an amount', disabled: true };
|
|
143
140
|
else if (!bestRoute || !bestRoute.result)
|
|
144
141
|
return { title: 'Swap', disabled: true };
|
|
145
142
|
else if (hasLimitError) return { title: 'Limit Error', disabled: true };
|
|
@@ -176,96 +173,6 @@ export function canComputePriceImpact(
|
|
|
176
173
|
);
|
|
177
174
|
}
|
|
178
175
|
|
|
179
|
-
export function calculatePendingSwap(
|
|
180
|
-
inputAmount: string,
|
|
181
|
-
bestRoute: BestRouteResponse,
|
|
182
|
-
wallets: { [p: string]: WalletTypeAndAddress },
|
|
183
|
-
settings: Omit<SwapSavedSettings, 'disabledSwappersIds'>,
|
|
184
|
-
validateBalanceOrFee: boolean,
|
|
185
|
-
meta: MetaResponse
|
|
186
|
-
): PendingSwap {
|
|
187
|
-
const simulationResult = bestRoute.result;
|
|
188
|
-
if (!simulationResult) throw Error('Simulation result should not be null');
|
|
189
|
-
|
|
190
|
-
return {
|
|
191
|
-
creationTime: new Date().getTime().toString(),
|
|
192
|
-
finishTime: null,
|
|
193
|
-
requestId: bestRoute.requestId || '',
|
|
194
|
-
inputAmount: inputAmount,
|
|
195
|
-
//@ts-ignore
|
|
196
|
-
wallets,
|
|
197
|
-
status: 'running',
|
|
198
|
-
isPaused: false,
|
|
199
|
-
extraMessage: null,
|
|
200
|
-
extraMessageSeverity: null,
|
|
201
|
-
extraMessageDetail: null,
|
|
202
|
-
extraMessageErrorCode: null,
|
|
203
|
-
networkStatusExtraMessage: null,
|
|
204
|
-
networkStatusExtraMessageDetail: null,
|
|
205
|
-
lastNotificationTime: null,
|
|
206
|
-
//@ts-ignore
|
|
207
|
-
settings: settings,
|
|
208
|
-
simulationResult: simulationResult,
|
|
209
|
-
validateBalanceOrFee,
|
|
210
|
-
//@ts-ignore
|
|
211
|
-
steps:
|
|
212
|
-
bestRoute.result?.swaps?.map((swap, index) => {
|
|
213
|
-
const swapper = meta.swappers.find(
|
|
214
|
-
(swapper) => swapper.id === swap.swapperId
|
|
215
|
-
);
|
|
216
|
-
const swapperType = swapper?.types[0];
|
|
217
|
-
const fromBlockchain = meta.blockchains.find(
|
|
218
|
-
(blockchain) => blockchain.name === swap.from.blockchain
|
|
219
|
-
);
|
|
220
|
-
const toBlockchain = meta.blockchains.find(
|
|
221
|
-
(blockchain) => blockchain.name === swap.to.blockchain
|
|
222
|
-
);
|
|
223
|
-
return {
|
|
224
|
-
id: index + 1,
|
|
225
|
-
fromBlockchain: swap.from.blockchain,
|
|
226
|
-
fromSymbol: swap.from.symbol,
|
|
227
|
-
fromSymbolAddress: swap.from.address,
|
|
228
|
-
fromDecimals: swap.from.decimals,
|
|
229
|
-
fromAmountPrecision: swap.fromAmountPrecision,
|
|
230
|
-
fromAmountMinValue: swap.fromAmountMinValue,
|
|
231
|
-
fromAmountMaxValue: swap.fromAmountMaxValue,
|
|
232
|
-
toBlockchain: swap.to.blockchain,
|
|
233
|
-
fromLogo: swap.from.logo,
|
|
234
|
-
toSymbol: swap.to.symbol,
|
|
235
|
-
toSymbolAddress: swap.to.address,
|
|
236
|
-
toDecimals: swap.to.decimals,
|
|
237
|
-
toLogo: swap.to.logo,
|
|
238
|
-
startTransactionTime: new Date().getTime(),
|
|
239
|
-
swapperId: swap.swapperId,
|
|
240
|
-
feeInUsd: numberToString(getUsdFeeOfStep(swap, meta.tokens), null, 2),
|
|
241
|
-
expectedOutputAmountHumanReadable: swap.toAmount,
|
|
242
|
-
outputAmount: '',
|
|
243
|
-
status: 'created',
|
|
244
|
-
networkStatus: null,
|
|
245
|
-
executedTransactionId: null,
|
|
246
|
-
externalTransactionId: null,
|
|
247
|
-
explorerUrl: null,
|
|
248
|
-
trackingCode: null,
|
|
249
|
-
cosmosTransaction: null,
|
|
250
|
-
solanaTransaction: null,
|
|
251
|
-
starknetTransaction: null,
|
|
252
|
-
starknetApprovalTransaction: null,
|
|
253
|
-
tronTransaction: null,
|
|
254
|
-
tronApprovalTransaction: null,
|
|
255
|
-
evmTransaction: null,
|
|
256
|
-
evmApprovalTransaction: null,
|
|
257
|
-
transferTransaction: null,
|
|
258
|
-
diagnosisUrl: null,
|
|
259
|
-
internalSteps: null,
|
|
260
|
-
fromBlockchainLogo: fromBlockchain?.logo || '',
|
|
261
|
-
toBlockchainLogo: toBlockchain?.logo || '',
|
|
262
|
-
swapperLogo: swapper?.logo || '',
|
|
263
|
-
swapperType: swapperType || '',
|
|
264
|
-
};
|
|
265
|
-
}) || [],
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
|
|
269
176
|
export function requiredWallets(route: BestRouteResponse | null) {
|
|
270
177
|
const wallets: string[] = [];
|
|
271
178
|
|
|
@@ -408,7 +315,8 @@ export function createBestRouteRequestBody(
|
|
|
408
315
|
selectedWallets: SelectedWallet[],
|
|
409
316
|
disabledLiquiditySources: string[],
|
|
410
317
|
slippage: number,
|
|
411
|
-
|
|
318
|
+
affiliateRef: string | null,
|
|
319
|
+
initialRoute?: BestRouteResponse
|
|
412
320
|
): BestRouteRequest {
|
|
413
321
|
const selectedWalletsMap = selectedWallets.reduce(
|
|
414
322
|
(
|
|
@@ -435,10 +343,20 @@ export function createBestRouteRequestBody(
|
|
|
435
343
|
});
|
|
436
344
|
});
|
|
437
345
|
|
|
438
|
-
const
|
|
346
|
+
const checkPrerequisites = !!initialRoute;
|
|
347
|
+
|
|
348
|
+
const filteredBlockchains = removeDuplicateFrom(
|
|
349
|
+
(initialRoute?.result?.swaps || []).reduce(
|
|
350
|
+
(blockchains: string[], swap) => (
|
|
351
|
+
blockchains.push(swap.from.blockchain, swap.to.blockchain), blockchains
|
|
352
|
+
),
|
|
353
|
+
[]
|
|
354
|
+
)
|
|
355
|
+
);
|
|
439
356
|
|
|
440
357
|
const requestBody: BestRouteRequest = {
|
|
441
358
|
amount: inputAmount.toString(),
|
|
359
|
+
affiliateRef,
|
|
442
360
|
checkPrerequisites,
|
|
443
361
|
from: {
|
|
444
362
|
address: fromToken.address,
|