@rango-dev/widget-embedded 0.1.11-next.0 → 0.1.11-next.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.
Files changed (77) hide show
  1. package/dist/App.d.ts +3 -3
  2. package/dist/App.d.ts.map +1 -1
  3. package/dist/QueueManager.d.ts.map +1 -1
  4. package/dist/components/AppRouter.d.ts +1 -7
  5. package/dist/components/AppRouter.d.ts.map +1 -1
  6. package/dist/components/AppRoutes.d.ts +2 -2
  7. package/dist/components/AppRoutes.d.ts.map +1 -1
  8. package/dist/components/Layout.d.ts +3 -3
  9. package/dist/components/Layout.d.ts.map +1 -1
  10. package/dist/components/TokenInfo.d.ts.map +1 -1
  11. package/dist/components/TokenPreview.d.ts.map +1 -1
  12. package/dist/hooks/useConfirmSwap.d.ts.map +1 -1
  13. package/dist/hooks/useTheme.d.ts +2 -5
  14. package/dist/hooks/useTheme.d.ts.map +1 -1
  15. package/dist/lib.d.ts +2 -2
  16. package/dist/lib.d.ts.map +1 -1
  17. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  18. package/dist/pages/Home.d.ts +1 -7
  19. package/dist/pages/Home.d.ts.map +1 -1
  20. package/dist/pages/LiquiditySourcesPage.d.ts +1 -2
  21. package/dist/pages/LiquiditySourcesPage.d.ts.map +1 -1
  22. package/dist/pages/SelectChainPage.d.ts +1 -2
  23. package/dist/pages/SelectChainPage.d.ts.map +1 -1
  24. package/dist/pages/SelectTokenPage.d.ts +2 -2
  25. package/dist/pages/SelectTokenPage.d.ts.map +1 -1
  26. package/dist/pages/SettingsPage.d.ts +1 -2
  27. package/dist/pages/SettingsPage.d.ts.map +1 -1
  28. package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
  29. package/dist/pages/WalletsPage.d.ts +1 -1
  30. package/dist/pages/WalletsPage.d.ts.map +1 -1
  31. package/dist/services/httpService.d.ts +2 -1
  32. package/dist/services/httpService.d.ts.map +1 -1
  33. package/dist/store/bestRoute.d.ts.map +1 -1
  34. package/dist/store/meta.d.ts.map +1 -1
  35. package/dist/store/settings.d.ts +2 -0
  36. package/dist/store/settings.d.ts.map +1 -1
  37. package/dist/types/config.d.ts +27 -29
  38. package/dist/types/config.d.ts.map +1 -1
  39. package/dist/utils/configs.d.ts +7 -0
  40. package/dist/utils/configs.d.ts.map +1 -0
  41. package/dist/utils/swap.d.ts +2 -6
  42. package/dist/utils/swap.d.ts.map +1 -1
  43. package/dist/widget-embedded.cjs.development.js +138 -189
  44. package/dist/widget-embedded.cjs.development.js.map +1 -1
  45. package/dist/widget-embedded.cjs.production.min.js +138 -189
  46. package/dist/widget-embedded.cjs.production.min.js.map +1 -1
  47. package/dist/widget-embedded.esm.js +138 -189
  48. package/dist/widget-embedded.esm.js.map +1 -1
  49. package/package.json +6 -4
  50. package/readme.md +1 -1
  51. package/src/App.tsx +36 -14
  52. package/src/QueueManager.tsx +9 -3
  53. package/src/components/AppRouter.tsx +7 -16
  54. package/src/components/AppRoutes.tsx +13 -32
  55. package/src/components/HeaderButtons.tsx +1 -1
  56. package/src/components/Layout.tsx +37 -27
  57. package/src/components/TokenInfo.tsx +4 -8
  58. package/src/components/TokenPreview.tsx +3 -7
  59. package/src/hooks/useConfirmSwap.ts +6 -5
  60. package/src/hooks/useTheme.ts +21 -9
  61. package/src/lib.tsx +30 -36
  62. package/src/pages/ConfirmSwapPage.tsx +2 -0
  63. package/src/pages/Home.tsx +2 -8
  64. package/src/pages/LiquiditySourcesPage.tsx +3 -6
  65. package/src/pages/SelectChainPage.tsx +6 -6
  66. package/src/pages/SelectTokenPage.tsx +16 -18
  67. package/src/pages/SettingsPage.tsx +8 -18
  68. package/src/pages/SwapDetailsPage.tsx +2 -4
  69. package/src/pages/WalletsPage.tsx +2 -2
  70. package/src/services/httpService.ts +12 -3
  71. package/src/store/bestRoute.ts +4 -3
  72. package/src/store/meta.ts +6 -4
  73. package/src/store/settings.ts +7 -0
  74. package/src/store/wallets.ts +1 -1
  75. package/src/types/config.ts +28 -29
  76. package/src/utils/configs.ts +24 -0
  77. package/src/utils/swap.ts +3 -96
