@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.1.12",
3
+ "version": "0.1.13-next.4",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -28,12 +28,12 @@
28
28
  "trailingComma": "es5"
29
29
  },
30
30
  "dependencies": {
31
- "@rango-dev/provider-all": "^0.1.11",
32
- "@rango-dev/queue-manager-core": "^0.1.11",
33
- "@rango-dev/queue-manager-rango-preset": "^0.1.11",
34
- "@rango-dev/queue-manager-react": "^0.1.10",
35
- "@rango-dev/ui": "^0.1.11",
36
- "@rango-dev/wallets-core": "^0.1.11",
31
+ "@rango-dev/provider-all": "^0.1.12",
32
+ "@rango-dev/queue-manager-core": "^0.1.12-next.0",
33
+ "@rango-dev/queue-manager-rango-preset": "^0.1.12-next.4",
34
+ "@rango-dev/queue-manager-react": "^0.1.11-next.0",
35
+ "@rango-dev/ui": "^0.1.13-next.2",
36
+ "@rango-dev/wallets-core": "^0.1.12",
37
37
  "@rango-dev/wallets-shared": "^0.1.11",
38
38
  "bignumber.js": "^9.1.1",
39
39
  "copy-to-clipboard": "^3.3.3",
package/src/App.tsx CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  } from './utils/wallets';
14
14
  import { useWalletsStore } from './store/wallets';
15
15
  import { Layout } from './components/Layout';
16
- import { globalFont, globalStyles } from './globalStyles';
16
+ import { globalFont } from './globalStyles';
17
17
  import { useTheme } from './hooks/useTheme';
18
18
  import QueueManager from './QueueManager';
19
19
  import { isEvmBlockchain } from 'rango-sdk';
@@ -30,7 +30,6 @@ export type WidgetProps = {
30
30
  };
31
31
 
