@rango-dev/widget-embedded 0.1.13-next.0 → 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 (43) 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 +85 -102
  18. package/dist/widget-embedded.cjs.development.js.map +1 -1
  19. package/dist/widget-embedded.cjs.production.min.js +85 -102
  20. package/dist/widget-embedded.cjs.production.min.js.map +1 -1
  21. package/dist/widget-embedded.esm.js +85 -102
  22. package/dist/widget-embedded.esm.js.map +1 -1
  23. package/package.json +3 -3
  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/Home.tsx +1 -1
  37. package/src/pages/SwapDetailsPage.tsx +1 -2
  38. package/src/store/bestRoute.ts +18 -16
  39. package/src/store/wallets.ts +38 -28
  40. package/src/utils/numbers.ts +2 -5
  41. package/dist/hooks/useCopyToClipboard.d.ts +0 -2
  42. package/dist/hooks/useCopyToClipboard.d.ts.map +0 -1
  43. 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
  }, []);
@@ -2745,24 +2757,6 @@ function WalletsPage(_ref) {
2745
2757
  }))))));
2746
2758
  }
2747
2759
 
2748
- function useCopyToClipboard(resetInterval) {
2749
- const [isCopied, setCopied] = React.useState(false);
2750
- const handleCopy = React.useCallback(text => {
2751
- copy(text.toString());
2752
- setCopied(true);
2753
- }, []);
2754
- React.useEffect(() => {
2755
- let timeout;
2756
- if (isCopied && resetInterval) {
2757
- timeout = setTimeout(() => setCopied(false), resetInterval);
2758
- }
2759
- return () => {
2760
- clearTimeout(timeout);
2761
- };
2762
- }, [isCopied, resetInterval]);
2763
- return [isCopied, handleCopy];
2764
- }
2765
-
2766
2760
  function timeSince(timeMillis) {
2767
2761
  const seconds = Math.floor((new Date().getTime() - timeMillis) / 1000);
2768
2762
  let intervalType;
@@ -3007,7 +3001,9 @@ const Header = /*#__PURE__*/styled('div', {
3007
3001
  const WalletImageContainer = /*#__PURE__*/styled('div', {
3008
3002
  marginLeft: -15,
3009
3003
  marginRight: '$6',
3010
- borderRadius: '99999px'
3004
+ '& img': {
3005
+ borderRadius: '50%'
3006
+ }
3011
3007
  });
3012
3008
  function Layout(_ref) {
3013
3009
  let {
@@ -3084,28 +3080,6 @@ function Layout(_ref) {
3084
3080
  }));
3085
3081
  }
3086
3082
 
3087
- const globalStyles = /*#__PURE__*/globalCss({
3088
- '*': {
3089
- boxSizing: 'border-box',
3090
- margin: 0,
3091
- padding: 0,
3092
- listStyleType: 'none',
3093
- '&::-webkit-scrollbar': {
3094
- width: '$8',
3095
- height: '$8'
3096
- },
3097
- '&::-webkit-scrollbar-thumb': {
3098
- backgroundColor: '$neutrals400',
3099
- borderRadius: '$10'
3100
- },
3101
- '&::-webkit-scrollbar-thumb:hover': {
3102
- backgroundColor: '$neutrals500'
3103
- },
3104
- '&::-webkit-scrollbar-track': {
3105
- backgroundColor: '$neutrals300'
3106
- }
3107
- }
3108
- });
3109
3083
  const globalFont = fontFamily => globalCss({
3110
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')"],
3111
3085
  body: {
@@ -3336,6 +3310,8 @@ function QueueManager(props) {
3336
3310
  API_KEY: getConfig('API_KEY')
3337
3311
  });
3338
3312
  }, []);
3313
+ const getOneOfWalletsDetails = useWalletsStore.use.getOneOfWalletsDetails();
3314
+ const accounts = useWalletsStore.use.accounts();
3339
3315
  const {
3340
3316
  blockchains
3341
3317
  } = useMetaStore.use.meta();
@@ -3362,6 +3338,17 @@ function QueueManager(props) {
3362
3338
  return walletAndSupportedChainsNames(supportedChains);
3363
3339
  };
3364
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
+ };
3365
3352
  const context = {
3366
3353
  meta: {
3367
3354
  blockchains: allBlockchains,
@@ -3377,9 +3364,7 @@ function QueueManager(props) {
3377
3364
  switchNetwork,
3378
3365
  connect,
3379
3366
  state,
3380
- notifier: message => {
3381
- console.log('[notifier]', message);
3382
- }
3367
+ notifier
3383
3368
  };
3384
3369
  return React.createElement(Provider
3385
3370
  //@ts-ignore
@@ -3398,7 +3383,6 @@ const Widget = _ref => {
3398
3383
  let {
3399
3384
  config
3400
3385
  } = _ref;
3401
- globalStyles();
3402
3386
  globalFont(config?.theme?.fontFamily || 'Roboto');
3403
3387
  const {
3404
3388
  activeTheme
@@ -3463,7 +3447,6 @@ const Widget = _ref => {
3463
3447
  providers: providers,
3464
3448
  onUpdateState: onUpdateState
3465
3449
  }, React.createElement("div", {
3466
- id: "pageContainer",
3467
3450
  className: activeTheme
3468
3451
  }, React.createElement(QueueManager, null, React.createElement(SwapContainer, {
3469
3452
  fixedHeight: currentPage !== navigationRoutes.home