package/src/lib.tsx CHANGED
@@ -15,35 +15,31 @@ import { Layout } from './components/Layout';
15
15
  import { globalFont, globalStyles } from './globalStyles';
16
16
  import { useTheme } from './hooks/useTheme';
17
17
  import { isEvmBlockchain } from 'rango-sdk';
18
- import { Configs } from './types';
19
- import { useSettingsStore } from './store/settings';
18
+ import { WidgetConfig } from './types';
20
19
  import useSelectLanguage from './hooks/useSelectLanguage';
21
20
  import './i18n';
22
21
  import QueueManager from './QueueManager';
22
+ import { useUiStore } from './store/ui';
23
+ import { navigationRoutes } from './constants/navigationRoutes';
23
24
 
24
25
  export type WidgetProps = {
25
- configs: Configs;
26
+ config?: WidgetConfig;
26
27
  };
27
28
 
28
- export const SwapBox: React.FC<WidgetProps> = ({ configs }) => {
29
+ export const SwapBox: React.FC<WidgetProps> = ({ config }) => {
29
30
  globalStyles();
30
- globalFont(configs?.fontFamily || 'Roboto');
31
+ globalFont(config?.theme?.fontFamily || 'Roboto');
31
32
 
32
- const { activeTheme } = useTheme({
33
- ...configs.colors,
34
- borderRadius: configs?.borderRadius,
35
- fontFamily: configs?.fontFamily,
36
- });
33
+ const { activeTheme } = useTheme({ ...config?.theme });
37
34
  const { blockchains } = useMetaStore.use.meta();
38
35
  const disconnectWallet = useWalletsStore.use.disconnectWallet();
39
36
  const connectWallet = useWalletsStore.use.connectWallet();
40
- const setTheme = useSettingsStore.use.setTheme();
41
37
  const { changeLanguage } = useSelectLanguage();
42
38
  const clearConnectedWallet = useWalletsStore.use.clearConnectedWallet();
43
-
44
39
  const [lastConnectedWalletWithNetwork, setLastConnectedWalletWithNetwork] =
45
40
  useState<string>('');
46
41
  const [disconnectedWallet, setDisconnectedWallet] = useState<WalletType>();
42
+ const currentPage = useUiStore.use.currentPage();
47
43
 
48
44
  const evmBasedChainNames = blockchains
49
45
  .filter(isEvmBlockchain)
@@ -71,7 +67,6 @@ export const SwapBox: React.FC<WidgetProps> = ({ configs }) => {
71
67
  disconnectWallet(type);
72
68
  }
73
69
  }
74
-
75
70
  if (event === Events.ACCOUNTS && state.connected) {
76
71
  const key = `${type}-${state.network}-${value}`;
77
72
 
@@ -88,24 +83,19 @@ export const SwapBox: React.FC<WidgetProps> = ({ configs }) => {
88
83
  let providers = allProviders();
89
84
 
90
85
  useEffect(() => {
91
- if (configs.theme !== 'auto') setTheme(configs.theme);
92
- }, [configs.theme]);
93
-
94
- useEffect(() => {
95
- const wallets = configs.wallets;
86
+ const wallets = config?.wallets;
96
87
  clearConnectedWallet();
97
- providers =
98
- wallets === 'all'
99
- ? allProviders()
100
- : allProviders().filter((provider) => {
101
- const type = provider.config.type;
102
- return wallets.find((w) => w === type);
103
- });
104
- }, [configs?.wallets]);
88
+ providers = !wallets
89
+ ? allProviders()
90
+ : allProviders().filter((provider) => {
91
+ const type = provider.config.type;
92
+ return wallets.find((w) => w === type);
93
+ });
94
+ }, [config?.wallets]);
105
95
 
106
96
  useEffect(() => {
107
- changeLanguage(configs?.languege);
108
- }, [configs?.languege]);
97
+ changeLanguage(config?.language || 'en');
98
+ }, [config?.language]);
109
99
 