32
32
  export function App({ config }: WidgetProps) {
33
- globalStyles();
34
33
  globalFont(config?.theme?.fontFamily || 'Roboto');
35
34
  const { activeTheme } = useTheme({ ...config?.theme });
36
35
  useMemo(() => {
@@ -4,6 +4,7 @@ import {
4
4
  makeQueueDefinition,
5
5
  SwapQueueContext,
6
6
  checkWaitingForNetworkChange,
7
+ SwapProgressNotification,
7
8
  } from '@rango-dev/queue-manager-rango-preset';
8
9
  import { useWallets } from '@rango-dev/wallets-core';
9
10
  import {
@@ -32,6 +33,9 @@ function QueueManager(props: PropsWithChildren<{}>) {
32
33
  API_KEY: getConfig('API_KEY'),
33
34
  });
34
35
  }, []);
36
+ const getOneOfWalletsDetails = useWalletsStore.use.getOneOfWalletsDetails();
37
+ const accounts = useWalletsStore.use.accounts();
38
+
35
39
  const { blockchains } = useMetaStore.use.meta();
36
40
  const balances = useWalletsStore.use.balances();
37
41
 
@@ -64,6 +68,29 @@ function QueueManager(props: PropsWithChildren<{}>) {
64
68
  return walletAndSupportedChainsNames(supportedChains);
65
69
  };
66
70
  const allProviders = providers();
71
+ const notifier = (data: SwapProgressNotification) => {
72
+ const lastStep = data.swap?.steps[data.swap.steps.length - 1];
73
+ const outputAmount = data.step?.outputAmount || '';
74
+ const step = data.step || lastStep;
75
+
76
+ if (
77
+ data.eventType === 'task_completed' ||
78
+ (data.eventType === 'step_completed_with_output' &&
79
+ lastStep?.id !== data.step?.id) ||
80
+ !!outputAmount
81
+ ) {
82
+ const fromAccount = accounts.find(
83
+ (account) => account.chain === step?.fromBlockchain
84
+ );
85
+ const toAccount =
86
+ step?.fromBlockchain !== step?.toBlockchain &&
87
+ accounts.find((account) => account.chain === step?.toBlockchain);
88
+
89
+ fromAccount && getOneOfWalletsDetails(fromAccount);
90
+ toAccount && getOneOfWalletsDetails(toAccount);
91
+ }
92
+ };
93
+
67
94
  const context: SwapQueueContext = {
68
95
  meta: {
69
96
  blockchains: allBlockchains,
@@ -80,9 +107,7 @@ function QueueManager(props: PropsWithChildren<{}>) {
80
107
  switchNetwork,
81
108
  connect,
82
109
  state,
83
- notifier: (message) => {
84
- console.log('[notifier]', message);
85
- },
110
+ notifier,
86
111
  };
87
112
 
88
113
  return (
@@ -29,7 +29,7 @@ export function BottomLogo() {
29
29
 
30
30
  return (
31
31
  <Container>
32
- <Typography variant="caption">{t('Powered By')}</Typography>
32
+ <Typography variant="caption" color='$neutrals600'>{t('Powered By')}</Typography>
33
33
  <StyledAnchor href="https://rango.exchange" target="_blank">
34
34
  <Logo xmlns="http://www.w3.org/2000/svg" viewBox="0 0 33.68 29">
35
35
  <defs></defs>
@@ -37,7 +37,9 @@ const Header = styled('div', {
37
37
  const WalletImageContainer = styled('div', {
38
38
  marginLeft: -15,
39
39
  marginRight: '$6',
40
- borderRadius: '99999px',
40
+ '& img': {
41
+ borderRadius: '50%',
42
+ }
41
43
  });
42
44
 
43
45
  export type LayoutProps = {
@@ -39,11 +39,11 @@ function RoutesOverview(props: PropTypes) {
39
39
  {swaps?.map((swap, idx) => {
40
40
  const isLast = idx + 1 == swaps.length;
41
41
  return (
42
- <>
42
+ <React.Fragment key={idx}>
43
43
  <div className="route">{swap.from.symbol}</div>
44
44
  <ChevronRightIcon size={12} />
45
45
  {isLast ? <div className="route">{swap.to.symbol}</div> : null}
46
- </>
46
+ </React.Fragment>
47
47
  );
48
48
  })}
49
49
  </div>
@@ -37,6 +37,7 @@ const Box = styled('div', {
37
37
  display: 'flex',
38
38
  flexDirection: 'column',
39
39
  width: '100%',
40
+ overflow: 'hidden'
40
41
  });
41
42
 
42
43
  const Container = styled('div', {
@@ -11,6 +11,7 @@ const Box = styled('div', {
11
11
  display: 'flex',
12
12
  flexDirection: 'column',
13
13
  width: '100%',
14
+ overflow: 'hidden',
14
15
  });
15
16
 
16
17
  const Container = styled('div', {
@@ -6,6 +6,8 @@ interface PropTypes {
6
6
  }
7
7
 
8
8
  const List = styled('ul', {
9
+ padding: 0,
10
+ margin: 0,
9
11
  variants: {
10
12
  showListStyle: {
11
13
  true: { paddingLeft: '$24' },
@@ -1,24 +1,5 @@
1
1
  import { globalCss } from '@rango-dev/ui';
2
2
 
3
- export const globalStyles = globalCss({
4
- '*': {
5
- boxSizing: 'border-box',
6
- margin: 0,
7
- padding: 0,
8
- listStyleType: 'none',
9
- '&::-webkit-scrollbar': { width: '$8', height: '$8' },
10
- '&::-webkit-scrollbar-thumb': {
11
- backgroundColor: '$neutrals400',
12
- borderRadius: '$10',
13
- },
14
- '&::-webkit-scrollbar-thumb:hover': {
15
- backgroundColor: '$neutrals500',
16
- },
17
- '&::-webkit-scrollbar-track': {
18
- backgroundColor: '$neutrals300',
19
- },
20
- },
21
- });
22
3
  export const globalFont = (fontFamily: string) =>
23
4
  globalCss({
24
5
  '@import': [
package/src/index.tsx CHANGED
@@ -11,4 +11,4 @@ root.render(
11
11
  </BrowserRouter>
12
12
  );
13
13
 
14
- export { Widget } from './lib';
14
+ export { Widget } from './lib';
package/src/lib.tsx CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  } from './utils/wallets';
13
13
  import { useWalletsStore } from './store/wallets';
14
14
  import { Layout } from './components/Layout';
15
- import { globalFont, globalStyles } from './globalStyles';
15
+ import { globalFont } from './globalStyles';
16
16
  import { useTheme } from './hooks/useTheme';
17
17
  import { isEvmBlockchain } from 'rango-sdk';
18
18
  import { WidgetTheme, WidgetConfig, WidgetColors, BlockchainAndTokenConfig } from './types';
@@ -31,7 +31,6 @@ export type WidgetProps = {
31
31
  };
32
32
 
33
33
  export const Widget: React.FC<WidgetProps> = ({ config }) => {
34
- globalStyles();
35
34
  globalFont(config?.theme?.fontFamily || 'Roboto');
36
35
 
37
36
  const { activeTheme } = useTheme({ ...config?.theme });
@@ -115,7 +114,7 @@ export const Widget: React.FC<WidgetProps> = ({ config }) => {
115
114
  providers={providers}
116
115
  onUpdateState={onUpdateState}
117
116
  >
118
- <div id="pageContainer" className={activeTheme}>
117
+ <div className={activeTheme}>
119
118
  <QueueManager>
120
119
  <SwapContainer
121
120
  fixedHeight={currentPage !== navigationRoutes.home}>
@@ -11,7 +11,7 @@ import {
11
11
  isExperimentalChain,
12
12
  } from '../utils/wallets';
13
13
  import { getTotalFeeInUsd, requiredWallets } from '../utils/swap';
14
- import { decimalNumber, numberToString } from '../utils/numbers';
14
+ import { numberToString } from '../utils/numbers';
15
15
  import { useMetaStore } from '../store/meta';
16
16
  import { Network, WalletType } from '@rango-dev/wallets-shared';
17
17
  import { useNavigateBack } from '../hooks/useNavigateBack';
@@ -74,8 +74,8 @@ export function ConfirmSwapPage() {
74
74
  const lastStep =
75
75
  bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1];
76
76
 
77
- const fromAmount = decimalNumber(firstStep?.fromAmount, 3);
78
- const toAmount = decimalNumber(lastStep?.toAmount, 3);
77
+ const fromAmount = numberToString(firstStep?.fromAmount, 4, 6);
78
+ const toAmount = numberToString(lastStep?.toAmount, 4, 6);
79
79
  useEffect(() => {
80
80
  initSelectedWallets();
81
81
  }, []);
@@ -12,10 +12,10 @@ export function HistoryPage() {
12
12
  const setSelectedSwap = useUiStore.use.setSelectedSwap();
13
13
  const navigate = useNavigate();
14
14
  const { navigateBackFrom } = useNavigateBack();
15
- const { manager } = useManager();
15
+ const { manager, state } = useManager();
16
16
  const pendingSwaps = getPendingSwaps(manager).map(({ swap }) => swap);
17
17
 
18
- const loading = !manager?.isLoaded();
18
+ const loading = !state.loadedFromPersistor;
19
19
 
20
20
  return (
21
21
  <History
@@ -139,7 +139,7 @@ export function Home() {
139
139
  title="SWAP"
140
140
  suffix={
141
141
  <HeaderButtons
142
- onClickRefresh={!!bestRoute ? fetchBestRoute : undefined}
142
+ onClickRefresh={!!bestRoute || bestRouteError ? fetchBestRoute : undefined}
143
143
  />
144
144
  }
145
145
  />
@@ -1,10 +1,9 @@
1
1
  import React from 'react';
2
2
  import { navigationRoutes } from '../constants/navigationRoutes';
3
- import useCopyToClipboard from '../hooks/useCopyToClipboard';
4
3
  import { useManager } from '@rango-dev/queue-manager-react';
5
4
  import { useNavigateBack } from '../hooks/useNavigateBack';
6
5
  import { getPendingSwaps } from '../utils/queue';
7
- import { SwapHistory } from '@rango-dev/ui';
6
+ import { SwapHistory, useCopyToClipboard } from '@rango-dev/ui';
8
7
  import { useUiStore } from '../store/ui';
9
8
  import {
10
9
  cancelSwap,
@@ -37,7 +36,7 @@ export function SwapDetailsPage() {
37
36
  const navigate = useNavigate();
38
37
  const { navigateBackFrom } = useNavigateBack();
39
38
  const [isCopied, handleCopy] = useCopyToClipboard(2000);
40
- const { manager } = useManager();
39
+ const { manager, state } = useManager();
41
40
 
42
41
  const pendingSwaps = getPendingSwaps(manager);
43
42
  const selectedSwap = pendingSwaps.find(
@@ -49,7 +48,7 @@ export function SwapDetailsPage() {
49
48
  if (swap) cancelSwap(swap);
50
49
  };
51
50
  const swap = selectedSwap?.swap;
52
- const loading = !manager?.isLoaded();
51
+ const loading = !state.loadedFromPersistor;
53
52
 
54
53
  if (!swap)
55
54
  return (
@@ -40,6 +40,7 @@ export interface RouteState {
40
40
  error: string;
41
41
  sourceTokens: Token[];
42
42
  destinationTokens: Token[];
43
+ resetRoute: () => void;
43
44
  setFromChain: (
44
45
  chain: BlockchainMeta | null,
45
46
  setDefaultToken?: boolean
@@ -92,6 +93,14 @@ export const useBestRouteStore = createSelectors(
92
93
  }),
93
94
  };
94
95
  }),
96
+ resetRoute: () =>
97
+ set(() => ({
98
+ loading: true,
99
+ error: '',
100
+ bestRoute: null,
101
+ outputAmount: null,
102
+ outputUsdValue: new BigNumber(0),
103
+ })),
95
104
  setFromChain: (chain, setDefaultToken) => {
96
105
  set((state) => {
97
106
  if (state.fromChain?.name === chain?.name) return {};
@@ -155,6 +164,7 @@ export const useBestRouteStore = createSelectors(
155
164
  outputAmount: new BigNumber(0),
156
165
  outputUsdValue: new BigNumber(0),
157
166
  bestRoute: null,
167
+ error: '',
158
168
  }),
159
169
  ...(!!state.fromToken && {
160
170
  inputUsdValue: getUsdValue(state.fromToken, amount),
@@ -250,7 +260,8 @@ const bestRoute = (
250
260
  ) => {
251
261
  let abortController: AbortController | null = null;
252
262
  const fetchBestRoute = () => {
253
- const { fromToken, toToken, inputAmount } = bestRouteStore.getState();
263
+ const { fromToken, toToken, inputAmount, resetRoute } =
264
+ bestRouteStore.getState();
254
265
  const { slippage, customSlippage, disabledLiquiditySources, affiliateRef } =
255
266
  settingsStore.getState();
256
267
  if (!fromToken || !toToken || !isPositiveNumber(inputAmount)) return;
@@ -267,13 +278,10 @@ const bestRoute = (
267
278
  userSlippage,
268
279
  affiliateRef
269
280
  );
270
- if (!bestRouteStore.getState().loading)
271
- bestRouteStore.setState({
272
- loading: true,
273
- bestRoute: null,
274
- outputAmount: null,
275
- outputUsdValue: new BigNumber(0),
276
- });
281
+
282
+ if (!bestRouteStore.getState().loading) {
283
+ resetRoute();
284
+ }
277
285
  httpService()
278
286
  .getBestRoute(requestBody, {
279
287
  signal: abortController.signal,
@@ -296,7 +304,7 @@ const bestRoute = (
296
304
  const debouncedFetchBestRoute = debounce(fetchBestRoute, 600);
297
305
 
298
306
  const bestRouteParamsListener = () => {
299
- const { fromToken, toToken, inputAmount, inputUsdValue } =
307
+ const { fromToken, toToken, inputAmount, inputUsdValue, resetRoute } =
300
308
  useBestRouteStore.getState();
301
309
  if (!isPositiveNumber(inputAmount) || inputUsdValue.eq(0))
302
310
  return bestRouteStore.setState({ loading: false });
@@ -309,13 +317,7 @@ const bestRoute = (
309
317
  outputUsdValue: inputUsdValue,
310
318
  });
311
319
 
312
- if (!bestRouteStore.getState().loading)
313
- bestRouteStore.setState({
314
- loading: true,
315
- bestRoute: null,
316
- outputAmount: null,
317
- outputUsdValue: new BigNumber(0),
318
- });
320
+ if (!bestRouteStore.getState().loading) resetRoute();
319
321
  debouncedFetchBestRoute();
320
322
  };
321
323
 
@@ -54,17 +54,17 @@ interface WalletsStore {
54
54
  initSelectedWallets: () => void;
55
55
  setSelectedWallet: (wallet: SelectableWallet) => void;
56
56
  clearConnectedWallet: () => void;
57
+ getOneOfWalletsDetails: (account: Account) => void;
57
58
  }
58
59
 
59
60
  export const useWalletsStore = createSelectors(
60
61
  create<WalletsStore>()(
61
- subscribeWithSelector((set) => ({
62
+ subscribeWithSelector((set, get) => ({
62
63
  accounts: [],
63
64
  balances: [],
64
65
  selectedWallets: [],
65
66
  connectWallet: (accounts) => {
66
- const tokens = useMetaStore.getState().meta.tokens;
67
-
67
+ const getOneOfWalletsDetails = get().getOneOfWalletsDetails;
68
68
  set((state) => ({
69
69
  accounts: state.accounts.concat(accounts),
70
70
  balances: state.balances.concat(
@@ -79,31 +79,7 @@ export const useWalletsStore = createSelectors(
79
79
  }))
80
80
  ),
81
81
  }));
82
- accounts.forEach(async (account) => {
83
- try {
84
- const response = await httpService().getWalletsDetails([
85
- { address: account.address, blockchain: account.chain },
86
- ]);
87
- const retrivedBalance = response.wallets[0];
88
- if (retrivedBalance) {
89
- set((state) => ({
90
- balances: state.balances.map((balance) => {
91
- return isAccountAndBalanceMatched(account, balance)
92
- ? makeBalanceFor(account, retrivedBalance, tokens)
93
- : balance;
94
- }),
95
- }));
96
- } else throw new Error('Wallet not found');
97
- } catch (error) {
98
- set((state) => ({
99
- balances: state.balances.map((balance) => {
100
- return isAccountAndBalanceMatched(account, balance)
101
- ? resetBalanceState(balance)
102
- : balance;
103
- }),
104
- }));
105
- }
106
- });
82
+ accounts.forEach(async (account) => getOneOfWalletsDetails(account));
107
83
  },
108
84
  disconnectWallet: (walletType) => {
109
85
  set((state) => ({
@@ -162,6 +138,40 @@ export const useWalletsStore = createSelectors(
162
138
  balances: [],
163
139
  selectedWallets: [],
164
140
  })),
141
+ getOneOfWalletsDetails: async (account: Account) => {
142
+ const tokens = useMetaStore.getState().meta.tokens;
143
+ set((state) => ({
144
+ balances: state.balances.map((balance) => {
145
+ return balance.address === account.address &&
146
+ balance.chain === account.chain
147
+ ? { ...balance, loading: true }
148
+ : balance;
149
+ }),
150
+ }));
151
+ try {
152
+ const response = await httpService().getWalletsDetails([
153
+ { address: account.address, blockchain: account.chain },
154
+ ]);
155
+ const retrivedBalance = response.wallets[0];
156
+ if (retrivedBalance) {
157
+ set((state) => ({
158
+ balances: state.balances.map((balance) => {
159
+ return isAccountAndBalanceMatched(account, balance)
160
+ ? makeBalanceFor(account, retrivedBalance, tokens)
161
+ : balance;
162
+ }),
163
+ }));
164
+ } else throw new Error('Wallet not found');
165
+ } catch (error) {
166
+ set((state) => ({
167
+ balances: state.balances.map((balance) => {
168
+ return isAccountAndBalanceMatched(account, balance)
169
+ ? resetBalanceState(balance)
170
+ : balance;
171
+ }),
172
+ }));
173
+ }
174
+ },
165
175
  }))
166
176
  )
167
177
  );
@@ -12,11 +12,11 @@ export const secondsToString = (s: number): string => {
12
12
  };
13
13
 
14
14
  export const numberToString = (
15
- number: BigNumber | string | null,
15
+ number: BigNumber | string | null | undefined,
16
16
  minDecimals: number | null = null,
17
17
  maxDecimals: number | null = null
18
18
  ): string => {
19
- if (number === null) return '';
19
+ if (number === null || number === undefined) return '';
20
20
  if (number === '') return '';
21
21
  const n = new BigNumber(number);
22
22
  const roundingMode = 1;
@@ -126,9 +126,6 @@ export const rawFees = (data: BestRouteResponse): string =>
126
126
  .reduce((partialSum, a) => partialSum + parseFloat(a.fee.amount), 0)
127
127
  .toFixed(3);
128
128
 
129
- export const decimalNumber = (number = '0', toFixed: number) =>
130
- parseFloat(number).toFixed(toFixed);
131
-
132
129
  export const containsText = (text: string, searchText: string) =>
133
130
  text.toLowerCase().indexOf(searchText.toLowerCase()) > -1;
134
131
 
@@ -1,2 +0,0 @@
1
- export default function useCopyToClipboard(resetInterval?: number): readonly [boolean, (text: string | number) => void];
2
- //# sourceMappingURL=useCopyToClipboard.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useCopyToClipboard.d.ts","sourceRoot":"","sources":["../src/hooks/useCopyToClipboard.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,aAAa,CAAC,EAAE,MAAM,6BAGnB,MAAM,GAAG,MAAM,WAgB5D"}
@@ -1,23 +0,0 @@
1
- import React from 'react';
2
- import copy from 'copy-to-clipboard';
3
-
4
- export default function useCopyToClipboard(resetInterval?: number) {
5
- const [isCopied, setCopied] = React.useState(false);
6
-
7
- const handleCopy = React.useCallback((text: string | number) => {
8
- copy(text.toString());
9
- setCopied(true);
10
- }, []);
11
-
12
- React.useEffect(() => {
13
- let timeout: NodeJS.Timeout;
14
- if (isCopied && resetInterval) {
15
- timeout = setTimeout(() => setCopied(false), resetInterval);
16
- }
17
- return () => {
18
- clearTimeout(timeout);
19
- };
20
- }, [isCopied, resetInterval]);
21
-
22
- return [isCopied, handleCopy] as const;
23
- }