@rango-dev/widget-embedded 0.1.12 → 0.1.13-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 (44) hide show
  1. package/dist/App.d.ts.map +1 -1
  2. package/dist/QueueManager.d.ts.map +1 -1
  3. package/dist/components/Layout.d.ts.map +1 -1
  4. package/dist/components/TokenInfo.d.ts.map +1 -1
  5. package/dist/components/TokenPreview.d.ts.map +1 -1
  6. package/dist/components/warnings/BalanceErrors.d.ts.map +1 -1
  7. package/dist/globalStyles.d.ts +0 -1
  8. package/dist/globalStyles.d.ts.map +1 -1
  9. package/dist/lib.d.ts.map +1 -1
  10. package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
  11. package/dist/store/bestRoute.d.ts +1 -0
  12. package/dist/store/bestRoute.d.ts.map +1 -1
  13. package/dist/store/wallets.d.ts +1 -0
  14. package/dist/store/wallets.d.ts.map +1 -1
  15. package/dist/utils/numbers.d.ts +1 -2
  16. package/dist/utils/numbers.d.ts.map +1 -1
  17. package/dist/widget-embedded.cjs.development.js +91 -106
  18. package/dist/widget-embedded.cjs.development.js.map +1 -1
  19. package/dist/widget-embedded.cjs.production.min.js +91 -106
  20. package/dist/widget-embedded.cjs.production.min.js.map +1 -1
  21. package/dist/widget-embedded.esm.js +91 -106
  22. package/dist/widget-embedded.esm.js.map +1 -1
  23. package/package.json +7 -7
  24. package/src/App.tsx +1 -2
  25. package/src/QueueManager.tsx +28 -3
  26. package/src/components/BottomLogo.tsx +1 -1
  27. package/src/components/Layout.tsx +3 -1
  28. package/src/components/RoutesOverview.tsx +2 -2
  29. package/src/components/TokenInfo.tsx +1 -0
  30. package/src/components/TokenPreview.tsx +1 -0
  31. package/src/components/warnings/BalanceErrors.tsx +2 -0
  32. package/src/globalStyles.ts +0 -19
  33. package/src/index.tsx +1 -1
  34. package/src/lib.tsx +2 -3
  35. package/src/pages/ConfirmSwapPage.tsx +3 -3
  36. package/src/pages/HistoryPage.tsx +2 -2
  37. package/src/pages/Home.tsx +1 -1
  38. package/src/pages/SwapDetailsPage.tsx +3 -4
  39. package/src/store/bestRoute.ts +18 -16
  40. package/src/store/wallets.ts +38 -28
  41. package/src/utils/numbers.ts +2 -5
  42. package/dist/hooks/useCopyToClipboard.d.ts +0 -2
  43. package/dist/hooks/useCopyToClipboard.d.ts.map +0 -1
  44. package/src/hooks/useCopyToClipboard.ts +0 -23
@@ -1,4 +1,4 @@
1
- import { WalletState, Typography, InfoCircleIcon, AngleDownIcon, Spacer, Button, Image, TextField, styled, Tooltip, RetryIcon, HistoryIcon, SettingsIcon, Header as Header$1, VerticalSwapIcon, BestRoute, Alert, ChevronRightIcon, GasIcon, ConfirmSwap, History, LiquiditySourcesSelector, BlockchainSelector, TokenSelector, Settings, SecondaryPage, Spinner, LoadingFailedAlert, Wallet, SwapHistory, AddWalletIcon, globalCss, createTheme, SwapContainer } from '@rango-dev/ui';
1
+ import { WalletState, Typography, InfoCircleIcon, AngleDownIcon, Spacer, Button, Image, TextField, styled, Tooltip, RetryIcon, HistoryIcon, SettingsIcon, Header as Header$1, VerticalSwapIcon, BestRoute, Alert, ChevronRightIcon, GasIcon, ConfirmSwap, History, LiquiditySourcesSelector, BlockchainSelector, TokenSelector, Settings, SecondaryPage, Spinner, LoadingFailedAlert, Wallet, useCopyToClipboard, SwapHistory, AddWalletIcon, globalCss, createTheme, SwapContainer } from '@rango-dev/ui';
2
2
  import React, { useRef, useEffect, useState, useLayoutEffect, useMemo } from 'react';
