@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
@@ -26,7 +26,6 @@ var i18n = require('i18next');
26
26
  var i18n__default = _interopDefault(i18n);
27
27
  var queueManagerReact = require('@rango-dev/queue-manager-react');
28
28
  var dayjs = _interopDefault(require('dayjs'));
29
- var copy = _interopDefault(require('copy-to-clipboard'));
30
29
  var Backend = _interopDefault(require('i18next-http-backend'));
31
30
  var LanguageDetector = _interopDefault(require('i18next-browser-languagedetector'));
32
31
 
@@ -99,7 +98,7 @@ const numberToString = function (number, minDecimals, maxDecimals) {
99
98
  if (maxDecimals === void 0) {
100
99
  maxDecimals = null;
101
100
  }
102
- if (number === null) return '';
101
+ if (number === null || number === undefined) return '';
103
102
  if (number === '') return '';
104
103
  const n = new BigNumber.BigNumber(number);
105
104
  const roundingMode = 1;
@@ -120,12 +119,6 @@ const numberToString = function (number, minDecimals, maxDecimals) {
120
119
  return n.toFormat(Math.min(maxI, Math.min(maxDecimals || 100, Math.max(minDecimals || 0, 8))), roundingMode);
121
120
  };
122
121
  const totalArrivalTime = data => data?.result?.swaps?.reduce((a, b) => a + b.estimatedTimeInSeconds, 0) || 0;
123
- const decimalNumber = function (number, toFixed) {
124
- if (number === void 0) {
125
- number = '0';
126
- }
127
- return parseFloat(number).toFixed(toFixed);
128
- };
129
122
  const isPositiveNumber = text => !!text && parseFloat(text) > 0;
130
123
 
131
124
  function searchParamsToToken(tokens, searchParams, chain) {
@@ -846,12 +839,12 @@ function shouldRetrySwap(pendingSwap) {
846
839
  return pendingSwap.status === 'failed' && !!pendingSwap.finishTime && new Date().getTime() - parseInt(pendingSwap.finishTime) < 4 * 3600 * 1000;
847
840
  }
848
841
 
849
- const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.create()( /*#__PURE__*/middleware.subscribeWithSelector(set => ({
842
+ const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.create()( /*#__PURE__*/middleware.subscribeWithSelector((set, get) => ({
850
843
  accounts: [],
851
844
  balances: [],
852
845
  selectedWallets: [],
853
846
  connectWallet: accounts => {
854
- const tokens = useMetaStore.getState().meta.tokens;
847
+ const getOneOfWalletsDetails = get().getOneOfWalletsDetails;
855
848
  set(state => ({
856
849
  accounts: state.accounts.concat(accounts),
857
850
  balances: state.balances.concat(accounts.map(account => ({
@@ -864,28 +857,7 @@ const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.creat
864
857
  explorerUrl: null
865
858
  })))
866
859
  }));
867
- accounts.forEach(async account => {
868
- try {
869
- const response = await httpService().getWalletsDetails([{
870
- address: account.address,
871
- blockchain: account.chain
872
- }]);
873
- const retrivedBalance = response.wallets[0];
874
- if (retrivedBalance) {
875
- set(state => ({
876
- balances: state.balances.map(balance => {
877
- return isAccountAndBalanceMatched(account, balance) ? makeBalanceFor(account, retrivedBalance, tokens) : balance;
878
- })
879
- }));
880
- } else throw new Error('Wallet not found');
881
- } catch (error) {
882
- set(state => ({
883
- balances: state.balances.map(balance => {
884
- return isAccountAndBalanceMatched(account, balance) ? resetBalanceState(balance) : balance;
885
- })
886
- }));
887
- }
888
- });
860
+ accounts.forEach(async account => getOneOfWalletsDetails(account));
889
861
  },
890
862
  disconnectWallet: walletType => {
891
863
  set(state => ({
@@ -924,7 +896,38 @@ const useWalletsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.creat
924
896
  accounts: [],
925
897
  balances: [],
926
898
  selectedWallets: []
927
- }))
899
+ })),
900
+ getOneOfWalletsDetails: async account => {
901
+ const tokens = useMetaStore.getState().meta.tokens;
902
+ set(state => ({
903
+ balances: state.balances.map(balance => {
904
+ return balance.address === account.address && balance.chain === account.chain ? {
905
+ ...balance,
906
+ loading: true
907
+ } : balance;
908
+ })
909
+ }));
910
+ try {
911
+ const response = await httpService().getWalletsDetails([{
912
+ address: account.address,
913
+ blockchain: account.chain
914
+ }]);
915
+ const retrivedBalance = response.wallets[0];
916
+ if (retrivedBalance) {
917
+ set(state => ({
918
+ balances: state.balances.map(balance => {
919
+ return isAccountAndBalanceMatched(account, balance) ? makeBalanceFor(account, retrivedBalance, tokens) : balance;
920
+ })
921
+ }));
922
+ } else throw new Error('Wallet not found');
923
+ } catch (error) {
924
+ set(state => ({
925
+ balances: state.balances.map(balance => {
926
+ return isAccountAndBalanceMatched(account, balance) ? resetBalanceState(balance) : balance;
927
+ })
928
+ }));
929
+ }
930
+ }
928
931
  }))));
929
932
  useWalletsStore.subscribe(state => state.balances, balances => {
930
933
  useBestRouteStore.setState(_ref => {
@@ -975,6 +978,13 @@ const useBestRouteStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.cre
975
978
  })
976
979
  };
977
980
  }),
981
+ resetRoute: () => set(() => ({
982
+ loading: true,
983
+ error: '',
984
+ bestRoute: null,
985
+ outputAmount: null,
986
+ outputUsdValue: new BigNumber__default(0)
987
+ })),
978
988
  setFromChain: (chain, setDefaultToken) => {
979
989
  set(state => {
980
990
  if (state.fromChain?.name === chain?.name) return {};
@@ -1024,7 +1034,8 @@ const useBestRouteStore = /*#__PURE__*/createSelectors( /*#__PURE__*/zustand.cre
1024
1034
  ...(!amount && {
1025
1035
  outputAmount: new BigNumber__default(0),
1026
1036
  outputUsdValue: new BigNumber__default(0),
1027
- bestRoute: null
1037
+ bestRoute: null,
1038
+ error: ''
1028
1039
  }),
1029
1040
  ...(!!state.fromToken && {
1030
1041
  inputUsdValue: getUsdValue(state.fromToken, amount)
@@ -1089,7 +1100,8 @@ const bestRoute = (bestRouteStore, settingsStore) => {
1089
1100
  const {
1090
1101
  fromToken,
1091
1102
  toToken,
1092
- inputAmount
1103
+ inputAmount,
1104
+ resetRoute
1093
1105
  } = bestRouteStore.getState();
1094
1106
  const {
1095
1107
  slippage,
@@ -1102,12 +1114,9 @@ const bestRoute = (bestRouteStore, settingsStore) => {
1102
1114
  abortController = new AbortController();
1103
1115
  const userSlippage = !!customSlippage ? customSlippage : slippage;
1104
1116
  const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, [], [], disabledLiquiditySources, userSlippage, affiliateRef);
1105
- if (!bestRouteStore.getState().loading) bestRouteStore.setState({
1106
- loading: true,
1107
- bestRoute: null,
1108
- outputAmount: null,
1109
- outputUsdValue: new BigNumber__default(0)
1110
- });
1117
+ if (!bestRouteStore.getState().loading) {
1118
+ resetRoute();
1119
+ }
1111
1120
  httpService().getBestRoute(requestBody, {
1112
1121
  signal: abortController.signal
1113
1122
  }).then(res => {
@@ -1133,7 +1142,8 @@ const bestRoute = (bestRouteStore, settingsStore) => {
1133
1142
  fromToken,
1134
1143
  toToken,
1135
1144
  inputAmount,
1136
- inputUsdValue
1145
+ inputUsdValue,
1146
+ resetRoute
1137
1147
  } = useBestRouteStore.getState();
1138
1148
  if (!isPositiveNumber(inputAmount) || inputUsdValue.eq(0)) return bestRouteStore.setState({
1139
1149
  loading: false
@@ -1144,12 +1154,7 @@ const bestRoute = (bestRouteStore, settingsStore) => {
1144
1154
  outputAmount: new BigNumber__default(inputAmount),
1145
1155
  outputUsdValue: inputUsdValue
1146
1156
  });
1147
- if (!bestRouteStore.getState().loading) bestRouteStore.setState({
1148
- loading: true,
1149
- bestRoute: null,
1150
- outputAmount: null,
1151
- outputUsdValue: new BigNumber__default(0)
1152
- });
1157
+ if (!bestRouteStore.getState().loading) resetRoute();
1153
1158
  debouncedFetchBestRoute();
1154
1159
  };
1155
1160
  useBestRouteStore.subscribe(state => ({
@@ -1360,7 +1365,8 @@ function PercentageChange(props) {
1360
1365
  const Box = /*#__PURE__*/ui.styled('div', {
1361
1366
  display: 'flex',
1362
1367
  flexDirection: 'column',
1363
- width: '100%'
1368
+ width: '100%',
1369
+ overflow: 'hidden'
1364
1370
  });
1365
1371
  const Container = /*#__PURE__*/ui.styled('div', {
1366
1372
  boxSizing: 'border-box',
@@ -1586,7 +1592,8 @@ function BottomLogo() {
1586
1592
  t
1587
1593
  } = reactI18next.useTranslation();
1588
1594
  return React__default.createElement(Container$1, null, React__default.createElement(ui.Typography, {
1589
- variant: "caption"
1595
+ variant: "caption",
1596
+ color: '$neutrals600'
1590
1597
  }, t('Powered By')), React__default.createElement(StyledAnchor, {
1591
1598
  href: "https://rango.exchange",
1592
1599
  target: "_blank"
@@ -1754,7 +1761,7 @@ function Home() {
1754
1761
  return React__default.createElement(Container$2, null, React__default.createElement(ui.Header, {
1755
1762
  title: "SWAP",
1756
1763
  suffix: React__default.createElement(HeaderButtons, {
1757
- onClickRefresh: !!bestRoute ? fetchBestRoute : undefined
1764
+ onClickRefresh: !!bestRoute || bestRouteError ? fetchBestRoute : undefined
1758
1765
  })
1759
1766
  }), React__default.createElement(FromContainer, null, React__default.createElement(TokenInfo, {
1760
1767
  type: "From",
@@ -1871,7 +1878,8 @@ function useNavigateBack() {
1871
1878
  const Box$1 = /*#__PURE__*/ui.styled('div', {
1872
1879
  display: 'flex',
1873
1880
  flexDirection: 'column',
1874
- width: '100%'
1881
+ width: '100%',
1882
+ overflow: 'hidden'
1875
1883
  });
1876
1884
  const Container$3 = /*#__PURE__*/ui.styled('div', {
1877
1885
  boxSizing: 'border-box',
@@ -2025,7 +2033,9 @@ function RoutesOverview(props) {
2025
2033
  className: "routes"
2026
2034
  }, swaps?.map((swap, idx) => {
2027
2035
  const isLast = idx + 1 == swaps.length;
2028
- return React__default.createElement(React__default.Fragment, null, React__default.createElement("div", {
2036
+ return React__default.createElement(React__default.Fragment, {
2037
+ key: idx
2038
+ }, React__default.createElement("div", {
2029
2039
  className: "route"
2030
2040
  }, swap.from.symbol), React__default.createElement(ui.ChevronRightIcon, {
2031
2041
  size: 12
@@ -2215,6 +2225,8 @@ function MinRequiredSlippage(_ref) {
2215
2225
  }
2216
2226
 
2217
2227
  const List = /*#__PURE__*/ui.styled('ul', {
2228
+ padding: 0,
2229
+ margin: 0,
2218
2230
  variants: {
2219
2231
  showListStyle: {
2220
2232
  true: {
@@ -2358,8 +2370,8 @@ function ConfirmSwapPage() {
2358
2370
  const confirmDisabled = fetchingBestRoute || !requiredWallets(bestRoute).every(chain => selectedWallets.map(wallet => wallet.chain).includes(chain));
2359
2371
  const firstStep = bestRoute?.result?.swaps[0];
2360
2372
  const lastStep = bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1];
2361
- const fromAmount = decimalNumber(firstStep?.fromAmount, 3);
2362
- const toAmount = decimalNumber(lastStep?.toAmount, 3);
2373
+ const fromAmount = numberToString(firstStep?.fromAmount, 4, 6);
2374
+ const toAmount = numberToString(lastStep?.toAmount, 4, 6);
2363
2375
  React.useEffect(() => {
2364
2376
  initSelectedWallets();
2365
2377
  }, []);
@@ -2489,7 +2501,8 @@ function HistoryPage() {
2489
2501
  navigateBackFrom
2490
2502
  } = useNavigateBack();
2491
2503
  const {
2492
- manager
2504
+ manager,
2505
+ state
2493
2506
  } = queueManagerReact.useManager();
2494
2507
  const pendingSwaps = getPendingSwaps(manager).map(_ref => {
2495
2508
  let {
@@ -2497,7 +2510,7 @@ function HistoryPage() {
2497
2510
  } = _ref;
2498
2511
  return swap;
2499
2512
  });
2500
- const loading = !manager?.isLoaded();
2513
+ const loading = !state.loadedFromPersistor;
2501
2514
  return React__default.createElement(ui.History, {
2502
2515
  list: pendingSwaps,
2503
2516
  groupBy: groupSwapsByDate,
@@ -2752,24 +2765,6 @@ function WalletsPage(_ref) {
2752
2765
  }))))));
2753
2766
  }
2754
2767
 
2755
- function useCopyToClipboard(resetInterval) {
2756
- const [isCopied, setCopied] = React__default.useState(false);
2757
- const handleCopy = React__default.useCallback(text => {
2758
- copy(text.toString());
2759
- setCopied(true);
2760
- }, []);
2761
- React__default.useEffect(() => {
2762
- let timeout;
2763
- if (isCopied && resetInterval) {
2764
- timeout = setTimeout(() => setCopied(false), resetInterval);
2765
- }
2766
- return () => {
2767
- clearTimeout(timeout);
2768
- };
2769
- }, [isCopied, resetInterval]);
2770
- return [isCopied, handleCopy];
2771
- }
2772
-
2773
2768
  function timeSince(timeMillis) {
2774
2769
  const seconds = Math.floor((new Date().getTime() - timeMillis) / 1000);
2775
2770
  let intervalType;
@@ -2848,9 +2843,10 @@ function SwapDetailsPage() {
2848
2843
  const {
2849
2844
  navigateBackFrom
2850
2845
  } = useNavigateBack();
2851
- const [isCopied, handleCopy] = useCopyToClipboard(2000);
2846
+ const [isCopied, handleCopy] = ui.useCopyToClipboard(2000);
2852
2847
  const {
2853
- manager
2848
+ manager,
2849
+ state
2854
2850
  } = queueManagerReact.useManager();
2855
2851
  const pendingSwaps = getPendingSwaps(manager);
2856
2852
  const selectedSwap = pendingSwaps.find(_ref => {
@@ -2864,7 +2860,7 @@ function SwapDetailsPage() {
2864
2860
  if (swap) queueManagerRangoPreset.cancelSwap(swap);
2865
2861
  };
2866
2862
  const swap = selectedSwap?.swap;
2867
- const loading = !manager?.isLoaded();
2863
+ const loading = !state.loadedFromPersistor;
2868
2864
  if (!swap) return React__default.createElement(SwapDetailsPlaceholder, {
2869
2865
  requestId: selectedSwapRequestId || '',
2870
2866
  loading: loading,
@@ -3013,7 +3009,9 @@ const Header = /*#__PURE__*/ui.styled('div', {
3013
3009
  const WalletImageContainer = /*#__PURE__*/ui.styled('div', {
3014
3010
  marginLeft: -15,
3015
3011
  marginRight: '$6',
3016
- borderRadius: '99999px'
3012
+ '& img': {
3013
+ borderRadius: '50%'
3014
+ }
3017
3015
  });
3018
3016
  function Layout(_ref) {
3019
3017
  let {
@@ -3090,28 +3088,6 @@ function Layout(_ref) {
3090
3088
  }));
3091
3089
  }
3092
3090
 
3093
- const globalStyles = /*#__PURE__*/ui.globalCss({
3094
- '*': {
3095
- boxSizing: 'border-box',
3096
- margin: 0,
3097
- padding: 0,
3098
- listStyleType: 'none',
3099
- '&::-webkit-scrollbar': {
3100
- width: '$8',
3101
- height: '$8'
3102
- },
3103
- '&::-webkit-scrollbar-thumb': {
3104
- backgroundColor: '$neutrals400',
3105
- borderRadius: '$10'
3106
- },
3107
- '&::-webkit-scrollbar-thumb:hover': {
3108
- backgroundColor: '$neutrals500'
3109
- },
3110
- '&::-webkit-scrollbar-track': {
3111
- backgroundColor: '$neutrals300'
3112
- }
3113
- }
3114
- });
3115
3091
  const globalFont = fontFamily => ui.globalCss({
3116
3092
  '@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')"],
3117
3093
  body: {
@@ -3342,6 +3318,8 @@ function QueueManager(props) {
3342
3318
  API_KEY: getConfig('API_KEY')
3343
3319
  });
3344
3320
  }, []);
3321
+ const getOneOfWalletsDetails = useWalletsStore.use.getOneOfWalletsDetails();
3322
+ const accounts = useWalletsStore.use.accounts();
3345
3323
  const {
3346
3324
  blockchains
3347
3325
  } = useMetaStore.use.meta();
@@ -3368,6 +3346,17 @@ function QueueManager(props) {
3368
3346
  return walletAndSupportedChainsNames(supportedChains);
3369
3347
  };
3370
3348
  const allProviders = providers();
3349
+ const notifier = data => {
3350
+ const lastStep = data.swap?.steps[data.swap.steps.length - 1];
3351
+ const outputAmount = data.step?.outputAmount || '';
3352
+ const step = data.step || lastStep;
3353
+ if (data.eventType === 'task_completed' || data.eventType === 'step_completed_with_output' && lastStep?.id !== data.step?.id || !!outputAmount) {
3354
+ const fromAccount = accounts.find(account => account.chain === step?.fromBlockchain);
3355
+ const toAccount = step?.fromBlockchain !== step?.toBlockchain && accounts.find(account => account.chain === step?.toBlockchain);
3356
+ fromAccount && getOneOfWalletsDetails(fromAccount);
3357
+ toAccount && getOneOfWalletsDetails(toAccount);
3358
+ }
3359
+ };
3371
3360
  const context = {
3372
3361
  meta: {
3373
3362
  blockchains: allBlockchains,
@@ -3383,9 +3372,7 @@ function QueueManager(props) {
3383
3372
  switchNetwork,
3384
3373
  connect,
3385
3374
  state,
3386
- notifier: message => {
3387
- console.log('[notifier]', message);
3388
- }
3375
+ notifier
3389
3376
  };
3390
3377
  return React__default.createElement(queueManagerReact.Provider
3391
3378
  //@ts-ignore
@@ -3404,7 +3391,6 @@ const Widget = _ref => {
3404
3391
  let {
3405
3392
  config
3406
3393
  } = _ref;
3407
- globalStyles();
3408
3394
  globalFont(config?.theme?.fontFamily || 'Roboto');
3409
3395
  const {
3410
3396
  activeTheme
@@ -3469,7 +3455,6 @@ const Widget = _ref => {
3469
3455
  providers: providers,
3470
3456
  onUpdateState: onUpdateState
3471
3457
  }, React__default.createElement("div", {
3472
- id: "pageContainer",
3473
3458
  className: activeTheme
3474
3459
  }, React__default.createElement(QueueManager, null, React__default.createElement(ui.SwapContainer, {
3475
3460
  fixedHeight: currentPage !== navigationRoutes.home