110
100
  return (
111
101
  <Provider
@@ -116,22 +106,26 @@ export const SwapBox: React.FC<WidgetProps> = ({ configs }) => {
116
106
  <div id="pageContainer" className={activeTheme}>
117
107
  <QueueManager>
118
108
  <SwapContainer
119
- style={{
120
- width: configs?.width || 'auto',
121
- height: configs?.height || 'auto',
122
- }}
109
+ fixedHeight={currentPage !== navigationRoutes.home}
110
+ // style={
111
+ // currentPage !== navigationRoutes.home && config?.theme?.height
112
+ // ? {
113
+ // height: config?.theme?.height,
114
+ // width: config?.theme?.width || 'auto',
115
+ // }
116
+ // : {
117
+ // width: config?.theme?.width || 'auto',
118
+ // }
119
+ // }
123
120
  >
124
121
  <AppRouter
125
- title={configs.title}
126
- titleSize={configs.titleSize}
127
- titleWeight={configs.titleWeight}
128
122
  lastConnectedWallet={lastConnectedWalletWithNetwork}
129
123
  disconnectedWallet={disconnectedWallet}
130
124
  clearDisconnectedWallet={() => {
131
125
  setDisconnectedWallet(undefined);
132
126
  }}
133
127
  >
134
- <Layout configs={configs} />
128
+ <Layout config={config} />
135
129
  </AppRouter>
136
130
  </SwapContainer>
137
131
  </QueueManager>
@@ -96,6 +96,7 @@ export function ConfirmSwapPage() {
96
96
 
97
97
  return (
98
98
  <ConfirmSwap
99
+ // @ts-ignore
99
100
  requiredWallets={getRequiredChains(bestRoute)}
100
101
  selectableWallets={selectableWallets}
101
102
  onBack={navigateBackFrom.bind(null, navigationRoutes.confirmSwap)}
@@ -105,6 +106,7 @@ export function ConfirmSwapPage() {
105
106
  manager?.create(
106
107
  'swap',
107
108
  { swapDetails: swap },
109
+ // @ts-ignore
108
110
  { id: swap.requestId }
109
111
  );
110
112
  setSelectedSwap(swap.requestId);
@@ -63,14 +63,8 @@ const Alerts = styled('div', {
63
63
  width: '100%',
64
64
  paddingTop: '$16',
65
65
  });
66
- interface PropTypes {
67
- title?: string;
68
- titleSize?: number;
69
- titleWeight?: number;
70
- }
71
- export function Home(props: PropTypes) {
72
- const { title = 'SWAP' } = props;
73
66
 
67
+ export function Home() {
74
68
  const isRouterInContext = useInRouterContext();
75
69
  const navigate = useNavigate();
76
70
  const [count, setCount] = useState(0);
@@ -142,7 +136,7 @@ export function Home(props: PropTypes) {
142
136
  return (
143
137
  <Container>
144
138
  <Header
145
- title={title}
139
+ title="SWAP"
146
140
  suffix={
147
141
  <HeaderButtons
148
142
  onClickRefresh={!!bestRoute ? fetchBestRoute : undefined}
@@ -4,10 +4,9 @@ import { navigationRoutes } from '../constants/navigationRoutes';
4
4
  import { useNavigateBack } from '../hooks/useNavigateBack';
5
5
  import { useMetaStore } from '../store/meta';
6
6
  import { useSettingsStore } from '../store/settings';
7
- import { Source } from '../types';
8
7
  import { removeDuplicateFrom } from '../utils/common';
9
8
  interface PropTypes {
10
- supportedSwappers: 'all' | Source[];
9
+ supportedSwappers?: string[];
11
10
  }
12
11
  export function LiquiditySourcePage({ supportedSwappers }: PropTypes) {
13
12
  const swappers = useMetaStore.use.meta().swappers;
@@ -47,12 +46,10 @@ export function LiquiditySourcePage({ supportedSwappers }: PropTypes) {
47
46
  <LiquiditySourcesSelector
48
47
  toggleAll={toggleAllLiquiditySources}
49
48
  list={
50
- supportedSwappers !== 'all'
49
+ supportedSwappers
51
50
  ? uniqueSwappersGroups.filter(
52
51
  (item) =>
53
- supportedSwappers.filter(
54
- (s) => s.title === item.title && s.type === item.type
55
- ).length > 0
52
+ supportedSwappers.filter((s) => s === item.title).length > 0
56
53
  )
57
54
  : uniqueSwappersGroups
58
55
  }
@@ -4,19 +4,19 @@ import { useBestRouteStore } from '../store/bestRoute';
4
4
  import { useMetaStore } from '../store/meta';
5
5
  import { useNavigateBack } from '../hooks/useNavigateBack';
6
6
  import { navigationRoutes } from '../constants/navigationRoutes';
7
- import { BlockchainMeta } from 'rango-sdk';
8
7
 
9
8
  interface PropTypes {
10
9
  type: 'from' | 'to';
11
- supportedChains: 'all' | BlockchainMeta[];
10
+ supportedChains?: string[];
12
11
  }
13
12
 
14
13
  export function SelectChainPage(props: PropTypes) {
15
14
  const { type, supportedChains } = props;
16
- const blockchains =
17
- supportedChains === 'all'
18
- ? useMetaStore.use.meta().blockchains
19
- : supportedChains;
15
+ const blockchains = supportedChains
16
+ ? useMetaStore.use
17
+ .meta()
18
+ .blockchains.filter((chain) => supportedChains.includes(chain.name))
19
+ : useMetaStore.use.meta().blockchains;
20
20
  const loadingStatus = useMetaStore.use.loadingStatus();
21
21
  const fromChain = useBestRouteStore.use.fromChain();
22
22
  const toChain = useBestRouteStore.use.toChain();
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { TokenSelector } from '@rango-dev/ui';
3
3
  import { useBestRouteStore } from '../store/bestRoute';
4
- import { Token } from 'rango-sdk';
4
+ import { Asset, Token } from 'rango-sdk';
5
5
  import { useNavigateBack } from '../hooks/useNavigateBack';
6
6
  import { navigationRoutes } from '../constants/navigationRoutes';
7
7
  import { tokensAreEqual } from '../utils/wallets';
@@ -9,7 +9,7 @@ import { useMetaStore } from '../store/meta';
9
9
 
10
10
  interface PropTypes {
11
11
  type: 'from' | 'to';
12
- supportedTokens: 'all' | Token[];
12
+ supportedTokens?: Asset[];
13
13
  }
14
14
 
15
15
  export interface TokenWithBalance extends Token {
@@ -25,23 +25,21 @@ export function SelectTokenPage(props: PropTypes) {
25
25
  const { type, supportedTokens } = props;
26
26
  const sourceTokens = useBestRouteStore.use.sourceTokens();
27
27
  const destinationTokens = useBestRouteStore.use.destinationTokens();
28
- const supportedSourceTokens =
29
- supportedTokens === 'all'
30
- ? sourceTokens
31
- : sourceTokens.filter((token) =>
32
- supportedTokens.some((supportedToken) =>
33
- tokensAreEqual(supportedToken, token)
34
- )
35
- );
28
+ const supportedSourceTokens = supportedTokens
29
+ ? sourceTokens.filter((token) =>
30
+ supportedTokens.some((supportedToken) =>
31
+ tokensAreEqual(supportedToken, token)
32
+ )
33
+ )
34
+ : sourceTokens;
36
35
 
37
- const supportedDestinationTokens =
38
- supportedTokens === 'all'
39
- ? destinationTokens
40
- : destinationTokens.filter((token) =>
41
- supportedTokens.some((supportedToken) =>
42
- tokensAreEqual(supportedToken, token)
43
- )
44
- );
36
+ const supportedDestinationTokens = supportedTokens
37
+ ? destinationTokens.filter((token) =>
38
+ supportedTokens.some((supportedToken) =>
39
+ tokensAreEqual(supportedToken, token)
40
+ )
41
+ )
42
+ : destinationTokens;
45
43
 
46
44
  const fromToken = useBestRouteStore.use.fromToken();
47
45
  const toToken = useBestRouteStore.use.toToken();
@@ -5,7 +5,6 @@ import { useMetaStore } from '../store/meta';
5
5
  import { useNavigate } from 'react-router-dom';
6
6
  import { navigationRoutes } from '../constants/navigationRoutes';
7
7
  import { removeDuplicateFrom } from '../utils/common';
8
- import { Source } from '../types';
9
8
  import {
10
9
  MAX_SLIPPAGE,
11
10
  MIN_SLIPPGAE,
@@ -13,7 +12,7 @@ import {
13
12
  } from '../constants/swapSettings';
14
13
  import { useNavigateBack } from '../hooks/useNavigateBack';
15
14
  interface PropTypes {
16
- supportedSwappers: 'all' | Source[];
15
+ supportedSwappers?: string[];
17
16
  }
18
17
  export function SettingsPage({ supportedSwappers }: PropTypes) {
19
18
  const slippage = useSettingsStore.use.slippage();
@@ -45,8 +44,6 @@ export function SettingsPage({ supportedSwappers }: PropTypes) {
45
44
  .find((s) => {
46
45
  if (s) {
47
46
  for (const type of s.types) {
48
- if (supportedSwappers !== 'all') {
49
- }
50
47
  uniqueSwappersGroups.push({
51
48
  title: s.swapperGroup,
52
49
  logo: s.logo,
@@ -56,23 +53,16 @@ export function SettingsPage({ supportedSwappers }: PropTypes) {
56
53
  }
57
54
  }
58
55
  });
59
- supportedSwappers !== 'all' &&
56
+ supportedSwappers &&
60
57
  uniqueSwappersGroups.filter(
61
- (item) =>
62
- supportedSwappers.filter(
63
- (s) => s.title === item.title && s.type === item.type
64
- ).length > 0
58
+ (item) => supportedSwappers.filter((s) => s === item.title).length > 0
65
59
  );
66
60
 
67
- const supportedUniqueSwappersGroups =
68
- supportedSwappers !== 'all'
69
- ? uniqueSwappersGroups.filter(
70
- (item) =>
71
- supportedSwappers.filter(
72
- (s) => s.title === item.title && s.type === item.type
73
- ).length > 0
74
- )
75
- : uniqueSwappersGroups;
61
+ const supportedUniqueSwappersGroups = supportedSwappers
62
+ ? uniqueSwappersGroups.filter(
63
+ (item) => supportedSwappers.filter((s) => s === item.title).length > 0
64
+ )
65
+ : uniqueSwappersGroups;
76
66
 
77
67
  return (
78
68
  <Settings
@@ -4,7 +4,7 @@ import useCopyToClipboard from '../hooks/useCopyToClipboard';
4
4
  import { useManager } from '@rango-dev/queue-manager-react';
5
5
  import { useNavigateBack } from '../hooks/useNavigateBack';
6
6
  import { getPendingSwaps } from '../utils/queue';
7
- import { SwapHistory } from '@rango-dev/ui';
7
+ import { SwapHistory, Spacer } from '@rango-dev/ui';
8
8
  import { useUiStore } from '../store/ui';
9
9
  import {
10
10
  cancelSwap,
@@ -26,7 +26,6 @@ import {
26
26
  shouldRetrySwap,
27
27
  } from '../utils/swap';
28
28
  import { TokenPreview } from '../components/TokenPreview';
29
- import { Spacer } from '@rango-dev/ui';
30
29
  import { numberToString } from '../utils/numbers';
31
30
  //@ts-ignore
32
31
  import { t } from 'i18next';
@@ -127,7 +126,7 @@ export function SwapDetailsPage() {
127
126
  <TokenPreview
128
127
  chain={{
129
128
  displayName: lastStep?.toBlockchain || '',
130
- // @ts-ignore
129
+ //@ts-ignore
131
130
  logo: lastStep?.toBlockchainLogo || '',
132
131
  }}
133
132
  token={{
@@ -141,7 +140,6 @@ export function SwapDetailsPage() {
141
140
  </>
142
141
  }
143
142
  //todo: move PendingSwap type to rango-types
144
- //@ts-ignore
145
143
  pendingSwap={swap}
146
144
  onCopy={handleCopy}
147
145
  isCopied={isCopied}
@@ -20,7 +20,7 @@ import { Spinner } from '@rango-dev/ui';
20
20
  import { LoadingFailedAlert } from '@rango-dev/ui';
21
21
 
22
22
  interface PropTypes {
23
- supportedWallets: 'all' | WalletType[];
23
+ supportedWallets?: WalletType[];
24
24
  multiWallets: boolean;
25
25
  }
26
26
 
@@ -50,7 +50,7 @@ export function WalletsPage({ supportedWallets, multiWallets }: PropTypes) {
50
50
  const wallets = getlistWallet(
51
51
  state,
52
52
  getWalletInfo,
53
- supportedWallets === 'all' ? Object.values(WalletType) : supportedWallets
53
+ supportedWallets || Object.values(WalletType)
54
54
  );
55
55
  const walletsRef = useRef<WalletInfo[]>();
56
56
 
@@ -1,5 +1,14 @@
1
1
  import { RangoClient } from 'rango-sdk';
2
+ import { getConfig } from '../utils/configs';
2
3
 
3
- export const httpService = new RangoClient(
4
- process.env.REACT_APP_API_KEY as string
5
- );
4
+ // this API key is limited and
5
+ // it is only for test purpose
6
+ export const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
7
+
8
+ let rango: RangoClient | undefined = undefined;
9
+
10
+ export const httpService = () => {
11
+ if (rango) return rango;
12
+ rango = new RangoClient(getConfig('API_KEY'));
13
+ return rango;
14
+ };
@@ -249,7 +249,7 @@ const bestRoute = (
249
249
  let abortController: AbortController | null = null;
250
250
  const fetchBestRoute = () => {
251
251
  const { fromToken, toToken, inputAmount } = bestRouteStore.getState();
252
- const { slippage, customSlippage, disabledLiquiditySources } =
252
+ const { slippage, customSlippage, disabledLiquiditySources, affiliateRef } =
253
253
  settingsStore.getState();
254
254
  if (!fromToken || !toToken || !inputAmount || inputAmount === '0') return;
255
255
  abortController?.abort();
@@ -263,7 +263,8 @@ const bestRoute = (
263
263
  [],
264
264
  disabledLiquiditySources,
265
265
  userSlippage,
266
- false
266
+ false,
267
+ affiliateRef
267
268
  );
268
269
  if (!bestRouteStore.getState().loading)
269
270
  bestRouteStore.setState({
@@ -272,7 +273,7 @@ const bestRoute = (
272
273
  outputAmount: null,
273
274
  outputUsdValue: new BigNumber(0),
274
275
  });
275
- httpService
276
+ httpService()
276
277
  .getBestRoute(requestBody, {
277
278
  signal: abortController.signal,
278
279
  })
package/src/store/meta.ts CHANGED
@@ -18,12 +18,14 @@ export const useMetaStore = createSelectors(
18
18
  loadingStatus: 'loading',
19
19
  fetchMeta: async () => {
20
20
  try {
21
- const response = await httpService.getAllMetadata();
21
+ const response = await httpService().getAllMetadata();
22
22
  const chainThatHasTokenInMetaResponse = removeDuplicateFrom(
23
- response.tokens.map((t) => t.blockchain),
23
+ response.tokens.map((t) => t.blockchain)
24
24
  );
25
25
  const enabledChains = response.blockchains.filter(
26
- (chain) => chain.enabled && chainThatHasTokenInMetaResponse.includes(chain.name),
26
+ (chain) =>
27
+ chain.enabled &&
28
+ chainThatHasTokenInMetaResponse.includes(chain.name)
27
29
  );
28
30
  response.blockchains = enabledChains.sort((a, b) => a.sort - b.sort);
29
31
  set({ meta: response, loadingStatus: 'success' });
@@ -31,5 +33,5 @@ export const useMetaStore = createSelectors(
31
33
  set({ loadingStatus: 'failed' });
32
34
  }
33
35
  },
34
- })),
36
+ }))
35
37
  );
@@ -13,12 +13,14 @@ export interface SettingsState {
13
13
  infiniteApprove: boolean;
14
14
  disabledLiquiditySources: string[];
15
15
  theme: Theme;
16
+ affiliateRef: string | null;
16
17
  setSlippage: (slippage: number) => void;
17
18
  setCustomSlippage: (customSlippage: number | null) => void;
18
19
  toggleInfiniteApprove: () => void;
19
20
  toggleLiquiditySource: (name: string) => void;
20
21
  setTheme: (theme: Theme) => void;
21
22
  toggleAllLiquiditySources: () => void;
23
+ setAffiliateRef: (affiliateRef: string | null) => void;
22
24
  }
23
25
 
24
26
  export const useSettingsStore = createSelectors(
@@ -28,6 +30,7 @@ export const useSettingsStore = createSelectors(
28
30
  slippage: DEFAULT_SLIPPAGE,
29
31
  customSlippage: null,
30
32
  infiniteApprove: false,
33
+ affiliateRef: null,
31
34
  disabledLiquiditySources: [],
32
35
  theme: 'auto',
33
36
  setSlippage: (slippage) =>
@@ -38,6 +41,10 @@ export const useSettingsStore = createSelectors(
38
41
  set(() => ({
39
42
  customSlippage: customSlippage,
40
43
  })),
44
+ setAffiliateRef: (affiliateRef) =>
45
+ set(() => ({
46
+ affiliateRef,
47
+ })),
41
48
  toggleAllLiquiditySources: () =>
42
49
  set((state) => {
43
50
  const { swappers } = useMetaStore.getState().meta;
@@ -81,7 +81,7 @@ export const useWalletsStore = createSelectors(
81
81
  }));
82
82
  accounts.forEach(async (account) => {
83
83
  try {
84
- const response = await httpService.getWalletsDetails([
84
+ const response = await httpService().getWalletsDetails([
85
85
  { address: account.address, blockchain: account.chain },
86
86
  ]);
87
87
  const retrivedBalance = response.wallets[0];
@@ -1,9 +1,5 @@
1
- import { BlockchainMeta, Token } from 'rango-sdk';
1
+ import { Asset } from 'rango-sdk';
2
2
  import { WalletType } from '@rango-dev/wallets-shared';
3
- export interface Source {
4
- title: string;
5
- type: 'BRIDGE' | 'AGGREGATOR' | 'DEX';
6
- }
7
3
 
8
4
  export type Colors = {
9
5
  background?: string;
@@ -17,28 +13,31 @@ export type Colors = {
17
13
  warning?: string;
18
14
  };
19
15
 
20
- export type Configs = {
21
- fromChain: BlockchainMeta | null;
22
- fromToken: Token | null;
23
- toChain: BlockchainMeta | null;
24
- toToken: Token | null;
25
- fromAmount: number;
26
- fromChains: 'all' | BlockchainMeta[];
27
- fromTokens: 'all' | Token[];
28
- toChains: 'all' | BlockchainMeta[];
29
- toTokens: 'all' | Token[];
30
- liquiditySources: 'all' | Source[];
31
- wallets: 'all' | WalletType[];
32
- multiWallets: boolean;
33
- customeAddress: boolean;
34
- theme: 'dark' | 'light' | 'auto';
35
- title: string;
36
- width: number;
37
- height: number;
38
- languege: string;
39
- borderRadius: number;
40
- fontFamily: string;
41
- titleSize: number;
42
- titleWeight: number;
43
- colors: Colors;
16
+ export type Theme = {
17
+ mode?: 'dark' | 'light' | 'auto';
18
+ fontFamily?: string;
19
+ colors?: Colors;
20
+ borderRadius?: number;
21
+ width?: number;
22
+ height?: number;
23
+ };
24
+ export type Support = {
25
+ blockchain?: string;
26
+ token?: Asset;
27
+ blockchains?: string[];
28
+ tokens?: Asset[];
29
+ };
30
+
31
+ export type WidgetConfig = {
32
+ apiKey: string;
33
+ affiliateRef?: string;
34
+ amount?: number;
35
+ from?: Support;
36
+ to?: Support;
37
+ liquiditySources?: string[];
38
+ wallets?: WalletType[];
39
+ multiWallets?: boolean;
40
+ customAddress?: boolean;
41
+ language?: string;
42
+ theme?: Theme;
44
43
  };
@@ -0,0 +1,24 @@
1
+ export interface Configs {
2
+ API_KEY: string;
3
+ }
4
+
5
+ const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
6
+
7
+ let configs: Configs = {
8
+ API_KEY: RANGO_PUBLIC_API_KEY,
9
+ };
10
+
11
+ export function getConfig(name: keyof Configs) {
12
+ return configs[name];
13
+ }
14
+
15
+ export function setConfig(name: keyof Configs, value: any) {
16
+ configs[name] = value;
17
+
18
+ return value;
19
+ }
20
+
21
+ export function initConfig(nextConfigs: Configs) {
22
+ configs = structuredClone(nextConfigs);
23
+ return configs;
24
+ }