@rango-dev/widget-embedded 0.1.10-next.99 → 0.1.10
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.
- package/dist/App.d.ts.map +1 -1
- package/dist/QueueManager.d.ts.map +1 -1
- package/dist/components/AppRouter.d.ts +6 -1
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/AppRoutes.d.ts.map +1 -1
- package/dist/components/HeaderButtons.d.ts +4 -1
- package/dist/components/HeaderButtons.d.ts.map +1 -1
- package/dist/components/Layout.d.ts.map +1 -1
- package/dist/components/SwapDetailsPlaceholder.d.ts +9 -0
- package/dist/components/SwapDetailsPlaceholder.d.ts.map +1 -0
- package/dist/components/TokenPreview.d.ts +1 -1
- package/dist/components/TokenPreview.d.ts.map +1 -1
- package/dist/components/UpdateUrl.d.ts.map +1 -1
- package/dist/components/warnings/BalanceWarnings.d.ts.map +1 -1
- package/dist/components/warnings/MinRequiredSlippage.d.ts +1 -1
- package/dist/components/warnings/MinRequiredSlippage.d.ts.map +1 -1
- package/dist/constants/navigationRoutes.d.ts +0 -1
- package/dist/constants/navigationRoutes.d.ts.map +1 -1
- package/dist/globalStyles.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap.d.ts.map +1 -1
- package/dist/lib.d.ts.map +1 -1
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/HistoryPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/LiquiditySourcesPage.d.ts.map +1 -1
- package/dist/pages/SelectTokenPage.d.ts.map +1 -1
- package/dist/pages/SettingsPage.d.ts.map +1 -1
- package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts +1 -0
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/store/bestRoute.d.ts +2 -0
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/store/ui.d.ts.map +1 -1
- package/dist/store/wallets.d.ts +14 -0
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/routing.d.ts +1 -1
- package/dist/types/swap.d.ts +6 -0
- package/dist/types/swap.d.ts.map +1 -1
- package/dist/utils/common.d.ts +1 -0
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/date.d.ts +3 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/routing.d.ts +1 -0
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +16 -5
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/time.d.ts +4 -0
- package/dist/utils/time.d.ts.map +1 -0
- package/dist/utils/wallets.d.ts +1 -1
- package/dist/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +1048 -705
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +1048 -705
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +1057 -714
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +12 -11
- package/readme.md +1 -2
- package/src/App.tsx +30 -5
- package/src/QueueManager.tsx +5 -2
- package/src/components/AppRouter.tsx +24 -13
- package/src/components/AppRoutes.tsx +15 -12
- package/src/components/HeaderButtons.tsx +9 -2
- package/src/components/Layout.tsx +37 -5
- package/src/components/SwapDetailsPlaceholder.tsx +32 -0
- package/src/components/TokenPreview.tsx +7 -4
- package/src/components/UpdateUrl.tsx +1 -3
- package/src/components/warnings/BalanceWarnings.tsx +1 -0
- package/src/components/warnings/MinRequiredSlippage.tsx +9 -4
- package/src/constants/navigationRoutes.ts +0 -1
- package/src/globalStyles.ts +2 -1
- package/src/hooks/useConfirmSwap.ts +2 -1
- package/src/hooks/useNavigateBack.ts +3 -3
- package/src/lib.tsx +25 -3
- package/src/pages/ConfirmSwapPage.tsx +128 -20
- package/src/pages/HistoryPage.tsx +4 -4
- package/src/pages/Home.tsx +19 -8
- package/src/pages/LiquiditySourcesPage.tsx +2 -0
- package/src/pages/SelectTokenPage.tsx +3 -1
- package/src/pages/SettingsPage.tsx +3 -0
- package/src/pages/SwapDetailsPage.tsx +142 -6
- package/src/pages/WalletsPage.tsx +47 -11
- package/src/store/bestRoute.ts +110 -12
- package/src/store/ui.ts +4 -0
- package/src/store/wallets.ts +4 -1
- package/src/types/routing.ts +1 -1
- package/src/types/swap.ts +7 -0
- package/src/utils/common.ts +14 -0
- package/src/utils/date.ts +62 -0
- package/src/utils/routing.ts +23 -13
- package/src/utils/swap.ts +101 -10
- package/src/utils/time.ts +52 -0
- package/src/utils/wallets.ts +13 -4
- package/dist/components/Header.d.ts +0 -10
- package/dist/components/Header.d.ts.map +0 -1
- package/dist/pages/ConfirmWalletsPage.d.ts +0 -3
- package/dist/pages/ConfirmWalletsPage.d.ts.map +0 -1
- package/src/components/Header.tsx +0 -37
- package/src/pages/ConfirmWalletsPage.tsx +0 -127
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { PendingSwap } from '@rango-dev/queue-manager-rango-preset';
|
|
2
|
+
|
|
3
|
+
export function timeSince(timeMillis: number): string {
|
|
4
|
+
const seconds = Math.floor((new Date().getTime() - timeMillis) / 1000);
|
|
5
|
+
let intervalType: string;
|
|
6
|
+
|
|
7
|
+
let interval = Math.floor(seconds / 31536000);
|
|
8
|
+
if (interval >= 1) {
|
|
9
|
+
intervalType = 'year';
|
|
10
|
+
} else {
|
|
11
|
+
interval = Math.floor(seconds / 2592000);
|
|
12
|
+
if (interval >= 1) {
|
|
13
|
+
intervalType = 'month';
|
|
14
|
+
} else {
|
|
15
|
+
interval = Math.floor(seconds / 86400);
|
|
16
|
+
if (interval >= 1) {
|
|
17
|
+
intervalType = 'day';
|
|
18
|
+
} else {
|
|
19
|
+
interval = Math.floor(seconds / 3600);
|
|
20
|
+
if (interval >= 1) {
|
|
21
|
+
intervalType = 'hour';
|
|
22
|
+
} else {
|
|
23
|
+
interval = Math.floor(seconds / 60);
|
|
24
|
+
if (interval >= 1) {
|
|
25
|
+
intervalType = 'minute';
|
|
26
|
+
} else {
|
|
27
|
+
interval = seconds;
|
|
28
|
+
intervalType = 'second';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (interval > 1 || interval === 0) {
|
|
36
|
+
intervalType += 's';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return interval + ' ' + intervalType;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function getSwapDate(pendingSwap: PendingSwap) {
|
|
43
|
+
return pendingSwap.finishTime
|
|
44
|
+
? `Finished ${timeSince(parseInt(pendingSwap.finishTime))} ago @ ${new Date(
|
|
45
|
+
parseInt(pendingSwap.finishTime)
|
|
46
|
+
).toLocaleString()}`
|
|
47
|
+
: `Started ${timeSince(
|
|
48
|
+
parseInt(pendingSwap.creationTime)
|
|
49
|
+
)} ago @ ${new Date(
|
|
50
|
+
parseInt(pendingSwap.creationTime)
|
|
51
|
+
).toLocaleString()}`;
|
|
52
|
+
}
|
package/src/utils/wallets.ts
CHANGED
|
@@ -441,10 +441,13 @@ export function getSortedTokens(
|
|
|
441
441
|
return sortTokens(getTokensWithBalance(filteredTokens, balances));
|
|
442
442
|
}
|
|
443
443
|
|
|
444
|
-
export function tokensAreEqual(
|
|
444
|
+
export function tokensAreEqual(
|
|
445
|
+
tokenA: Pick<Token, 'blockchain' | 'symbol' | 'address'> | null,
|
|
446
|
+
tokenB: Pick<Token, 'blockchain' | 'symbol' | 'address'> | null
|
|
447
|
+
) {
|
|
445
448
|
return (
|
|
446
449
|
tokenA?.blockchain === tokenB?.blockchain &&
|
|
447
|
-
tokenA?.
|
|
450
|
+
tokenA?.symbol === tokenB?.symbol &&
|
|
448
451
|
tokenA?.address === tokenB?.address
|
|
449
452
|
);
|
|
450
453
|
}
|
|
@@ -469,7 +472,13 @@ export function sortWalletsBasedOnState(
|
|
|
469
472
|
(a, b) =>
|
|
470
473
|
Number(b.state === WalletStatus.CONNECTED) -
|
|
471
474
|
Number(a.state === WalletStatus.CONNECTED) ||
|
|
472
|
-
Number(
|
|
473
|
-
|
|
475
|
+
Number(
|
|
476
|
+
b.state === WalletStatus.DISCONNECTED ||
|
|
477
|
+
b.state === WalletStatus.CONNECTING
|
|
478
|
+
) -
|
|
479
|
+
Number(
|
|
480
|
+
a.state === WalletStatus.DISCONNECTED ||
|
|
481
|
+
a.state === WalletStatus.CONNECTING
|
|
482
|
+
)
|
|
474
483
|
);
|
|
475
484
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
export declare const HeaderContainer: any;
|
|
3
|
-
export interface PropTypes {
|
|
4
|
-
onClickRefresh: () => void;
|
|
5
|
-
title?: string;
|
|
6
|
-
titleSize?: number;
|
|
7
|
-
titleWeight?: number;
|
|
8
|
-
}
|
|
9
|
-
export declare function Header(props: PropTypes): JSX.Element;
|
|
10
|
-
//# sourceMappingURL=Header.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Header.d.ts","sourceRoot":"","sources":["../src/components/Header.tsx"],"names":[],"mappings":";AAKA,eAAO,MAAM,eAAe,KAM1B,CAAC;AAEH,MAAM,WAAW,SAAS;IACxB,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,SAAS,eAgBtC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ConfirmWalletsPage.d.ts","sourceRoot":"","sources":["../src/pages/ConfirmWalletsPage.tsx"],"names":[],"mappings":";AA4BA,wBAAgB,kBAAkB,gBAkGjC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { css, styled, Typography } from '@rango-dev/ui';
|
|
3
|
-
import { HeaderButtons } from './HeaderButtons';
|
|
4
|
-
import { useTranslation } from 'react-i18next';
|
|
5
|
-
|
|
6
|
-
export const HeaderContainer = styled('div', {
|
|
7
|
-
display: 'flex',
|
|
8
|
-
justifyContent: 'space-between',
|
|
9
|
-
alignItems: 'center',
|
|
10
|
-
width: '100%',
|
|
11
|
-
padding: '$16 0',
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
export interface PropTypes {
|
|
15
|
-
onClickRefresh: () => void;
|
|
16
|
-
title?: string;
|
|
17
|
-
titleSize?: number;
|
|
18
|
-
titleWeight?: number;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function Header(props: PropTypes) {
|
|
22
|
-
const { onClickRefresh, title, titleSize, titleWeight } = props;
|
|
23
|
-
const { t } = useTranslation();
|
|
24
|
-
const titleStyle = css({
|
|
25
|
-
fontSize: `${titleSize}px !important`,
|
|
26
|
-
fontWeight: `${titleWeight} !important`,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<HeaderContainer>
|
|
31
|
-
<Typography variant="h4" className={titleStyle()}>
|
|
32
|
-
{title ? t(title.toLocaleLowerCase()) : ''}
|
|
33
|
-
</Typography>
|
|
34
|
-
<HeaderButtons onClickRefresh={onClickRefresh} />
|
|
35
|
-
</HeaderContainer>
|
|
36
|
-
);
|
|
37
|
-
}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import React, { useEffect } from 'react';
|
|
2
|
-
import { ConfirmWallets } from '@rango-dev/ui';
|
|
3
|
-
import { useNavigate } from 'react-router-dom';
|
|
4
|
-
import { useBestRouteStore } from '../store/bestRoute';
|
|
5
|
-
import { useWalletsStore } from '../store/wallets';
|
|
6
|
-
import { useWallets } from '@rango-dev/wallets-core';
|
|
7
|
-
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
8
|
-
import {
|
|
9
|
-
getKeplrCompatibleConnectedWallets,
|
|
10
|
-
getRequiredChains,
|
|
11
|
-
getSelectableWallets,
|
|
12
|
-
isExperimentalChain,
|
|
13
|
-
} from '../utils/wallets';
|
|
14
|
-
import {
|
|
15
|
-
calcOutputUsdValue,
|
|
16
|
-
getTotalFeeInUsd,
|
|
17
|
-
requiredWallets,
|
|
18
|
-
} from '../utils/swap';
|
|
19
|
-
import { decimalNumber, numberToString } from '../utils/numbers';
|
|
20
|
-
import { useMetaStore } from '../store/meta';
|
|
21
|
-
import { Network, WalletType } from '@rango-dev/wallets-shared';
|
|
22
|
-
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
23
|
-
import { TokenPreview } from '../components/TokenPreview';
|
|
24
|
-
// @ts-ignore // TODO: fix error in tsc build
|
|
25
|
-
import { t } from 'i18next';
|
|
26
|
-
import { Spacer } from '@rango-dev/ui';
|
|
27
|
-
import RoutesOverview from '../components/RoutesOverview';
|
|
28
|
-
|
|
29
|
-
export function ConfirmWalletsPage() {
|
|
30
|
-
const navigate = useNavigate();
|
|
31
|
-
const { navigateBackFrom } = useNavigateBack();
|
|
32
|
-
const bestRoute = useBestRouteStore.use.bestRoute();
|
|
33
|
-
|
|
34
|
-
const { blockchains, tokens } = useMetaStore.use.meta();
|
|
35
|
-
const accounts = useWalletsStore.use.accounts();
|
|
36
|
-
const selectedWallets = useWalletsStore.use.selectedWallets();
|
|
37
|
-
const initSelectedWallets = useWalletsStore.use.initSelectedWallets();
|
|
38
|
-
const setSelectedWallet = useWalletsStore.use.setSelectedWallet();
|
|
39
|
-
|
|
40
|
-
const { getWalletInfo, connect } = useWallets();
|
|
41
|
-
const confirmDisabled = !requiredWallets(bestRoute).every((chain) =>
|
|
42
|
-
selectedWallets.map((wallet) => wallet.chain).includes(chain)
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const firstStep = bestRoute?.result?.swaps[0];
|
|
46
|
-
const lastStep =
|
|
47
|
-
bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1];
|
|
48
|
-
|
|
49
|
-
const fromAmount = decimalNumber(firstStep?.fromAmount, 3);
|
|
50
|
-
const toAmount = decimalNumber(lastStep?.toAmount, 3);
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
initSelectedWallets();
|
|
53
|
-
}, []);
|
|
54
|
-
|
|
55
|
-
const selectableWallets = getSelectableWallets(
|
|
56
|
-
accounts,
|
|
57
|
-
selectedWallets,
|
|
58
|
-
getWalletInfo
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
const handleConnectChain = (wallet: string) => {
|
|
62
|
-
const network = wallet as Network;
|
|
63
|
-
getKeplrCompatibleConnectedWallets(selectableWallets).forEach(
|
|
64
|
-
(compatibleWallet: WalletType) => connect?.(compatibleWallet, network)
|
|
65
|
-
);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
69
|
-
|
|
70
|
-
return (
|
|
71
|
-
<ConfirmWallets
|
|
72
|
-
requiredWallets={getRequiredChains(bestRoute)}
|
|
73
|
-
selectableWallets={selectableWallets}
|
|
74
|
-
onBack={navigateBackFrom.bind(null, navigationRoutes.confirmWallets)}
|
|
75
|
-
onConfirm={() =>
|
|
76
|
-
navigate(navigationRoutes.confirmSwap, { replace: true })
|
|
77
|
-
}
|
|
78
|
-
onChange={(wallet) => setSelectedWallet(wallet)}
|
|
79
|
-
confirmDisabled={confirmDisabled}
|
|
80
|
-
handleConnectChain={(wallet) => handleConnectChain(wallet)}
|
|
81
|
-
isExperimentalChain={(wallet) =>
|
|
82
|
-
getKeplrCompatibleConnectedWallets(selectableWallets).length > 0
|
|
83
|
-
? isExperimentalChain(blockchains, wallet)
|
|
84
|
-
: false
|
|
85
|
-
}
|
|
86
|
-
previewInputs={
|
|
87
|
-
<>
|
|
88
|
-
<TokenPreview
|
|
89
|
-
chain={{
|
|
90
|
-
displayName: firstStep?.from.blockchain || '',
|
|
91
|
-
logo: firstStep?.from.blockchainLogo || '',
|
|
92
|
-
}}
|
|
93
|
-
token={{
|
|
94
|
-
symbol: firstStep?.from.symbol || '',
|
|
95
|
-
image: firstStep?.from.logo || '',
|
|
96
|
-
}}
|
|
97
|
-
usdValue={calcOutputUsdValue(fromAmount, firstStep?.from.usdPrice)}
|
|
98
|
-
amount={fromAmount}
|
|
99
|
-
label={t('From')}
|
|
100
|
-
loadingStatus={'success'}
|
|
101
|
-
/>
|
|
102
|
-
<Spacer size={12} direction="vertical" />
|
|
103
|
-
<TokenPreview
|
|
104
|
-
chain={{
|
|
105
|
-
displayName: lastStep?.to.blockchain || '',
|
|
106
|
-
logo: lastStep?.to.blockchainLogo || '',
|
|
107
|
-
}}
|
|
108
|
-
token={{
|
|
109
|
-
symbol: lastStep?.to.symbol || '',
|
|
110
|
-
image: lastStep?.to.logo || '',
|
|
111
|
-
}}
|
|
112
|
-
usdValue={calcOutputUsdValue(toAmount, lastStep?.to.usdPrice)}
|
|
113
|
-
amount={toAmount}
|
|
114
|
-
label={t('To')}
|
|
115
|
-
loadingStatus={'success'}
|
|
116
|
-
/>
|
|
117
|
-
</>
|
|
118
|
-
}
|
|
119
|
-
previewRoutes={
|
|
120
|
-
<RoutesOverview
|
|
121
|
-
routes={bestRoute}
|
|
122
|
-
totalFee={numberToString(totalFeeInUsd, 0, 2)}
|
|
123
|
-
/>
|
|
124
|
-
}
|
|
125
|
-
/>
|
|
126
|
-
);
|
|
127
|
-
}
|