@rango-dev/widget-embedded 0.1.10-next.100

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 (204) hide show
  1. package/dist/App.d.ts +9 -0
  2. package/dist/App.d.ts.map +1 -0
  3. package/dist/QueueManager.d.ts +4 -0
  4. package/dist/QueueManager.d.ts.map +1 -0
  5. package/dist/components/AppRouter.d.ts +9 -0
  6. package/dist/components/AppRouter.d.ts.map +1 -0
  7. package/dist/components/AppRoutes.d.ts +8 -0
  8. package/dist/components/AppRoutes.d.ts.map +1 -0
  9. package/dist/components/BottomLogo.d.ts +3 -0
  10. package/dist/components/BottomLogo.d.ts.map +1 -0
  11. package/dist/components/ChangeSlippageButton.d.ts +3 -0
  12. package/dist/components/ChangeSlippageButton.d.ts.map +1 -0
  13. package/dist/components/ConfirmSwapErrors.d.ts +4 -0
  14. package/dist/components/ConfirmSwapErrors.d.ts.map +1 -0
  15. package/dist/components/ConfirmSwapWarnings.d.ts +4 -0
  16. package/dist/components/ConfirmSwapWarnings.d.ts.map +1 -0
  17. package/dist/components/Footer.d.ts +2 -0
  18. package/dist/components/Footer.d.ts.map +1 -0
  19. package/dist/components/Header.d.ts +10 -0
  20. package/dist/components/Header.d.ts.map +1 -0
  21. package/dist/components/HeaderButtons.d.ts +4 -0
  22. package/dist/components/HeaderButtons.d.ts.map +1 -0
  23. package/dist/components/Layout.d.ts +7 -0
  24. package/dist/components/Layout.d.ts.map +1 -0
  25. package/dist/components/RoutesOverview.d.ts +10 -0
  26. package/dist/components/RoutesOverview.d.ts.map +1 -0
  27. package/dist/components/SwitchFromAndTo.d.ts +4 -0
  28. package/dist/components/SwitchFromAndTo.d.ts.map +1 -0
  29. package/dist/components/TokenInfo.d.ts +18 -0
  30. package/dist/components/TokenInfo.d.ts.map +1 -0
  31. package/dist/components/TokenPreview.d.ts +20 -0
  32. package/dist/components/TokenPreview.d.ts.map +1 -0
  33. package/dist/components/UpdateUrl.d.ts +2 -0
  34. package/dist/components/UpdateUrl.d.ts.map +1 -0
  35. package/dist/components/warnings/BalanceWarnings.d.ts +7 -0
  36. package/dist/components/warnings/BalanceWarnings.d.ts.map +1 -0
  37. package/dist/components/warnings/ConfirmSwapExtraMessages.d.ts +7 -0
  38. package/dist/components/warnings/ConfirmSwapExtraMessages.d.ts.map +1 -0
  39. package/dist/components/warnings/HighSlippageWarning.d.ts +7 -0
  40. package/dist/components/warnings/HighSlippageWarning.d.ts.map +1 -0
  41. package/dist/components/warnings/MinRequiredSlippage.d.ts +7 -0
  42. package/dist/components/warnings/MinRequiredSlippage.d.ts.map +1 -0
  43. package/dist/constants/errors.d.ts +4 -0
  44. package/dist/constants/errors.d.ts.map +1 -0
  45. package/dist/constants/navigationRoutes.d.ts +15 -0
  46. package/dist/constants/navigationRoutes.d.ts.map +1 -0
  47. package/dist/constants/numbers.d.ts +3 -0
  48. package/dist/constants/numbers.d.ts.map +1 -0
  49. package/dist/constants/searchParams.d.ts +8 -0
  50. package/dist/constants/searchParams.d.ts.map +1 -0
  51. package/dist/constants/swapSettings.d.ts +6 -0
  52. package/dist/constants/swapSettings.d.ts.map +1 -0
  53. package/dist/globalStyles.d.ts +3 -0
  54. package/dist/globalStyles.d.ts.map +1 -0
  55. package/dist/hooks/useConfirmSwap.d.ts +11 -0
  56. package/dist/hooks/useConfirmSwap.d.ts.map +1 -0
  57. package/dist/hooks/useCopyToClipboard.d.ts +2 -0
  58. package/dist/hooks/useCopyToClipboard.d.ts.map +1 -0
  59. package/dist/hooks/useNavigateBack.d.ts +4 -0
  60. package/dist/hooks/useNavigateBack.d.ts.map +1 -0
  61. package/dist/hooks/usePrevious.d.ts +2 -0
  62. package/dist/hooks/usePrevious.d.ts.map +1 -0
  63. package/dist/hooks/useSelectLanguage.d.ts +5 -0
  64. package/dist/hooks/useSelectLanguage.d.ts.map +1 -0
  65. package/dist/hooks/useTheme.d.ts +8 -0
  66. package/dist/hooks/useTheme.d.ts.map +1 -0
  67. package/dist/i18n.d.ts +3 -0
  68. package/dist/i18n.d.ts.map +1 -0
  69. package/dist/index.d.ts +2 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +8 -0
  72. package/dist/lib.d.ts +8 -0
  73. package/dist/lib.d.ts.map +1 -0
  74. package/dist/mockData/pendingSwap.d.ts +2 -0
  75. package/dist/mockData/pendingSwap.d.ts.map +1 -0
  76. package/dist/pages/ConfirmSwapPage.d.ts +3 -0
  77. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -0
  78. package/dist/pages/ConfirmWalletsPage.d.ts +3 -0
  79. package/dist/pages/ConfirmWalletsPage.d.ts.map +1 -0
  80. package/dist/pages/HistoryPage.d.ts +3 -0
  81. package/dist/pages/HistoryPage.d.ts.map +1 -0
  82. package/dist/pages/Home.d.ts +9 -0
  83. package/dist/pages/Home.d.ts.map +1 -0
  84. package/dist/pages/LiquiditySourcesPage.d.ts +8 -0
  85. package/dist/pages/LiquiditySourcesPage.d.ts.map +1 -0
  86. package/dist/pages/SelectChainPage.d.ts +9 -0
  87. package/dist/pages/SelectChainPage.d.ts.map +1 -0
  88. package/dist/pages/SelectTokenPage.d.ts +15 -0
  89. package/dist/pages/SelectTokenPage.d.ts.map +1 -0
  90. package/dist/pages/SettingsPage.d.ts +8 -0
  91. package/dist/pages/SettingsPage.d.ts.map +1 -0
  92. package/dist/pages/SwapDetailsPage.d.ts +3 -0
  93. package/dist/pages/SwapDetailsPage.d.ts.map +1 -0
  94. package/dist/pages/WalletsPage.d.ts +9 -0
  95. package/dist/pages/WalletsPage.d.ts.map +1 -0
  96. package/dist/services/httpService.d.ts +3 -0
  97. package/dist/services/httpService.d.ts.map +1 -0
  98. package/dist/store/bestRoute.d.ts +28 -0
  99. package/dist/store/bestRoute.d.ts.map +1 -0
  100. package/dist/store/meta.d.ts +9 -0
  101. package/dist/store/meta.d.ts.map +1 -0
  102. package/dist/store/selectors.d.ts +11 -0
  103. package/dist/store/selectors.d.ts.map +1 -0
  104. package/dist/store/settings.d.ts +17 -0
  105. package/dist/store/settings.d.ts.map +1 -0
  106. package/dist/store/ui.d.ts +2 -0
  107. package/dist/store/ui.d.ts.map +1 -0
  108. package/dist/store/wallets.d.ts +28 -0
  109. package/dist/store/wallets.d.ts.map +1 -0
  110. package/dist/types/config.d.ts +40 -0
  111. package/dist/types/config.d.ts.map +1 -0
  112. package/dist/types/index.d.ts +4 -0
  113. package/dist/types/index.d.ts.map +1 -0
  114. package/dist/types/routing.d.ts +45 -0
  115. package/dist/types/routing.d.ts.map +1 -0
  116. package/dist/types/swap.d.ts +11 -0
  117. package/dist/types/swap.d.ts.map +1 -0
  118. package/dist/utils/common.d.ts +4 -0
  119. package/dist/utils/common.d.ts.map +1 -0
  120. package/dist/utils/numbers.d.ts +14 -0
  121. package/dist/utils/numbers.d.ts.map +1 -0
  122. package/dist/utils/queue.d.ts +4 -0
  123. package/dist/utils/queue.d.ts.map +1 -0
  124. package/dist/utils/routing.d.ts +18 -0
  125. package/dist/utils/routing.d.ts.map +1 -0
  126. package/dist/utils/swap.d.ts +45 -0
  127. package/dist/utils/swap.d.ts.map +1 -0
  128. package/dist/utils/wallets.d.ts +29 -0
  129. package/dist/utils/wallets.d.ts.map +1 -0
  130. package/dist/widget-embedded.cjs.development.js +3101 -0
  131. package/dist/widget-embedded.cjs.development.js.map +1 -0
  132. package/dist/widget-embedded.cjs.production.min.js +3101 -0
  133. package/dist/widget-embedded.cjs.production.min.js.map +1 -0
  134. package/dist/widget-embedded.esm.js +3092 -0
  135. package/dist/widget-embedded.esm.js.map +1 -0
  136. package/package.json +55 -0
  137. package/readme.md +2 -0
  138. package/src/App.tsx +91 -0
  139. package/src/QueueManager.tsx +94 -0
  140. package/src/app.css +27 -0
  141. package/src/components/AppRouter.tsx +60 -0
  142. package/src/components/AppRoutes.tsx +105 -0
  143. package/src/components/BottomLogo.tsx +47 -0
  144. package/src/components/ChangeSlippageButton.tsx +19 -0
  145. package/src/components/ConfirmSwapErrors.tsx +38 -0
  146. package/src/components/ConfirmSwapWarnings.tsx +35 -0
  147. package/src/components/Footer.tsx +8 -0
  148. package/src/components/Header.tsx +37 -0
  149. package/src/components/HeaderButtons.tsx +47 -0
  150. package/src/components/Layout.tsx +96 -0
  151. package/src/components/RoutesOverview.tsx +60 -0
  152. package/src/components/SwitchFromAndTo.tsx +30 -0
  153. package/src/components/TokenInfo.tsx +311 -0
  154. package/src/components/TokenPreview.tsx +175 -0
  155. package/src/components/UpdateUrl.tsx +162 -0
  156. package/src/components/warnings/BalanceWarnings.tsx +39 -0
  157. package/src/components/warnings/ConfirmSwapExtraMessages.tsx +20 -0
  158. package/src/components/warnings/HighSlippageWarning.tsx +18 -0
  159. package/src/components/warnings/MinRequiredSlippage.tsx +18 -0
  160. package/src/constants/errors.ts +3 -0
  161. package/src/constants/navigationRoutes.ts +14 -0
  162. package/src/constants/numbers.ts +3 -0
  163. package/src/constants/searchParams.ts +7 -0
  164. package/src/constants/swapSettings.ts +9 -0
  165. package/src/globalStyles.ts +26 -0
  166. package/src/hooks/useConfirmSwap.ts +260 -0
  167. package/src/hooks/useCopyToClipboard.ts +23 -0
  168. package/src/hooks/useNavigateBack.ts +40 -0
  169. package/src/hooks/usePrevious.ts +13 -0
  170. package/src/hooks/useSelectLanguage.ts +15 -0
  171. package/src/hooks/useTheme.ts +127 -0
  172. package/src/i18n.js +30 -0
  173. package/src/index.tsx +14 -0
  174. package/src/languages/en.json +14 -0
  175. package/src/languages/tr.json +11 -0
  176. package/src/lib.tsx +119 -0
  177. package/src/mockData/pendingSwap.ts +607 -0
  178. package/src/pages/ConfirmSwapPage.tsx +72 -0
  179. package/src/pages/ConfirmWalletsPage.tsx +127 -0
  180. package/src/pages/HistoryPage.tsx +29 -0
  181. package/src/pages/Home.tsx +228 -0
  182. package/src/pages/LiquiditySourcesPage.tsx +64 -0
  183. package/src/pages/SelectChainPage.tsx +42 -0
  184. package/src/pages/SelectTokenPage.tsx +64 -0
  185. package/src/pages/SettingsPage.tsx +98 -0
  186. package/src/pages/SwapDetailsPage.tsx +38 -0
  187. package/src/pages/WalletsPage.tsx +119 -0
  188. package/src/services/httpService.ts +5 -0
  189. package/src/store/bestRoute.ts +245 -0
  190. package/src/store/meta.ts +35 -0
  191. package/src/store/selectors.ts +19 -0
  192. package/src/store/settings.ts +84 -0
  193. package/src/store/ui.ts +21 -0
  194. package/src/store/wallets.ts +190 -0
  195. package/src/types/config.ts +44 -0
  196. package/src/types/index.ts +3 -0
  197. package/src/types/routing.ts +60 -0
  198. package/src/types/swap.ts +13 -0
  199. package/src/utils/common.ts +35 -0
  200. package/src/utils/numbers.ts +133 -0
  201. package/src/utils/queue.ts +24 -0
  202. package/src/utils/routing.ts +150 -0
  203. package/src/utils/swap.ts +552 -0
  204. package/src/utils/wallets.ts +481 -0
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@rango-dev/widget-embedded",
3
+ "version": "0.1.10-next.100",
4
+ "license": "MIT",
5
+ "main": "dist/index.js",
6
+ "typings": "dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "src"
10
+ ],
11
+ "browserslist": "> 0.5%, last 2 versions, not dead",
12
+ "scripts": {
13
+ "dev": "parcel public/index.html -p 3001",
14
+ "build:app": "parcel build",
15
+ "build": "tsdx build --entry ./src/lib.tsx"
16
+ },
17
+ "husky": {
18
+ "hooks": {
19
+ "pre-commit": "tsdx lint"
20
+ }
21
+ },
22
+ "prettier": {
23
+ "printWidth": 80,
24
+ "semi": true,
25
+ "singleQuote": true,
26
+ "trailingComma": "es5"
27
+ },
28
+ "dependencies": {
29
+ "@rango-dev/provider-all": "^0.1.11-next.79",
30
+ "@rango-dev/queue-manager-core": "^0.1.10-next.75",
31
+ "@rango-dev/queue-manager-rango-preset": "^0.1.10-next.77",
32
+ "@rango-dev/queue-manager-react": "^0.1.10-next.73",
33
+ "@rango-dev/ui": "^0.1.10-next.75",
34
+ "@rango-dev/wallets-core": "^0.1.11-next.80",
35
+ "@rango-dev/wallets-shared": "^0.1.11-next.78",
36
+ "bignumber.js": "^9.1.1",
37
+ "copy-to-clipboard": "^3.3.3",
38
+ "i18next": "^22.4.11",
39
+ "i18next-browser-languagedetector": "^7.0.1",
40
+ "i18next-http-backend": "^2.1.1",
41
+ "immer": "^9.0.19",
42
+ "mitt": "^3.0.0",
43
+ "parcel": "^2.8.0",
44
+ "rango-sdk": "^0.1.19",
45
+ "rango-types": "^0.1.23",
46
+ "react": "^18.2.0",
47
+ "react-dom": "^18.2.0",
48
+ "react-i18next": "^12.2.0",
49
+ "react-router-dom": "^6.8.0",
50
+ "zustand": "^4.3.2"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ }
55
+ }
package/readme.md ADDED
@@ -0,0 +1,2 @@
1
+
2
+ Widget will use `components`, `queues` and `wallets` to make a react app to be embedded as widget.
package/src/App.tsx ADDED
@@ -0,0 +1,91 @@
1
+ import { SwapContainer } from '@rango-dev/ui';
2
+ import React from 'react';
3
+ import { AppRouter } from './components/AppRouter';
4
+ import { useMetaStore } from './store/meta';
5
+ import './app.css';
6
+ import { Events, Provider } from '@rango-dev/wallets-core';
7
+ import { allProviders } from '@rango-dev/provider-all';
8
+ import { EventHandler } from '@rango-dev/wallets-core/dist/wallet';
9
+ import { Network } from '@rango-dev/wallets-shared';
10
+ import {
11
+ prepareAccountsForWalletStore,
12
+ walletAndSupportedChainsNames,
13
+ } from './utils/wallets';
14
+ import { useWalletsStore } from './store/wallets';
15
+ import { Layout } from './components/Layout';
16
+ import { globalFont, globalStyles } from './globalStyles';
17
+ import { useTheme } from './hooks/useTheme';
18
+ import QueueManager from './QueueManager';
19
+ import { isEvmBlockchain } from 'rango-sdk';
20
+ import { Configs } from './types';
21
+ import './i18n';
22
+
23
+ const providers = allProviders();
24
+
25
+ //todo: update interface and update widget state based on WidgetProps change
26
+ export type WidgetProps = {
27
+ configs?: Configs;
28
+ };
29
+
30
+ export function App({ configs }: WidgetProps) {
31
+ globalStyles();
32
+ globalFont(configs?.fontFamily || 'Roboto');
33
+ const { activeTheme } = useTheme({
34
+ ...configs?.colors,
35
+ borderRadius: configs?.borderRadius,
36
+ });
37
+
38
+ const { blockchains } = useMetaStore.use.meta();
39
+ const disconnectWallet = useWalletsStore.use.disconnectWallet();
40
+ const connectWallet = useWalletsStore.use.connectWallet();
41
+
42
+ const evmBasedChainNames = blockchains
43
+ .filter(isEvmBlockchain)
44
+ .map((chain) => chain.name);
45
+
46
+ const onUpdateState: EventHandler = (
47
+ type,
48
+ event,
49
+ value,
50
+ _,
51
+ supportedChains
52
+ ) => {
53
+ if (event === Events.ACCOUNTS) {
54
+ if (value) {
55
+ const supportedChainNames: Network[] | null =
56
+ walletAndSupportedChainsNames(supportedChains);
57
+ const data = prepareAccountsForWalletStore(
58
+ type,
59
+ value,
60
+ evmBasedChainNames,
61
+ supportedChainNames
62
+ );
63
+ connectWallet(data);
64
+ } else {
65
+ disconnectWallet(type);
66
+ }
67
+ }
68
+ };
69
+
70
+ return (
71
+ <Provider
72
+ allBlockChains={blockchains}
73
+ providers={providers}
74
+ onUpdateState={onUpdateState}
75
+ >
76
+ <div id="pageContainer" className={activeTheme}>
77
+ <QueueManager>
78
+ <SwapContainer>
79
+ <AppRouter
80
+ title={configs?.title}
81
+ titleSize={configs?.titleSize}
82
+ titleWeight={configs?.titleWeight}
83
+ >
84
+ <Layout configs={configs} />
85
+ </AppRouter>
86
+ </SwapContainer>
87
+ </QueueManager>
88
+ </div>
89
+ </Provider>
90
+ );
91
+ }
@@ -0,0 +1,94 @@
1
+ import React, { PropsWithChildren } from 'react';
2
+ import { Provider as ManagerProvider } from '@rango-dev/queue-manager-react';
3
+ import {
4
+ swapQueueDef,
5
+ SwapQueueContext,
6
+ } from '@rango-dev/queue-manager-rango-preset';
7
+ import { useWallets } from '@rango-dev/wallets-core';
8
+ import {
9
+ convertEvmBlockchainMetaToEvmChainInfo,
10
+ Network,
11
+ WalletType,
12
+ } from '@rango-dev/wallets-shared';
13
+ import { useMetaStore } from './store/meta';
14
+ import { useWalletsStore } from './store/wallets';
15
+ import { walletAndSupportedChainsNames } from './utils/wallets';
16
+ import { isEvmBlockchain } from 'rango-sdk';
17
+
18
+ function QueueManager(props: PropsWithChildren<{}>) {
19
+ const {
20
+ providers,
21
+ getSigners,
22
+ state,
23
+ connect,
24
+ canSwitchNetworkTo,
25
+ getWalletInfo,
26
+ } = useWallets();
27
+
28
+ const { blockchains } = useMetaStore.use.meta();
29
+ const balances = useWalletsStore.use.balances();
30
+
31
+ const wallets = {
32
+ blockchains: balances.map((wallet) => ({
33
+ accounts: [wallet],
34
+ name: wallet.chain,
35
+ })),
36
+ };
37
+
38
+ const switchNetwork = (wallet: WalletType, network: Network) => {
39
+ if (!canSwitchNetworkTo(wallet, network)) {
40
+ return undefined;
41
+ }
42
+ return connect(wallet, network);
43
+ };
44
+
45
+ // TODO: this code copy & pasted from rango, should be refactored.
46
+ const allBlockchains = blockchains
47
+ .filter((blockchain) => blockchain.enabled)
48
+ .reduce(
49
+ (blockchainsObj, blockchain) => (
50
+ (blockchainsObj[blockchain.name] = blockchain), blockchainsObj
51
+ ),
52
+ {}
53
+ );
54
+ const evmBasedChains = blockchains.filter(isEvmBlockchain);
55
+ const getSupportedChainNames = (type: WalletType) => {
56
+ const { supportedChains } = getWalletInfo(type);
57
+ return walletAndSupportedChainsNames(supportedChains);
58
+ };
59
+ const allProviders = providers();
60
+ const context: SwapQueueContext = {
61
+ meta: {
62
+ blockchains: allBlockchains,
63
+ evmBasedChains: evmBasedChains,
64
+ evmNetworkChainInfo:
65
+ convertEvmBlockchainMetaToEvmChainInfo(evmBasedChains),
66
+ getSupportedChainNames,
67
+ },
68
+ getSigners,
69
+ //todo: remove Network type
70
+ //@ts-ignore
71
+ wallets,
72
+ providers: allProviders,
73
+ switchNetwork,
74
+ connect,
75
+ state,
76
+ notifier: (message) => {
77
+ console.log('[notifier]', message);
78
+ },
79
+ };
80
+
81
+ return (
82
+ <ManagerProvider
83
+ //@ts-ignore
84
+ queuesDefs={[swapQueueDef]}
85
+ context={context}
86
+ onPersistedDataLoaded={(_manager) => {}}
87
+ isPaused={false}
88
+ >
89
+ {props.children}
90
+ </ManagerProvider>
91
+ );
92
+ }
93
+
94
+ export default QueueManager;
package/src/app.css ADDED
@@ -0,0 +1,27 @@
1
+ @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');
2
+ * {
3
+ box-sizing: border-box;
4
+ margin: 0;
5
+ padding: 0;
6
+ list-style-type: none;
7
+ }
8
+
9
+ input::-webkit-outer-spin-button,
10
+ input::-webkit-inner-spin-button {
11
+ -webkit-appearance: none;
12
+ margin: 0;
13
+ }
14
+ input[type='number'] {
15
+ -moz-appearance: textfield;
16
+ }
17
+
18
+ #app {
19
+ height: 100vh;
20
+ }
21
+ #pageContainer {
22
+ display: flex;
23
+ align-items: center;
24
+ justify-content: center;
25
+ height: 100%;
26
+ width: 100%;
27
+ }
@@ -0,0 +1,60 @@
1
+ import React, { PropsWithChildren, useEffect, useRef } from 'react';
2
+ import {
3
+ MemoryRouter,
4
+ useInRouterContext,
5
+ useLocation,
6
+ useNavigate,
7
+ } from 'react-router';
8
+ import { navigationRoutes } from '../constants/navigationRoutes';
9
+ import { UpdateUrl } from './UpdateUrl';
10
+ import { Home } from '../pages/Home';
11
+ interface PropTypes {
12
+ title?: string;
13
+ titleSize?: number;
14
+ titleWeight?: number;
15
+ }
16
+ const Route: React.FC = ({
17
+ children,
18
+ ...props
19
+ }: PropTypes & PropsWithChildren) => {
20
+ const location = useLocation();
21
+ const navigate = useNavigate();
22
+ const ref = useRef(true);
23
+
24
+ useEffect(() => {
25
+ if (
26
+ [navigationRoutes.confirmWallets, navigationRoutes.confirmSwap].includes(
27
+ location.pathname
28
+ ) &&
29
+ ref.current
30
+ )
31
+ navigate(navigationRoutes.home + location.search, { state: 'redirect' });
32
+
33
+ ref.current = false;
34
+ }, []);
35
+
36
+ if (
37
+ [navigationRoutes.confirmWallets, navigationRoutes.confirmSwap].includes(
38
+ location.pathname
39
+ ) &&
40
+ ref.current
41
+ )
42
+ return <Home {...props} />;
43
+
44
+ return <> {children}</>;
45
+ };
46
+
47
+ export function AppRouter({
48
+ children,
49
+ ...props
50
+ }: PropTypes & PropsWithChildren) {
51
+ const isRouterInContext = useInRouterContext();
52
+ const Router = isRouterInContext ? Route : MemoryRouter;
53
+
54
+ return (
55
+ <>
56
+ <Router {...props}>{children}</Router>
57
+ {isRouterInContext && <UpdateUrl />}
58
+ </>
59
+ );
60
+ }
@@ -0,0 +1,105 @@
1
+ import React from 'react';
2
+ import { useRoutes } from 'react-router-dom';
3
+ import { navigationRoutes } from '../constants/navigationRoutes';
4
+ import { ConfirmSwapPage } from '../pages/ConfirmSwapPage';
5
+ import { HistoryPage } from '../pages/HistoryPage';
6
+ import { Home } from '../pages/Home';
7
+ import { LiquiditySourcePage } from '../pages/LiquiditySourcesPage';
8
+ import { SelectChainPage } from '../pages/SelectChainPage';
9
+ import { SelectTokenPage } from '../pages/SelectTokenPage';
10
+ import { SettingsPage } from '../pages/SettingsPage';
11
+ import { WalletsPage } from '../pages/WalletsPage';
12
+ import { ConfirmWalletsPage } from '../pages/ConfirmWalletsPage';
13
+ import { SwapDetailsPage } from '../pages/SwapDetailsPage';
14
+ import { Configs } from '../types';
15
+
16
+ interface PropTypes {
17
+ configs?: Configs;
18
+ }
19
+
20
+ export function AppRoutes(props: PropTypes) {
21
+ const { configs } = props;
22
+
23
+ return useRoutes([
24
+ {
25
+ path: navigationRoutes.home,
26
+ element: (
27
+ <Home
28
+ title={configs?.title}
29
+ titleSize={configs?.titleSize}
30
+ titleWeight={configs?.titleWeight}
31
+ />
32
+ ),
33
+ },
34
+ {
35
+ path: navigationRoutes.fromChain,
36
+ element: (
37
+ <SelectChainPage
38
+ type="from"
39
+ supportedChains={configs?.fromChains || 'all'}
40
+ />
41
+ ),
42
+ },
43
+ {
44
+ path: navigationRoutes.toChain,
45
+ element: (
46
+ <SelectChainPage
47
+ type="to"
48
+ supportedChains={configs?.toChains || 'all'}
49
+ />
50
+ ),
51
+ },
52
+ {
53
+ path: navigationRoutes.fromToken + '/*',
54
+ element: (
55
+ <SelectTokenPage
56
+ type="from"
57
+ supportedTokens={configs?.fromTokens || 'all'}
58
+ />
59
+ ),
60
+ },
61
+ {
62
+ path: navigationRoutes.toToken,
63
+ element: (
64
+ <SelectTokenPage
65
+ type="to"
66
+ supportedTokens={configs?.toTokens || 'all'}
67
+ />
68
+ ),
69
+ },
70
+ {
71
+ path: navigationRoutes.settings,
72
+ element: (
73
+ <SettingsPage supportedSwappers={configs?.liquiditySources || 'all'} />
74
+ ),
75
+ },
76
+ {
77
+ path: navigationRoutes.liquiditySources,
78
+ element: (
79
+ <LiquiditySourcePage
80
+ supportedSwappers={configs?.liquiditySources || 'all'}
81
+ />
82
+ ),
83
+ },
84
+ { path: navigationRoutes.swaps, element: <HistoryPage /> },
85
+ {
86
+ path: navigationRoutes.swapDetails,
87
+ element: <SwapDetailsPage />,
88
+ },
89
+ {
90
+ path: navigationRoutes.wallets,
91
+ element: (
92
+ <WalletsPage
93
+ supportedWallets={configs?.wallets || 'all'}
94
+ multiWallets={
95
+ typeof configs?.multiWallets === 'undefined'
96
+ ? true
97
+ : configs.multiWallets
98
+ }
99
+ />
100
+ ),
101
+ },
102
+ { path: navigationRoutes.confirmSwap, element: <ConfirmSwapPage /> },
103
+ { path: navigationRoutes.confirmWallets, element: <ConfirmWalletsPage /> },
104
+ ]);
105
+ }
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+ import { styled } from '@rango-dev/ui/src/theme';
3
+ import { Typography } from '@rango-dev/ui';
4
+ import { useTranslation } from 'react-i18next';
5
+
6
+ const Container = styled('div', {
7
+ display: 'flex',
8
+ width: '100%',
9
+ justifyContent: 'end',
10
+ alignItems: 'center',
11
+ paddingTop: '$16',
12
+ });
13
+
14
+ const Logo = styled('svg', {
15
+ fill: '$foreground',
16
+ width: '$24',
17
+ margin: '0 $8 0 $16',
18
+ });
19
+
20
+ const StyledAnchor = styled('a', {
21
+ display: 'flex',
22
+ justifyContent: 'center',
23
+ alignItems: 'center',
24
+ textDecoration: 'none',
25
+ });
26
+
27
+ export function BottomLogo() {
28
+ const { t } = useTranslation();
29
+
30
+ return (
31
+ <Container>
32
+ <Typography variant="caption">{t('Powered By')}</Typography>
33
+ <StyledAnchor href="https://rango.exchange" target="_blank">
34
+ <Logo xmlns="http://www.w3.org/2000/svg" viewBox="0 0 33.68 29">
35
+ <defs></defs>
36
+ <g id="Layer_2" data-name="Layer 2">
37
+ <g id="Layer_1-2" data-name="Layer 1">
38
+ <path d="M33.68,18.05A17.93,17.93,0,0,0,28.34,5.29,18.31,18.31,0,0,0,15.45,0H13.54V7.41L6.07,0H.69L9.83,9.07H0V11A17.93,17.93,0,0,0,5.34,23.71,18.32,18.32,0,0,0,18.24,29h1.9V21.59l7.38,7.31h5.39l-9-9h9.82ZM17.37,16.16H12.49a1.93,1.93,0,0,0-1.35.55,1.89,1.89,0,0,0-.56,1.34,1.85,1.85,0,0,0,.56,1.33,1.93,1.93,0,0,0,1.35.55h3.84V25.1A14.43,14.43,0,0,1,8,21a14.21,14.21,0,0,1-4.1-8.2H21.2a1.86,1.86,0,0,0,.74-.13,1.92,1.92,0,0,0,.64-.4,2,2,0,0,0,.43-.62,1.88,1.88,0,0,0,0-1.47,2,2,0,0,0-.43-.62,1.92,1.92,0,0,0-.64-.4,1.86,1.86,0,0,0-.74-.13H17.35V3.9A14.43,14.43,0,0,1,25.64,8a14.19,14.19,0,0,1,4.11,8.2Zm2.12-5.27a1.43,1.43,0,0,1,.26-.83,1.52,1.52,0,0,1,.67-.56,1.55,1.55,0,0,1,.88-.08,1.51,1.51,0,0,1,.77.4,1.54,1.54,0,0,1,.42.77,1.41,1.41,0,0,1-.09.86,1.47,1.47,0,0,1-.55.68,1.56,1.56,0,0,1-.84.25,1.52,1.52,0,0,1-1.52-1.49Z" />
39
+ <path d="M21.7,11.57a.68.68,0,0,0-.12-.38.64.64,0,0,0-.31-.25.68.68,0,0,0-.75.15.61.61,0,0,0-.19.35.62.62,0,0,0,0,.4.67.67,0,0,0,.25.3.69.69,0,0,0,.39.12.7.7,0,0,0,.49-.2A.68.68,0,0,0,21.7,11.57Z" />
40
+ </g>
41
+ </g>
42
+ </Logo>
43
+ <Typography variant="body2">RANGO</Typography>
44
+ </StyledAnchor>
45
+ </Container>
46
+ );
47
+ }
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { Button } from '@rango-dev/ui';
3
+ import { useNavigate } from 'react-router-dom';
4
+ import { navigationRoutes } from '../constants/navigationRoutes';
5
+
6
+ export function ChangeSlippageButton() {
7
+ const navigate = useNavigate();
8
+
9
+ return (
10
+ <Button
11
+ type="primary"
12
+ variant="outlined"
13
+ size="small"
14
+ onClick={() => navigate(navigationRoutes.settings)}
15
+ >
16
+ Change Slippage
17
+ </Button>
18
+ );
19
+ }
@@ -0,0 +1,38 @@
1
+ import React from 'react';
2
+ import { Typography } from '@rango-dev/ui';
3
+ import { ConfirmSwapError, ConfirmSwapErrorTypes } from '../types';
4
+ import { MinRequiredSlippage } from './warnings/MinRequiredSlippage';
5
+
6
+ export function ConfirmSwapErrors(errors: ConfirmSwapError[]) {
7
+ return errors.flatMap((error) => {
8
+ switch (error.type) {
9
+ case ConfirmSwapErrorTypes.NO_ROUTE:
10
+ return (
11
+ <Typography variant="body2">
12
+ No routes found. Please try again later.
13
+ </Typography>
14
+ );
15
+ case ConfirmSwapErrorTypes.REQUEST_FAILED:
16
+ return (
17
+ <Typography variant="body2">{`Failed to confirm swap ${
18
+ error.status ? `'status': ${error.status})` : ''
19
+ }, please try again.`}</Typography>
20
+ );
21
+
22
+ case ConfirmSwapErrorTypes.ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS:
23
+ return (
24
+ <Typography variant="body2">
25
+ Route updated and price impact is too high, try again later!
26
+ </Typography>
27
+ );
28
+ case ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE:
29
+ return (
30
+ <MinRequiredSlippage
31
+ minRequiredSlippage={error.minRequiredSlippage}
32
+ />
33
+ );
34
+ default:
35
+ return [];
36
+ }
37
+ });
38
+ }
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ import { Typography } from '@rango-dev/ui';
3
+ import { ConfirmSwapWarningTypes, ConfirmSwapWarnings } from '../types';
4
+ import { BalanceWarnings } from './warnings/BalanceWarnings';
5
+
6
+ export function ConfirmSwapWarnings(warnings: ConfirmSwapWarnings[]) {
7
+ return warnings.flatMap((warning) => {
8
+ switch (warning.type) {
9
+ case ConfirmSwapWarningTypes.ROUTE_UPDATED:
10
+ return <Typography variant="body2">Route has been updated.</Typography>;
11
+ case ConfirmSwapWarningTypes.ROUTE_AND_OUTPUT_AMOUNT_UPDATED:
12
+ return (
13
+ <Typography variant="body2">{`Output amount changed to ${warning.newOutputAmount}
14
+ (${warning.percentageChange}% change).`}</Typography>
15
+ );
16
+
17
+ case ConfirmSwapWarningTypes.ROUTE_SWAPPERS_UPDATED:
18
+ return (
19
+ <Typography variant="body2">
20
+ Route swappers has been updated.
21
+ </Typography>
22
+ );
23
+ case ConfirmSwapWarningTypes.ROUTE_COINS_UPDATED:
24
+ return (
25
+ <Typography variant="body2">
26
+ Route internal coins has been updated.
27
+ </Typography>
28
+ );
29
+ case ConfirmSwapWarningTypes.INSUFFICIENT_BALANCE:
30
+ return <BalanceWarnings messages={warning.messages} />;
31
+ default:
32
+ return [];
33
+ }
34
+ });
35
+ }
@@ -0,0 +1,8 @@
1
+ import { styled } from '@rango-dev/ui';
2
+
3
+ export const Footer = styled('div', {
4
+ display: 'flex',
5
+ flexDirection: 'column',
6
+ width: '100%',
7
+ paddingTop: '$16',
8
+ });
@@ -0,0 +1,37 @@
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
+ }
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+ import {
3
+ SettingsIcon,
4
+ Tooltip,
5
+ styled,
6
+ Button,
7
+ HistoryIcon,
8
+ RetryIcon,
9
+ } from '@rango-dev/ui';
10
+ import { useNavigate } from 'react-router-dom';
11
+ import { navigationRoutes } from '../constants/navigationRoutes';
12
+ import { PropTypes } from './Header';
13
+
14
+ const ButtonsContainer = styled('div', {
15
+ display: 'flex',
16
+ });
17
+
18
+ export function HeaderButtons(props: PropTypes) {
19
+ const { onClickRefresh } = props;
20
+ const navigate = useNavigate();
21
+
22
+ return (
23
+ <ButtonsContainer>
24
+ <Tooltip content="Refresh">
25
+ <Button variant="ghost" onClick={onClickRefresh}>
26
+ <RetryIcon size={24} />
27
+ </Button>
28
+ </Tooltip>
29
+ <Tooltip content="Transactions History">
30
+ <Button
31
+ variant="ghost"
32
+ onClick={() => navigate(navigationRoutes.swaps)}
33
+ >
34
+ <HistoryIcon size={24} />
35
+ </Button>
36
+ </Tooltip>
37
+ <Tooltip content="Settings">
38
+ <Button
39
+ variant="ghost"
40
+ onClick={() => navigate(navigationRoutes.settings)}
41
+ >
42
+ <SettingsIcon size={24} />
43
+ </Button>
44
+ </Tooltip>
45
+ </ButtonsContainer>
46
+ );
47
+ }