@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.
Files changed (76) hide show
  1. package/dist/App.d.ts +3 -3
  2. package/dist/App.d.ts.map +1 -1
  3. package/dist/components/AppRouter.d.ts +1 -7
  4. package/dist/components/AppRouter.d.ts.map +1 -1
  5. package/dist/components/AppRoutes.d.ts +2 -2
  6. package/dist/components/AppRoutes.d.ts.map +1 -1
  7. package/dist/components/Layout.d.ts +3 -3
  8. package/dist/components/Layout.d.ts.map +1 -1
  9. package/dist/components/PercentageChange.d.ts +9 -0
  10. package/dist/components/PercentageChange.d.ts.map +1 -0
  11. package/dist/components/TokenInfo.d.ts.map +1 -1
  12. package/dist/components/TokenPreview.d.ts +2 -1
  13. package/dist/components/TokenPreview.d.ts.map +1 -1
  14. package/dist/hooks/useConfirmSwap.d.ts.map +1 -1
  15. package/dist/hooks/useTheme.d.ts +2 -5
  16. package/dist/hooks/useTheme.d.ts.map +1 -1
  17. package/dist/lib.d.ts +2 -2
  18. package/dist/lib.d.ts.map +1 -1
  19. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  20. package/dist/pages/Home.d.ts +1 -7
  21. package/dist/pages/Home.d.ts.map +1 -1
  22. package/dist/pages/LiquiditySourcesPage.d.ts +1 -2
  23. package/dist/pages/LiquiditySourcesPage.d.ts.map +1 -1
  24. package/dist/pages/SelectChainPage.d.ts +1 -2
  25. package/dist/pages/SelectChainPage.d.ts.map +1 -1
  26. package/dist/pages/SelectTokenPage.d.ts +2 -2
  27. package/dist/pages/SelectTokenPage.d.ts.map +1 -1
  28. package/dist/pages/SettingsPage.d.ts +1 -2
  29. package/dist/pages/SettingsPage.d.ts.map +1 -1
  30. package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
  31. package/dist/pages/WalletsPage.d.ts +1 -1
  32. package/dist/pages/WalletsPage.d.ts.map +1 -1
  33. package/dist/store/bestRoute.d.ts +1 -0
  34. package/dist/store/bestRoute.d.ts.map +1 -1
  35. package/dist/store/settings.d.ts +2 -0
  36. package/dist/store/settings.d.ts.map +1 -1
  37. package/dist/types/config.d.ts +26 -29
  38. package/dist/types/config.d.ts.map +1 -1
  39. package/dist/types/routing.d.ts +14 -1
  40. package/dist/types/routing.d.ts.map +1 -1
  41. package/dist/utils/routing.d.ts +2 -2
  42. package/dist/utils/routing.d.ts.map +1 -1
  43. package/dist/utils/swap.d.ts +2 -6
  44. package/dist/utils/swap.d.ts.map +1 -1
  45. package/dist/widget-embedded.cjs.development.js +181 -193
  46. package/dist/widget-embedded.cjs.development.js.map +1 -1
  47. package/dist/widget-embedded.cjs.production.min.js +181 -193
  48. package/dist/widget-embedded.cjs.production.min.js.map +1 -1
  49. package/dist/widget-embedded.esm.js +181 -193
  50. package/dist/widget-embedded.esm.js.map +1 -1
  51. package/package.json +6 -4
  52. package/readme.md +1 -1
  53. package/src/App.tsx +21 -13
  54. package/src/components/AppRouter.tsx +7 -16
  55. package/src/components/AppRoutes.tsx +13 -32
  56. package/src/components/Layout.tsx +32 -23
  57. package/src/components/PercentageChange.tsx +33 -0
  58. package/src/components/TokenInfo.tsx +20 -4
  59. package/src/components/TokenPreview.tsx +16 -8
  60. package/src/hooks/useConfirmSwap.ts +5 -4
  61. package/src/hooks/useTheme.ts +15 -9
  62. package/src/lib.tsx +30 -36
  63. package/src/pages/ConfirmSwapPage.tsx +14 -7
  64. package/src/pages/Home.tsx +10 -22
  65. package/src/pages/LiquiditySourcesPage.tsx +3 -6
  66. package/src/pages/SelectChainPage.tsx +6 -6
  67. package/src/pages/SelectTokenPage.tsx +16 -18
  68. package/src/pages/SettingsPage.tsx +8 -18
  69. package/src/pages/SwapDetailsPage.tsx +2 -4
  70. package/src/pages/WalletsPage.tsx +2 -2
  71. package/src/store/bestRoute.ts +38 -8
  72. package/src/store/settings.ts +7 -0
  73. package/src/types/config.ts +27 -29
  74. package/src/types/routing.ts +17 -1
  75. package/src/utils/routing.ts +29 -23
  76. package/src/utils/swap.ts +5 -97
@@ -1,9 +1,5 @@
1
- import { BlockchainMeta, Token } from 'rango-sdk';
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 Configs = {
21
- fromChain: BlockchainMeta | null;
22
- fromToken: Token | null;
23
- toChain: BlockchainMeta | null;
24
- toToken: Token | null;
25
- fromAmount: number;
26
- fromChains: 'all' | BlockchainMeta[];
27
- fromTokens: 'all' | Token[];
28
- toChains: 'all' | BlockchainMeta[];
29
- toTokens: 'all' | Token[];
30
- liquiditySources: 'all' | Source[];
31
- wallets: 'all' | WalletType[];
32
- multiWallets: boolean;
33
- customeAddress: boolean;
34
- theme: 'dark' | 'light' | 'auto';
35
- title: string;
36
- width: number;
37
- height: number;
38
- languege: string;
39
- borderRadius: number;
40
- fontFamily: string;
41
- titleSize: number;
42
- titleWeight: number;
43
- colors: Colors;
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
  };
@@ -1,17 +1,33 @@
1
1
  import { RouteState } from '../store/bestRoute';
2
2
  import { SettingsState } from '../store/settings';
3
3
 
4
- export interface BestRouteParams {
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,
@@ -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 { BestRouteParams } from '../types';
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
- prevParams: BestRouteParams,
117
- currentParams: BestRouteParams
118
- ) {
119
- return (
120
- !!currentParams.fromToken &&
121
- !!currentParams.toToken &&
122
- (prevParams.fromChain?.name !== currentParams.fromChain?.name ||
123
- prevParams.toChain?.name !== currentParams.toChain?.name ||
124
- prevParams.fromToken?.symbol !== currentParams.fromToken?.symbol ||
125
- prevParams.toToken?.symbol !== currentParams.toToken?.symbol ||
126
- prevParams.fromToken?.blockchain !==
127
- currentParams.fromToken?.blockchain ||
128
- prevParams.toToken?.blockchain !== currentParams.toToken?.blockchain ||
129
- prevParams.fromToken?.address !== currentParams.fromToken?.address ||
130
- prevParams.toToken?.address !== currentParams.toToken?.address ||
131
- prevParams.inputAmount !== currentParams.inputAmount ||
132
- prevParams.slippage !== currentParams.slippage ||
133
- prevParams.customSlippage !== currentParams.customSlippage ||
134
- prevParams.disabledLiquiditySources?.length !==
135
- currentParams.disabledLiquiditySources?.length)
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) return { title: 'Swap', disabled: true };
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,