@rango-dev/widget-embedded 0.1.10 → 0.1.11-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.
- package/dist/App.d.ts +3 -3
- package/dist/App.d.ts.map +1 -1
- package/dist/components/AppRouter.d.ts +1 -7
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/AppRoutes.d.ts +2 -2
- package/dist/components/AppRoutes.d.ts.map +1 -1
- package/dist/components/Layout.d.ts +3 -3
- package/dist/components/Layout.d.ts.map +1 -1
- package/dist/components/PercentageChange.d.ts +9 -0
- package/dist/components/PercentageChange.d.ts.map +1 -0
- package/dist/components/TokenInfo.d.ts.map +1 -1
- package/dist/components/TokenPreview.d.ts +2 -1
- package/dist/components/TokenPreview.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap.d.ts.map +1 -1
- package/dist/hooks/useTheme.d.ts +2 -5
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/lib.d.ts +2 -2
- package/dist/lib.d.ts.map +1 -1
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts +1 -7
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/LiquiditySourcesPage.d.ts +1 -2
- package/dist/pages/LiquiditySourcesPage.d.ts.map +1 -1
- package/dist/pages/SelectChainPage.d.ts +1 -2
- package/dist/pages/SelectChainPage.d.ts.map +1 -1
- package/dist/pages/SelectTokenPage.d.ts +2 -2
- package/dist/pages/SelectTokenPage.d.ts.map +1 -1
- package/dist/pages/SettingsPage.d.ts +1 -2
- 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 -1
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/store/bestRoute.d.ts +1 -0
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/store/settings.d.ts +2 -0
- package/dist/store/settings.d.ts.map +1 -1
- package/dist/types/config.d.ts +26 -29
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/routing.d.ts +14 -1
- package/dist/types/routing.d.ts.map +1 -1
- package/dist/utils/routing.d.ts +2 -2
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +2 -6
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +181 -193
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +181 -193
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +181 -193
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +6 -4
- package/readme.md +1 -1
- package/src/App.tsx +21 -13
- package/src/components/AppRouter.tsx +7 -16
- package/src/components/AppRoutes.tsx +13 -32
- package/src/components/Layout.tsx +32 -23
- package/src/components/PercentageChange.tsx +33 -0
- package/src/components/TokenInfo.tsx +20 -4
- package/src/components/TokenPreview.tsx +16 -8
- package/src/hooks/useConfirmSwap.ts +5 -4
- package/src/hooks/useTheme.ts +15 -9
- package/src/lib.tsx +30 -36
- package/src/pages/ConfirmSwapPage.tsx +14 -7
- package/src/pages/Home.tsx +10 -22
- package/src/pages/LiquiditySourcesPage.tsx +3 -6
- package/src/pages/SelectChainPage.tsx +6 -6
- package/src/pages/SelectTokenPage.tsx +16 -18
- package/src/pages/SettingsPage.tsx +8 -18
- package/src/pages/SwapDetailsPage.tsx +2 -4
- package/src/pages/WalletsPage.tsx +2 -2
- package/src/store/bestRoute.ts +38 -8
- package/src/store/settings.ts +7 -0
- package/src/types/config.ts +27 -29
- package/src/types/routing.ts +17 -1
- package/src/utils/routing.ts +29 -23
- package/src/utils/swap.ts +5 -97
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/widget-embedded",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11-next.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
],
|
|
11
11
|
"browserslist": "> 0.5%, last 2 versions, not dead",
|
|
12
12
|
"scripts": {
|
|
13
|
-
"
|
|
13
|
+
"watch-tsc": "tsc --watch --noEmit",
|
|
14
|
+
"parcel": "parcel public/index.html -p 3001 --cache-dir=.parcel-cache",
|
|
15
|
+
"dev": "npm-run-all --parallel watch-tsc parcel",
|
|
14
16
|
"build:app": "parcel build --cache-dir=.parcel-cache",
|
|
15
17
|
"build": "tsdx build --entry ./src/lib.tsx"
|
|
16
18
|
},
|
|
@@ -27,8 +29,8 @@
|
|
|
27
29
|
},
|
|
28
30
|
"dependencies": {
|
|
29
31
|
"@rango-dev/provider-all": "^0.1.11-next.84",
|
|
30
|
-
"@rango-dev/queue-manager-core": "^0.1.
|
|
31
|
-
"@rango-dev/queue-manager-rango-preset": "^0.1.
|
|
32
|
+
"@rango-dev/queue-manager-core": "^0.1.11-next.0",
|
|
33
|
+
"@rango-dev/queue-manager-rango-preset": "^0.1.11-next.2",
|
|
32
34
|
"@rango-dev/queue-manager-react": "^0.1.10-next.76",
|
|
33
35
|
"@rango-dev/ui": "^0.1.10-next.75",
|
|
34
36
|
"@rango-dev/wallets-core": "^0.1.11-next.88",
|
package/readme.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
# @rango-dev/widget-embedded
|
|
1
|
+
# @rango-dev/widget-embedded
|
package/src/App.tsx
CHANGED
|
@@ -17,7 +17,7 @@ import { globalFont, globalStyles } from './globalStyles';
|
|
|
17
17
|
import { useTheme } from './hooks/useTheme';
|
|
18
18
|
import QueueManager from './QueueManager';
|
|
19
19
|
import { isEvmBlockchain } from 'rango-sdk';
|
|
20
|
-
import {
|
|
20
|
+
import { WidgetConfig } from './types';
|
|
21
21
|
import './i18n';
|
|
22
22
|
import { useUiStore } from './store/ui';
|
|
23
23
|
import { navigationRoutes } from './constants/navigationRoutes';
|
|
@@ -25,16 +25,13 @@ import { navigationRoutes } from './constants/navigationRoutes';
|
|
|
25
25
|
const providers = allProviders();
|
|
26
26
|
|
|
27
27
|
export type WidgetProps = {
|
|
28
|
-
|
|
28
|
+
config?: WidgetConfig;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
export function App({
|
|
31
|
+
export function App({ config }: WidgetProps) {
|
|
32
32
|
globalStyles();
|
|
33
|
-
globalFont(
|
|
34
|
-
const { activeTheme } = useTheme({
|
|
35
|
-
...configs?.colors,
|
|
36
|
-
borderRadius: configs?.borderRadius,
|
|
37
|
-
});
|
|
33
|
+
globalFont(config?.theme?.fontFamily || 'Roboto');
|
|
34
|
+
const { activeTheme } = useTheme({ ...config?.theme });
|
|
38
35
|
|
|
39
36
|
const { blockchains } = useMetaStore.use.meta();
|
|
40
37
|
const disconnectWallet = useWalletsStore.use.disconnectWallet();
|
|
@@ -95,18 +92,29 @@ export function App({ configs }: WidgetProps) {
|
|
|
95
92
|
>
|
|
96
93
|
<div id="pageContainer" className={activeTheme}>
|
|
97
94
|
<QueueManager>
|
|
98
|
-
<SwapContainer
|
|
95
|
+
<SwapContainer
|
|
96
|
+
// style={
|
|
97
|
+
// currentPage !== navigationRoutes.home && config?.theme?.height
|
|
98
|
+
// ? {
|
|
99
|
+
// height: config?.theme?.height,
|
|
100
|
+
// width: config?.theme?.width || 'auto',
|
|
101
|
+
// }
|
|
102
|
+
// : config?.theme?.width
|
|
103
|
+
// ? {
|
|
104
|
+
// width: config?.theme?.width || 'auto',
|
|
105
|
+
// }
|
|
106
|
+
// : undefined
|
|
107
|
+
// }
|
|
108
|
+
fixedHeight={currentPage !== navigationRoutes.home}
|
|
109
|
+
>
|
|
99
110
|
<AppRouter
|
|
100
|
-
title={configs?.title}
|
|
101
|
-
titleSize={configs?.titleSize}
|
|
102
|
-
titleWeight={configs?.titleWeight}
|
|
103
111
|
lastConnectedWallet={lastConnectedWalletWithNetwork}
|
|
104
112
|
disconnectedWallet={disconnectedWallet}
|
|
105
113
|
clearDisconnectedWallet={() => {
|
|
106
114
|
setDisconnectedWallet(undefined);
|
|
107
115
|
}}
|
|
108
116
|
>
|
|
109
|
-
<Layout
|
|
117
|
+
<Layout config={config} />
|
|
110
118
|
</AppRouter>
|
|
111
119
|
</SwapContainer>
|
|
112
120
|
</QueueManager>
|
|
@@ -13,15 +13,7 @@ import { UpdateUrl } from './UpdateUrl';
|
|
|
13
13
|
import { Home } from '../pages/Home';
|
|
14
14
|
import { useMetaStore } from '../store/meta';
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
title?: string;
|
|
18
|
-
titleSize?: number;
|
|
19
|
-
titleWeight?: number;
|
|
20
|
-
}
|
|
21
|
-
const Route: React.FC = ({
|
|
22
|
-
children,
|
|
23
|
-
...props
|
|
24
|
-
}: PropTypes & PropsWithChildren) => {
|
|
16
|
+
const Route: React.FC = ({ children }: PropsWithChildren) => {
|
|
25
17
|
const location = useLocation();
|
|
26
18
|
const navigate = useNavigate();
|
|
27
19
|
const ref = useRef(true);
|
|
@@ -34,7 +26,7 @@ const Route: React.FC = ({
|
|
|
34
26
|
}, []);
|
|
35
27
|
|
|
36
28
|
if (location.pathname === navigationRoutes.confirmSwap && ref.current)
|
|
37
|
-
return <Home
|
|
29
|
+
return <Home />;
|
|
38
30
|
|
|
39
31
|
return <> {children}</>;
|
|
40
32
|
};
|
|
@@ -42,12 +34,11 @@ const Route: React.FC = ({
|
|
|
42
34
|
export function AppRouter({
|
|
43
35
|
children,
|
|
44
36
|
...props
|
|
45
|
-
}:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}) {
|
|
37
|
+
}: PropsWithChildren & {
|
|
38
|
+
lastConnectedWallet: string;
|
|
39
|
+
disconnectedWallet: WalletType | undefined;
|
|
40
|
+
clearDisconnectedWallet: () => void;
|
|
41
|
+
}) {
|
|
51
42
|
const isRouterInContext = useInRouterContext();
|
|
52
43
|
const Router = isRouterInContext ? Route : MemoryRouter;
|
|
53
44
|
const { blockchains } = useMetaStore.use.meta();
|
|
@@ -10,76 +10,57 @@ import { SelectTokenPage } from '../pages/SelectTokenPage';
|
|
|
10
10
|
import { SettingsPage } from '../pages/SettingsPage';
|
|
11
11
|
import { WalletsPage } from '../pages/WalletsPage';
|
|
12
12
|
import { SwapDetailsPage } from '../pages/SwapDetailsPage';
|
|
13
|
-
import {
|
|
13
|
+
import { WidgetConfig } from '../types';
|
|
14
14
|
|
|
15
15
|
const getAbsolutePath = (path: string) => path.replace('/', '');
|
|
16
16
|
|
|
17
17
|
interface PropTypes {
|
|
18
|
-
|
|
18
|
+
config?: WidgetConfig;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export function AppRoutes(props: PropTypes) {
|
|
22
|
-
const {
|
|
22
|
+
const { config } = props;
|
|
23
23
|
|
|
24
24
|
return useRoutes([
|
|
25
25
|
{
|
|
26
26
|
path: getAbsolutePath(navigationRoutes.home),
|
|
27
|
-
element:
|
|
28
|
-
<Home
|
|
29
|
-
title={configs?.title}
|
|
30
|
-
titleSize={configs?.titleSize}
|
|
31
|
-
titleWeight={configs?.titleWeight}
|
|
32
|
-
/>
|
|
33
|
-
),
|
|
27
|
+
element: <Home />,
|
|
34
28
|
},
|
|
35
29
|
{
|
|
36
30
|
path: getAbsolutePath(navigationRoutes.fromChain),
|
|
37
31
|
element: (
|
|
38
32
|
<SelectChainPage
|
|
39
33
|
type="from"
|
|
40
|
-
supportedChains={
|
|
34
|
+
supportedChains={config?.from?.blockchains}
|
|
41
35
|
/>
|
|
42
36
|
),
|
|
43
37
|
},
|
|
44
38
|
{
|
|
45
39
|
path: getAbsolutePath(navigationRoutes.toChain),
|
|
46
40
|
element: (
|
|
47
|
-
<SelectChainPage
|
|
48
|
-
type="to"
|
|
49
|
-
supportedChains={configs?.toChains || 'all'}
|
|
50
|
-
/>
|
|
41
|
+
<SelectChainPage type="to" supportedChains={config?.to?.blockchains} />
|
|
51
42
|
),
|
|
52
43
|
},
|
|
53
44
|
{
|
|
54
45
|
path: getAbsolutePath(navigationRoutes.fromToken),
|
|
55
46
|
element: (
|
|
56
|
-
<SelectTokenPage
|
|
57
|
-
type="from"
|
|
58
|
-
supportedTokens={configs?.fromTokens || 'all'}
|
|
59
|
-
/>
|
|
47
|
+
<SelectTokenPage type="from" supportedTokens={config?.from?.tokens} />
|
|
60
48
|
),
|
|
61
49
|
},
|
|
62
50
|
{
|
|
63
51
|
path: getAbsolutePath(navigationRoutes.toToken),
|
|
64
52
|
element: (
|
|
65
|
-
<SelectTokenPage
|
|
66
|
-
type="to"
|
|
67
|
-
supportedTokens={configs?.toTokens || 'all'}
|
|
68
|
-
/>
|
|
53
|
+
<SelectTokenPage type="to" supportedTokens={config?.to?.tokens} />
|
|
69
54
|
),
|
|
70
55
|
},
|
|
71
56
|
{
|
|
72
57
|
path: getAbsolutePath(navigationRoutes.settings),
|
|
73
|
-
element:
|
|
74
|
-
<SettingsPage supportedSwappers={configs?.liquiditySources || 'all'} />
|
|
75
|
-
),
|
|
58
|
+
element: <SettingsPage supportedSwappers={config?.liquiditySources} />,
|
|
76
59
|
},
|
|
77
60
|
{
|
|
78
61
|
path: getAbsolutePath(navigationRoutes.liquiditySources),
|
|
79
62
|
element: (
|
|
80
|
-
<LiquiditySourcePage
|
|
81
|
-
supportedSwappers={configs?.liquiditySources || 'all'}
|
|
82
|
-
/>
|
|
63
|
+
<LiquiditySourcePage supportedSwappers={config?.liquiditySources} />
|
|
83
64
|
),
|
|
84
65
|
},
|
|
85
66
|
{ path: getAbsolutePath(navigationRoutes.swaps), element: <HistoryPage /> },
|
|
@@ -91,11 +72,11 @@ export function AppRoutes(props: PropTypes) {
|
|
|
91
72
|
path: getAbsolutePath(navigationRoutes.wallets),
|
|
92
73
|
element: (
|
|
93
74
|
<WalletsPage
|
|
94
|
-
supportedWallets={
|
|
75
|
+
supportedWallets={config?.wallets}
|
|
95
76
|
multiWallets={
|
|
96
|
-
typeof
|
|
77
|
+
typeof config?.multiWallets === 'undefined'
|
|
97
78
|
? true
|
|
98
|
-
:
|
|
79
|
+
: config.multiWallets
|
|
99
80
|
}
|
|
100
81
|
/>
|
|
101
82
|
),
|
|
@@ -15,12 +15,14 @@ import { fetchingBalanceSelector, useWalletsStore } from '../store/wallets';
|
|
|
15
15
|
import {
|
|
16
16
|
calculateWalletUsdValue,
|
|
17
17
|
getSelectableWallets,
|
|
18
|
+
tokensAreEqual,
|
|
18
19
|
} from '../utils/wallets';
|
|
19
20
|
import { removeDuplicateFrom } from '../utils/common';
|
|
20
|
-
import {
|
|
21
|
+
import { WidgetConfig } from '../types';
|
|
21
22
|
import { useTranslation } from 'react-i18next';
|
|
22
23
|
import { useBestRouteStore } from '../store/bestRoute';
|
|
23
24
|
import { useMetaStore } from '../store/meta';
|
|
25
|
+
import { useSettingsStore } from '../store/settings';
|
|
24
26
|
|
|
25
27
|
const Header = styled('div', {
|
|
26
28
|
display: 'flex',
|
|
@@ -40,10 +42,10 @@ const WalletImage = styled('img', {
|
|
|
40
42
|
});
|
|
41
43
|
|
|
42
44
|
export type LayoutProps = {
|
|
43
|
-
|
|
45
|
+
config?: WidgetConfig;
|
|
44
46
|
};
|
|
45
47
|
|
|
46
|
-
export function Layout({
|
|
48
|
+
export function Layout({ config }: LayoutProps) {
|
|
47
49
|
const navigate = useNavigate();
|
|
48
50
|
const { balances, accounts, selectedWallets } = useWalletsStore();
|
|
49
51
|
const { getWalletInfo } = useWallets();
|
|
@@ -52,12 +54,13 @@ export function Layout({ configs }: LayoutProps) {
|
|
|
52
54
|
(w) => w.image
|
|
53
55
|
)
|
|
54
56
|
);
|
|
55
|
-
|
|
57
|
+
const { blockchains, tokens } = useMetaStore.use.meta();
|
|
56
58
|
const setFromChain = useBestRouteStore.use.setFromChain();
|
|
57
59
|
const setFromToken = useBestRouteStore.use.setFromToken();
|
|
58
60
|
const setToChain = useBestRouteStore.use.setToChain();
|
|
59
61
|
const setToToken = useBestRouteStore.use.setToToken();
|
|
60
62
|
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
63
|
+
const setAffiliateRef = useSettingsStore.use.setAffiliateRef();
|
|
61
64
|
|
|
62
65
|
const totalBalance = calculateWalletUsdValue(balances);
|
|
63
66
|
const connectWalletsButtonDisabled =
|
|
@@ -67,29 +70,35 @@ export function Layout({ configs }: LayoutProps) {
|
|
|
67
70
|
|
|
68
71
|
const { t } = useTranslation();
|
|
69
72
|
useEffect(() => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
const chain = blockchains.find(
|
|
74
|
+
(chain) => chain.name === config?.to?.blockchain
|
|
75
|
+
);
|
|
76
|
+
const token = tokens.find((t) =>
|
|
77
|
+
tokensAreEqual(t, config?.to?.token || null)
|
|
78
|
+
);
|
|
79
|
+
setToChain(chain || null);
|
|
80
|
+
setToToken(token || null);
|
|
81
|
+
}, [config?.to?.token, config?.to?.blockchain]);
|
|
82
|
+
|
|
73
83
|
useEffect(() => {
|
|
74
|
-
setInputAmount(
|
|
75
|
-
}, [
|
|
84
|
+
setInputAmount(config?.amount?.toString() || '');
|
|
85
|
+
}, [config?.amount]);
|
|
76
86
|
|
|
77
87
|
useEffect(() => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
88
|
+
const chain = blockchains.find(
|
|
89
|
+
(chain) => chain.name === config?.from?.blockchain
|
|
90
|
+
);
|
|
91
|
+
const token = tokens.find((t) =>
|
|
92
|
+
tokensAreEqual(t, config?.from?.token || null)
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
setFromChain(chain || null);
|
|
96
|
+
setFromToken(token || null);
|
|
97
|
+
}, [config?.from?.token, config?.from?.blockchain]);
|
|
81
98
|
|
|
82
99
|
useEffect(() => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
setFromToken(null);
|
|
86
|
-
setToToken(null);
|
|
87
|
-
}, [
|
|
88
|
-
configs?.fromChains,
|
|
89
|
-
configs?.toChains,
|
|
90
|
-
configs?.fromTokens,
|
|
91
|
-
configs?.toTokens,
|
|
92
|
-
]);
|
|
100
|
+
setAffiliateRef(config?.affiliateRef || null);
|
|
101
|
+
}, [config?.affiliateRef]);
|
|
93
102
|
return (
|
|
94
103
|
<>
|
|
95
104
|
<Header>
|
|
@@ -122,7 +131,7 @@ export function Layout({ configs }: LayoutProps) {
|
|
|
122
131
|
</div>
|
|
123
132
|
</Button>
|
|
124
133
|
</Header>
|
|
125
|
-
<AppRoutes
|
|
134
|
+
<AppRoutes config={config} />
|
|
126
135
|
</>
|
|
127
136
|
);
|
|
128
137
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { getPercentageChange } from '../utils/swap';
|
|
4
|
+
import { Typography } from '@rango-dev/ui';
|
|
5
|
+
import { numberToString } from '../utils/numbers';
|
|
6
|
+
|
|
7
|
+
interface PropTypes {
|
|
8
|
+
inputUsdValue: BigNumber | null;
|
|
9
|
+
outputUsdValue: BigNumber | null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function PercentageChange(props: PropTypes) {
|
|
13
|
+
const { inputUsdValue, outputUsdValue } = props;
|
|
14
|
+
|
|
15
|
+
if (!inputUsdValue || !outputUsdValue || !outputUsdValue.gt(0)) return null;
|
|
16
|
+
|
|
17
|
+
const percentageChange = getPercentageChange(
|
|
18
|
+
inputUsdValue.toNumber(),
|
|
19
|
+
outputUsdValue.toNumber()
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const showPercentageChange = percentageChange?.lt(0);
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<>
|
|
26
|
+
{showPercentageChange && (
|
|
27
|
+
<Typography variant="caption" color="$error500">
|
|
28
|
+
{`(${numberToString(percentageChange, 0, 2)}%)`}
|
|
29
|
+
</Typography>
|
|
30
|
+
)}
|
|
31
|
+
</>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -17,6 +17,7 @@ import { getBalanceFromWallet } from '../utils/wallets';
|
|
|
17
17
|
import { useWalletsStore } from '../store/wallets';
|
|
18
18
|
import { useTranslation } from 'react-i18next';
|
|
19
19
|
import { Spacer } from '@rango-dev/ui';
|
|
20
|
+
import { PercentageChange } from './PercentageChange';
|
|
20
21
|
|
|
21
22
|
type PropTypes = (
|
|
22
23
|
| {
|
|
@@ -80,6 +81,13 @@ const Container = styled('div', {
|
|
|
80
81
|
width: '30%',
|
|
81
82
|
},
|
|
82
83
|
},
|
|
84
|
+
'.output-usd': {
|
|
85
|
+
display: 'flex',
|
|
86
|
+
div: {
|
|
87
|
+
display: 'flex',
|
|
88
|
+
paddingLeft: '$8',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
83
91
|
});
|
|
84
92
|
|
|
85
93
|
const StyledImage = styled('img', {
|
|
@@ -201,10 +209,18 @@ export function TokenInfo(props: PropTypes) {
|
|
|
201
209
|
</div>
|
|
202
210
|
</Options>
|
|
203
211
|
) : (
|
|
204
|
-
<
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
212
|
+
<div className="output-usd">
|
|
213
|
+
<PercentageChange
|
|
214
|
+
inputUsdValue={inputUsdValue}
|
|
215
|
+
outputUsdValue={props.outputUsdValue}
|
|
216
|
+
/>
|
|
217
|
+
<div>
|
|
218
|
+
<Typography
|
|
219
|
+
variant="caption"
|
|
220
|
+
color="neutrals600"
|
|
221
|
+
>{`$${numberToString(props.outputUsdValue)}`}</Typography>
|
|
222
|
+
</div>
|
|
223
|
+
</div>
|
|
208
224
|
)}
|
|
209
225
|
</div>
|
|
210
226
|
<div className="form">
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
2
|
import { Button, InfoCircleIcon, styled, Typography } from '@rango-dev/ui';
|
|
3
3
|
import { LoadingStatus } from '../store/meta';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
@@ -37,6 +37,9 @@ const Container = styled('div', {
|
|
|
37
37
|
justifyContent: 'space-between',
|
|
38
38
|
alignItems: 'center',
|
|
39
39
|
minHeight: '32px',
|
|
40
|
+
'.usd-value': {
|
|
41
|
+
paddingLeft: '$8',
|
|
42
|
+
},
|
|
40
43
|
},
|
|
41
44
|
'.form': {
|
|
42
45
|
display: 'flex',
|
|
@@ -95,10 +98,11 @@ interface PropTypes {
|
|
|
95
98
|
symbol: string;
|
|
96
99
|
image: string;
|
|
97
100
|
};
|
|
101
|
+
percentageChange?: ReactNode;
|
|
98
102
|
}
|
|
99
103
|
|
|
100
104
|
export function TokenPreview(props: PropTypes) {
|
|
101
|
-
const { chain, token, loadingStatus } = props;
|
|
105
|
+
const { chain, token, loadingStatus, percentageChange } = props;
|
|
102
106
|
const { t } = useTranslation();
|
|
103
107
|
|
|
104
108
|
const ItemSuffix = (
|
|
@@ -120,12 +124,16 @@ export function TokenPreview(props: PropTypes) {
|
|
|
120
124
|
<Typography variant="body2" color="neutrals800">
|
|
121
125
|
{props.label}
|
|
122
126
|
</Typography>
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
<div>
|
|
128
|
+
{percentageChange}
|
|
129
|
+
{props.usdValue && (
|
|
130
|
+
<Typography
|
|
131
|
+
variant="caption"
|
|
132
|
+
color="neutrals600"
|
|
133
|
+
className="usd-value"
|
|
134
|
+
>{`$${numberToString(props.usdValue)}`}</Typography>
|
|
135
|
+
)}
|
|
136
|
+
</div>
|
|
129
137
|
</div>
|
|
130
138
|
<div className="form">
|
|
131
139
|
<Button
|
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
} from '../types';
|
|
13
13
|
import { PendingSwap } from '@rango-dev/ui/dist/containers/History/types';
|
|
14
14
|
import {
|
|
15
|
-
calculatePendingSwap,
|
|
16
15
|
createBestRouteRequestBody,
|
|
17
16
|
getBalanceWarnings,
|
|
18
17
|
getMinRequiredSlippage,
|
|
@@ -34,6 +33,7 @@ import {
|
|
|
34
33
|
} from '../utils/routing';
|
|
35
34
|
import { numberToString } from '../utils/numbers';
|
|
36
35
|
import { BestRouteResponse } from 'rango-sdk';
|
|
36
|
+
import { calculatePendingSwap } from '@rango-dev/queue-manager-rango-preset';
|
|
37
37
|
|
|
38
38
|
type ConfirmSwap = {
|
|
39
39
|
loading: boolean;
|
|
@@ -49,6 +49,8 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
49
49
|
const initialRoute = useBestRouteStore.use.bestRoute();
|
|
50
50
|
const setBestRoute = useBestRouteStore.use.setBestRoute();
|
|
51
51
|
const inputUsdValue = useBestRouteStore.use.inputUsdValue();
|
|
52
|
+
const affiliateRef = useSettingsStore.use.affiliateRef();
|
|
53
|
+
|
|
52
54
|
const accounts = useWalletsStore.use.accounts();
|
|
53
55
|
const selectedWallets = useWalletsStore.use.selectedWallets();
|
|
54
56
|
const meta = useMetaStore.use.meta();
|
|
@@ -93,7 +95,6 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
93
95
|
meta
|
|
94
96
|
);
|
|
95
97
|
|
|
96
|
-
//@ts-ignore
|
|
97
98
|
return newSwap;
|
|
98
99
|
}
|
|
99
100
|
return;
|
|
@@ -111,7 +112,8 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
111
112
|
selectedWallets,
|
|
112
113
|
disabledLiquiditySources,
|
|
113
114
|
userSlippage,
|
|
114
|
-
true
|
|
115
|
+
true,
|
|
116
|
+
affiliateRef
|
|
115
117
|
);
|
|
116
118
|
|
|
117
119
|
try {
|
|
@@ -229,7 +231,6 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
229
231
|
false,
|
|
230
232
|
meta
|
|
231
233
|
);
|
|
232
|
-
//@ts-ignore
|
|
233
234
|
return newSwap;
|
|
234
235
|
} else if (!proceedAnywayRef.current) {
|
|
235
236
|
proceedAnywayRef.current = true;
|
package/src/hooks/useTheme.ts
CHANGED
|
@@ -2,22 +2,26 @@ import { createTheme } from '@rango-dev/ui';
|
|
|
2
2
|
import { useState, useEffect, useLayoutEffect } from 'react';
|
|
3
3
|
import { useMetaStore } from '../store/meta';
|
|
4
4
|
import { useSettingsStore } from '../store/settings';
|
|
5
|
-
import {
|
|
5
|
+
import { Theme } from '../types';
|
|
6
6
|
import { shadeColor } from '../utils/common';
|
|
7
7
|
import usePrevious from './usePrevious';
|
|
8
8
|
|
|
9
9
|
export function useTheme({
|
|
10
|
-
|
|
11
|
-
background = '#fff',
|
|
12
|
-
foreground = '#000',
|
|
13
|
-
error = '#FF0000',
|
|
14
|
-
warning = '#F5A623',
|
|
15
|
-
success = '#0070F3',
|
|
10
|
+
colors: themeColors,
|
|
16
11
|
fontFamily = 'Robot',
|
|
17
12
|
borderRadius = 8,
|
|
18
|
-
|
|
13
|
+
mode = 'auto',
|
|
14
|
+
}: Theme) {
|
|
19
15
|
const theme = useSettingsStore.use.theme();
|
|
20
16
|
const fetchMeta = useMetaStore.use.fetchMeta();
|
|
17
|
+
const setTheme = useSettingsStore.use.setTheme();
|
|
18
|
+
|
|
19
|
+
const primary = themeColors?.primary || '#5FA425',
|
|
20
|
+
background = themeColors?.background || '#fff',
|
|
21
|
+
foreground = themeColors?.foreground || '#000',
|
|
22
|
+
error = themeColors?.error || '#FF0000',
|
|
23
|
+
warning = themeColors?.warning || '#F5A623',
|
|
24
|
+
success = themeColors?.success || '#0070F3';
|
|
21
25
|
const colors = {
|
|
22
26
|
neutrals200: '#FAFAFA',
|
|
23
27
|
neutrals300: '#f2f2f2',
|
|
@@ -108,7 +112,9 @@ export function useTheme({
|
|
|
108
112
|
.removeEventListener('change', switchTheme);
|
|
109
113
|
};
|
|
110
114
|
}, []);
|
|
111
|
-
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
if (mode !== 'auto') setTheme(mode);
|
|
117
|
+
}, [mode]);
|
|
112
118
|
const prevFont = usePrevious(fontFamily);
|
|
113
119
|
|
|
114
120
|
useLayoutEffect(() => {
|