3
3
  import { useInRouterContext as useInRouterContext$1, MemoryRouter, useLocation as useLocation$1, useNavigate as useNavigate$1 } from 'react-router';
4
4
  import { PendingSwapNetworkStatus, useQueueManager, calculatePendingSwap, getCurrentStep, getCurrentBlockchainOfOrNull, getRelatedWalletOrNull, cancelSwap, makeQueueDefinition, checkWaitingForNetworkChange } from '@rango-dev/queue-manager-rango-preset';
@@ -18,7 +18,6 @@ import { allProviders } from '@rango-dev/provider-all';
18
18
  import i18n, { t } from 'i18next';
19
19
  import { useManager, Provider } from '@rango-dev/queue-manager-react';
20
20
  import dayjs from 'dayjs';
21
- import copy from 'copy-to-clipboard';
22
21
  import Backend from 'i18next-http-backend';
23
22
  import LanguageDetector from 'i18next-browser-languagedetector';
24
23
 
@@ -91,7 +90,7 @@ const numberToString = function (number, minDecimals, maxDecimals) {
91
90
  if (maxDecimals === void 0) {
92
91
  maxDecimals = null;
93
92
  }
94
- if (number === null) return '';
93
+ if (number === null || number === undefined) return '';
95
94
  if (number === '') return '';
96
95
  const n = new BigNumber$1(number);
97
96
  const roundingMode = 1;
@@ -112,12 +111,6 @@ const numberToString = function (number, minDecimals, maxDecimals) {
112
111
  return n.toFormat(Math.min(maxI, Math.min(maxDecimals || 100, Math.max(minDecimals || 0, 8))), roundingMode);
113
112
  };
114
113
  const totalArrivalTime = data => data?.result?.swaps?.reduce((a, b) => a + b.estimatedTimeInSeconds, 0) || 0;
115
- const decimalNumber = function (number, toFixed) {
116
- if (number === void 0) {
117
- number = '0';
118
- }
119
- return parseFloat(number).toFixed(toFixed);
120
- };
121
114
  const isPositiveNumber = text => !!text && parseFloat(text) > 0;
122
115
 
123
116
  function searchParamsToToken(tokens, searchParams, chain) {
@@ -838,12 +831,12 @@ function shouldRetrySwap(pendingSwap) {
838
831
  return pendingSwap.status === 'failed' && !!pendingSwap.finishTime && new Date().getTime() - parseInt(pendingSwap.finishTime) < 4 * 3600 * 1000;
839
832
  }
840
833
 
841
- const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /*#__PURE__*/subscribeWithSelector(set => ({
834
+ const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /*#__PURE__*/subscribeWithSelector((set, get) => ({
842
835
  accounts: [],
843
836
  balances: [],
844
837
  selectedWallets: [],
845
838
  connectWallet: accounts => {
846
- const tokens = useMetaStore.getState().meta.tokens;
839
+ const getOneOfWalletsDetails = get().getOneOfWalletsDetails;
847
840
  set(state => ({
848
841
  accounts: state.accounts.concat(accounts),
849
842
  balances: state.balances.concat(accounts.map(account => ({
@@ -856,28 +849,7 @@ const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /*#
856
849
  explorerUrl: null
857
850
  })))
858
851
  }));
859
- accounts.forEach(async account => {
860
- try {
861
- const response = await httpService().getWalletsDetails([{
862
- address: account.address,
863
- blockchain: account.chain
864
- }]);
865
- const retrivedBalance = response.wallets[0];
866
- if (retrivedBalance) {
867
- set(state => ({
868
- balances: state.balances.map(balance => {
869
- return isAccountAndBalanceMatched(account, balance) ? makeBalanceFor(account, retrivedBalance, tokens) : balance;
870
- })
871
- }));
872
- } else throw new Error('Wallet not found');
873
- } catch (error) {
874
- set(state => ({
875
- balances: state.balances.map(balance => {
876
- return isAccountAndBalanceMatched(account, balance) ? resetBalanceState(balance) : balance;
877
- })
878
- }));
879
- }
880
- });
852
+ accounts.forEach(async account => getOneOfWalletsDetails(account));
881
853
  },
882
854
  disconnectWallet: walletType => {
883
855
  set(state => ({
@@ -916,7 +888,38 @@ const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /*#
916
888
  accounts: [],
917
889
  balances: [],
918
890
  selectedWallets: []
919
- }))
891
+ })),
892
+ getOneOfWalletsDetails: async account => {
893
+ const tokens = useMetaStore.getState().meta.tokens;
894
+ set(state => ({
895
+ balances: state.balances.map(balance => {
896
+ return balance.address === account.address && balance.chain === account.chain ? {
897
+ ...balance,
898
+ loading: true
899
+ } : balance;
900
+ })
901
+ }));
902
+ try {
903
+ const response = await httpService().getWalletsDetails([{
904
+ address: account.address,
905
+ blockchain: account.chain
906
+ }]);
907
+ const retrivedBalance = response.wallets[0];
908
+ if (retrivedBalance) {
909
+ set(state => ({
910
+ balances: state.balances.map(balance => {
911
+ return isAccountAndBalanceMatched(account, balance) ? makeBalanceFor(account, retrivedBalance, tokens) : balance;
912
+ })
913
+ }));
914
+ } else throw new Error('Wallet not found');
915
+ } catch (error) {
916
+ set(state => ({
917
+ balances: state.balances.map(balance => {
918
+ return isAccountAndBalanceMatched(account, balance) ? resetBalanceState(balance) : balance;
919
+ })
920
+ }));
921
+ }
922
+ }
920
923
  }))));
921
924
  useWalletsStore.subscribe(state => state.balances, balances => {
922
925
  useBestRouteStore.setState(_ref => {
@@ -967,6 +970,13 @@ const useBestRouteStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /
967
970
  })
968
971
  };
969
972
  }),
973
+ resetRoute: () => set(() => ({
974
+ loading: true,
975
+ error: '',
976
+ bestRoute: null,
977
+ outputAmount: null,
978
+ outputUsdValue: new BigNumber(0)
979
+ })),
970
980
  setFromChain: (chain, setDefaultToken) => {
971
981
  set(state => {
972
982
  if (state.fromChain?.name === chain?.name) return {};
@@ -1016,7 +1026,8 @@ const useBestRouteStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /
1016
1026
  ...(!amount && {
1017
1027
  outputAmount: new BigNumber(0),
1018
1028
  outputUsdValue: new BigNumber(0),
1019
- bestRoute: null
1029
+ bestRoute: null,
1030
+ error: ''
1020
1031
  }),
1021
1032
  ...(!!state.fromToken && {
1022
1033
  inputUsdValue: getUsdValue(state.fromToken, amount)
@@ -1081,7 +1092,8 @@ const bestRoute = (bestRouteStore, settingsStore) => {
1081
1092
  const {
1082
1093
  fromToken,
1083
1094
  toToken,
1084
- inputAmount
1095
+ inputAmount,
1096
+ resetRoute
1085
1097
  } = bestRouteStore.getState();
1086
1098
  const {
1087
1099
  slippage,
@@ -1094,12 +1106,9 @@ const bestRoute = (bestRouteStore, settingsStore) => {
1094
1106
  abortController = new AbortController();
1095
1107
  const userSlippage = !!customSlippage ? customSlippage : slippage;
1096
1108
  const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, [], [], disabledLiquiditySources, userSlippage, affiliateRef);
1097
- if (!bestRouteStore.getState().loading) bestRouteStore.setState({
1098
- loading: true,
1099
- bestRoute: null,
1100
- outputAmount: null,
1101
- outputUsdValue: new BigNumber(0)
1102
- });
1109
+ if (!bestRouteStore.getState().loading) {
1110
+ resetRoute();
1111
+ }
1103
1112
  httpService().getBestRoute(requestBody, {
1104
1113
  signal: abortController.signal
1105
1114
  }).then(res => {
@@ -1125,7 +1134,8 @@ const bestRoute = (bestRouteStore, settingsStore) => {
1125
1134
  fromToken,
1126
1135
  toToken,
1127
1136
  inputAmount,
1128
- inputUsdValue
1137
+ inputUsdValue,
1138
+ resetRoute
1129
1139
  } = useBestRouteStore.getState();
1130
1140
  if (!isPositiveNumber(inputAmount) || inputUsdValue.eq(0)) return bestRouteStore.setState({
1131
1141
  loading: false
@@ -1136,12 +1146,7 @@ const bestRoute = (bestRouteStore, settingsStore) => {
1136
1146
  outputAmount: new BigNumber(inputAmount),
1137
1147
  outputUsdValue: inputUsdValue
1138
1148
  });
1139
- if (!bestRouteStore.getState().loading) bestRouteStore.setState({
1140
- loading: true,
1141
- bestRoute: null,
1142
- outputAmount: null,
1143
- outputUsdValue: new BigNumber(0)
1144
- });
1149
+ if (!bestRouteStore.getState().loading) resetRoute();
1145
1150
  debouncedFetchBestRoute();
1146
1151
  };
1147
1152
  useBestRouteStore.subscribe(state => ({
@@ -1352,7 +1357,8 @@ function PercentageChange(props) {
1352
1357
  const Box = /*#__PURE__*/styled('div', {
1353
1358
  display: 'flex',
1354
1359
  flexDirection: 'column',
1355
- width: '100%'
1360
+ width: '100%',
1361
+ overflow: 'hidden'
1356
1362
  });
1357
1363
  const Container = /*#__PURE__*/styled('div', {
1358
1364
  boxSizing: 'border-box',
@@ -1578,7 +1584,8 @@ function BottomLogo() {
1578
1584
  t
1579
1585
  } = useTranslation();
1580
1586
  return React.createElement(Container$1, null, React.createElement(Typography, {
1581
- variant: "caption"
1587
+ variant: "caption",
1588
+ color: '$neutrals600'
1582
1589
  }, t('Powered By')), React.createElement(StyledAnchor, {
1583
1590
  href: "https://rango.exchange",
1584
1591
  target: "_blank"
@@ -1746,7 +1753,7 @@ function Home() {
1746
1753
  return React.createElement(Container$2, null, React.createElement(Header$1, {
1747
1754
  title: "SWAP",
1748
1755
  suffix: React.createElement(HeaderButtons, {
1749
- onClickRefresh: !!bestRoute ? fetchBestRoute : undefined
1756
+ onClickRefresh: !!bestRoute || bestRouteError ? fetchBestRoute : undefined
1750
1757
  })
1751
1758
  }), React.createElement(FromContainer, null, React.createElement(TokenInfo, {
1752
1759
  type: "From",
@@ -1863,7 +1870,8 @@ function useNavigateBack() {
1863
1870
  const Box$1 = /*#__PURE__*/styled('div', {
1864
1871
  display: 'flex',
1865
1872
  flexDirection: 'column',
1866
- width: '100%'
1873
+ width: '100%',
1874
+ overflow: 'hidden'
1867
1875
  });
1868
1876
  const Container$3 = /*#__PURE__*/styled('div', {
1869
1877
  boxSizing: 'border-box',
@@ -2017,7 +2025,9 @@ function RoutesOverview(props) {
2017
2025
  className: "routes"
2018
2026
  }, swaps?.map((swap, idx) => {
2019
2027
  const isLast = idx + 1 == swaps.length;
2020
- return React.createElement(React.Fragment, null, React.createElement("div", {
2028
+ return React.createElement(React.Fragment, {
2029
+ key: idx
2030
+ }, React.createElement("div", {
2021
2031
  className: "route"
2022
2032
  }, swap.from.symbol), React.createElement(ChevronRightIcon, {
2023
2033
  size: 12
@@ -2207,6 +2217,8 @@ function MinRequiredSlippage(_ref) {
2207
2217
  }
2208
2218
 
2209
2219
  const List = /*#__PURE__*/styled('ul', {
2220
+ padding: 0,
2221
+ margin: 0,
2210
2222
  variants: {
2211
2223
  showListStyle: {
2212
2224
  true: {
@@ -2350,8 +2362,8 @@ function ConfirmSwapPage() {
2350
2362
  const confirmDisabled = fetchingBestRoute || !requiredWallets(bestRoute).every(chain => selectedWallets.map(wallet => wallet.chain).includes(chain));
2351
2363
  const firstStep = bestRoute?.result?.swaps[0];
2352
2364
  const lastStep = bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1];
2353
- const fromAmount = decimalNumber(firstStep?.fromAmount, 3);
2354
- const toAmount = decimalNumber(lastStep?.toAmount, 3);
2365
+ const fromAmount = numberToString(firstStep?.fromAmount, 4, 6);
2366
+ const toAmount = numberToString(lastStep?.toAmount, 4, 6);
2355
2367
  useEffect(() => {
2356
2368
  initSelectedWallets();
2357
2369
  }, []);
@@ -2481,7 +2493,8 @@ function HistoryPage() {
2481
2493
  navigateBackFrom
2482
2494
  } = useNavigateBack();
2483
2495
  const {
2484
- manager
2496
+ manager,
2497
+ state
2485
2498
  } = useManager();
2486
2499
  const pendingSwaps = getPendingSwaps(manager).map(_ref => {
2487
2500
  let {
@@ -2489,7 +2502,7 @@ function HistoryPage() {
2489
2502
  } = _ref;
2490
2503
  return swap;
2491
2504
  });
2492
- const loading = !manager?.isLoaded();
2505
+ const loading = !state.loadedFromPersistor;
2493
2506
  return React.createElement(History, {
2494
2507
  list: pendingSwaps,
2495
2508
  groupBy: groupSwapsByDate,
@@ -2744,24 +2757,6 @@ function WalletsPage(_ref) {
2744
2757
  }))))));
2745
2758
  }
2746
2759
 
2747
- function useCopyToClipboard(resetInterval) {
2748
- const [isCopied, setCopied] = React.useState(false);
2749
- const handleCopy = React.useCallback(text => {
2750
- copy(text.toString());
2751
- setCopied(true);
2752
- }, []);
2753
- React.useEffect(() => {
2754
- let timeout;
2755
- if (isCopied && resetInterval) {
2756
- timeout = setTimeout(() => setCopied(false), resetInterval);
2757
- }
2758
- return () => {
2759
- clearTimeout(timeout);
2760
- };
2761
- }, [isCopied, resetInterval]);
2762
- return [isCopied, handleCopy];
2763
- }
2764
-
2765
2760
  function timeSince(timeMillis) {
2766
2761
  const seconds = Math.floor((new Date().getTime() - timeMillis) / 1000);
2767
2762
  let intervalType;
@@ -2842,7 +2837,8 @@ function SwapDetailsPage() {
2842
2837
  } = useNavigateBack();
2843
2838
  const [isCopied, handleCopy] = useCopyToClipboard(2000);
2844
2839
  const {
2845
- manager
2840
+ manager,
2841
+ state
2846
2842
  } = useManager();
2847
2843
  const pendingSwaps = getPendingSwaps(manager);
2848
2844
  const selectedSwap = pendingSwaps.find(_ref => {
@@ -2856,7 +2852,7 @@ function SwapDetailsPage() {
2856
2852
  if (swap) cancelSwap(swap);
2857
2853
  };
2858
2854
  const swap = selectedSwap?.swap;
2859
- const loading = !manager?.isLoaded();
2855
+ const loading = !state.loadedFromPersistor;
2860
2856
  if (!swap) return React.createElement(SwapDetailsPlaceholder, {
2861
2857
  requestId: selectedSwapRequestId || '',
2862
2858
  loading: loading,
@@ -3005,7 +3001,9 @@ const Header = /*#__PURE__*/styled('div', {
3005
3001
  const WalletImageContainer = /*#__PURE__*/styled('div', {
3006
3002
  marginLeft: -15,
3007
3003
  marginRight: '$6',
3008
- borderRadius: '99999px'
3004
+ '& img': {
3005
+ borderRadius: '50%'
3006
+ }
3009
3007
  });
3010
3008
  function Layout(_ref) {
3011
3009
  let {
@@ -3082,28 +3080,6 @@ function Layout(_ref) {
3082
3080
  }));
3083
3081
  }
3084
3082
 
3085
- const globalStyles = /*#__PURE__*/globalCss({
3086
- '*': {
3087
- boxSizing: 'border-box',
3088
- margin: 0,
3089
- padding: 0,
3090
- listStyleType: 'none',
3091
- '&::-webkit-scrollbar': {
3092
- width: '$8',
3093
- height: '$8'
3094
- },
3095
- '&::-webkit-scrollbar-thumb': {
3096
- backgroundColor: '$neutrals400',
3097
- borderRadius: '$10'
3098
- },
3099
- '&::-webkit-scrollbar-thumb:hover': {
3100
- backgroundColor: '$neutrals500'
3101
- },
3102
- '&::-webkit-scrollbar-track': {
3103
- backgroundColor: '$neutrals300'
3104
- }
3105
- }
3106
- });
3107
3083
  const globalFont = fontFamily => globalCss({
3108
3084
  '@import': ["url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap')", "url('https://fonts.cdnfonts.com/css/times-new-roman')"],
3109
3085
  body: {
@@ -3334,6 +3310,8 @@ function QueueManager(props) {
3334
3310
  API_KEY: getConfig('API_KEY')
3335
3311
  });
3336
3312
  }, []);
3313
+ const getOneOfWalletsDetails = useWalletsStore.use.getOneOfWalletsDetails();
3314
+ const accounts = useWalletsStore.use.accounts();
3337
3315
  const {
3338
3316
  blockchains
3339
3317
  } = useMetaStore.use.meta();
@@ -3360,6 +3338,17 @@ function QueueManager(props) {
3360
3338
  return walletAndSupportedChainsNames(supportedChains);
3361
3339
  };
3362
3340
  const allProviders = providers();
3341
+ const notifier = data => {
3342
+ const lastStep = data.swap?.steps[data.swap.steps.length - 1];
3343
+ const outputAmount = data.step?.outputAmount || '';
3344
+ const step = data.step || lastStep;
3345
+ if (data.eventType === 'task_completed' || data.eventType === 'step_completed_with_output' && lastStep?.id !== data.step?.id || !!outputAmount) {
3346
+ const fromAccount = accounts.find(account => account.chain === step?.fromBlockchain);
3347
+ const toAccount = step?.fromBlockchain !== step?.toBlockchain && accounts.find(account => account.chain === step?.toBlockchain);
3348
+ fromAccount && getOneOfWalletsDetails(fromAccount);
3349
+ toAccount && getOneOfWalletsDetails(toAccount);
3350
+ }
3351
+ };
3363
3352
  const context = {
3364
3353
  meta: {
3365
3354
  blockchains: allBlockchains,
@@ -3375,9 +3364,7 @@ function QueueManager(props) {
3375
3364
  switchNetwork,
3376
3365
  connect,
3377
3366
  state,
3378
- notifier: message => {
3379
- console.log('[notifier]', message);
3380
- }
3367
+ notifier
3381
3368
  };
3382
3369
  return React.createElement(Provider
3383
3370
  //@ts-ignore
@@ -3396,7 +3383,6 @@ const Widget = _ref => {
3396
3383
  let {
3397
3384
  config
3398
3385
  } = _ref;
3399
- globalStyles();
3400
3386
  globalFont(config?.theme?.fontFamily || 'Roboto');
3401
3387
  const {
3402
3388
  activeTheme
@@ -3461,7 +3447,6 @@ const Widget = _ref => {
3461
3447
  providers: providers,
3462
3448
  onUpdateState: onUpdateState
3463
3449
  }, React.createElement("div", {
3464
- id: "pageContainer",
3465
3450
  className: activeTheme
3466
3451
  }, React.createElement(QueueManager, null, React.createElement(SwapContainer, {
3467
3452
  fixedHeight: currentPage !== navigationRoutes.home