@rango-dev/widget-embedded 0.1.16-next.0 → 0.1.16-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 (62) hide show
  1. package/dist/QueueManager.d.ts.map +1 -1
  2. package/dist/components/Layout.d.ts.map +1 -1
  3. package/dist/components/TokenInfo.d.ts.map +1 -1
  4. package/dist/hooks/useTheme.d.ts.map +1 -1
  5. package/dist/index.d.ts +9 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  8. package/dist/pages/Home.d.ts.map +1 -1
  9. package/dist/pages/SettingsPage.d.ts +2 -1
  10. package/dist/pages/SettingsPage.d.ts.map +1 -1
  11. package/dist/store/wallets.d.ts +6 -15
  12. package/dist/store/wallets.d.ts.map +1 -1
  13. package/dist/types/config.d.ts +11 -1
  14. package/dist/types/config.d.ts.map +1 -1
  15. package/dist/types/index.d.ts +1 -0
  16. package/dist/types/index.d.ts.map +1 -1
  17. package/dist/types/wallets.d.ts +7 -0
  18. package/dist/types/wallets.d.ts.map +1 -0
  19. package/dist/utils/common.d.ts +0 -1
  20. package/dist/utils/common.d.ts.map +1 -1
  21. package/dist/utils/routing.d.ts +2 -3
  22. package/dist/utils/routing.d.ts.map +1 -1
  23. package/dist/utils/swap.d.ts +8 -9
  24. package/dist/utils/swap.d.ts.map +1 -1
  25. package/dist/utils/wallets.d.ts +11 -12
  26. package/dist/utils/wallets.d.ts.map +1 -1
  27. package/dist/widget-embedded.cjs.development.js +161 -197
  28. package/dist/widget-embedded.cjs.development.js.map +1 -1
  29. package/dist/widget-embedded.cjs.production.min.js +161 -197
  30. package/dist/widget-embedded.cjs.production.min.js.map +1 -1
  31. package/dist/widget-embedded.esm.js +162 -198
  32. package/dist/widget-embedded.esm.js.map +1 -1
  33. package/package.json +10 -13
  34. package/src/QueueManager.tsx +4 -6
  35. package/src/components/AppRoutes.tsx +1 -1
  36. package/src/components/BottomLogo.tsx +1 -1
  37. package/src/components/Layout.tsx +27 -23
  38. package/src/components/RoutesOverview.tsx +2 -2
  39. package/src/components/TokenInfo.tsx +14 -13
  40. package/src/components/TokenPreview.tsx +6 -6
  41. package/src/hooks/useConfirmSwap.ts +2 -2
  42. package/src/hooks/useTheme.ts +42 -59
  43. package/src/index.tsx +144 -14
  44. package/src/pages/ConfirmSwapPage.tsx +27 -19
  45. package/src/pages/Home.tsx +5 -3
  46. package/src/pages/SettingsPage.tsx +3 -1
  47. package/src/store/bestRoute.ts +7 -7
  48. package/src/store/wallets.ts +32 -46
  49. package/src/types/config.ts +8 -1
  50. package/src/types/index.ts +1 -0
  51. package/src/types/wallets.ts +7 -0
  52. package/src/utils/common.ts +0 -21
  53. package/src/utils/routing.ts +2 -3
  54. package/src/utils/swap.ts +12 -11
  55. package/src/utils/wallets.ts +60 -63
  56. package/dist/App.d.ts +0 -9
  57. package/dist/App.d.ts.map +0 -1
  58. package/dist/lib.d.ts +0 -10
  59. package/dist/lib.d.ts.map +0 -1
  60. package/src/App.tsx +0 -123
  61. package/src/app.css +0 -12
  62. package/src/lib.tsx +0 -144
package/src/index.tsx CHANGED
@@ -1,14 +1,144 @@
1
- import React from 'react';
2
- import { createRoot } from 'react-dom/client';
3
- import { BrowserRouter } from 'react-router-dom';
4
- import { App } from './App';
5
-
6
- const container = document.getElementById('app')!;
7
- const root = createRoot(container);
8
- root.render(
9
- <BrowserRouter>
10
- <App />,
11
- </BrowserRouter>
12
- );
13
-
14
- export { Widget } from './lib';
1
+ import { SwapContainer } from '@rango-dev/ui';
2
+ import React, { useEffect, useMemo, useState } from 'react';
3
+ import { AppRouter } from './components/AppRouter';
4
+ import { useMetaStore } from './store/meta';
5
+ import { Events, Provider } from '@rango-dev/wallets-core';
6
+ import { allProviders } from '@rango-dev/provider-all';
7
+ import { EventHandler } from '@rango-dev/wallets-core/dist/wallet';
8
+ import { Network, WalletType } from '@rango-dev/wallets-shared';
9
+ import {
10
+ prepareAccountsForWalletStore,
11
+ walletAndSupportedChainsNames,
12
+ } from './utils/wallets';
13
+ import { useWalletsStore } from './store/wallets';
14
+ import { Layout } from './components/Layout';
15
+ import { globalFont } from './globalStyles';
16
+ import { useTheme } from './hooks/useTheme';
17
+ import { isEvmBlockchain } from 'rango-sdk';
18
+ import {
19
+ WidgetTheme,
20
+ WidgetConfig,
21
+ WidgetColors,
22
+ BlockchainAndTokenConfig,
23
+ } from './types';
24
+ import useSelectLanguage from './hooks/useSelectLanguage';
25
+ import './i18n';
26
+ import QueueManager from './QueueManager';
27
+ import { useUiStore } from './store/ui';
28
+ import { navigationRoutes } from './constants/navigationRoutes';
29
+ import { initConfig } from './utils/configs';
30
+
31
+ export {
32
+ WidgetConfig,
33
+ WalletType,
34
+ WidgetTheme,
35
+ WidgetColors,
36
+ BlockchainAndTokenConfig,
37
+ };
38
+
39
+ export type WidgetProps = {
40
+ config?: WidgetConfig;
41
+ };
42
+
43
+ export const Widget: React.FC<WidgetProps> = ({ config }) => {
44
+ globalFont(config?.theme?.fontFamily || 'Roboto');
45
+
46
+ const { activeTheme } = useTheme({ ...config?.theme });
47
+ const { blockchains } = useMetaStore.use.meta();
48
+ const disconnectWallet = useWalletsStore.use.disconnectWallet();
49
+ const connectWallet = useWalletsStore.use.connectWallet();
50
+ const { changeLanguage } = useSelectLanguage();
51
+ const clearConnectedWallet = useWalletsStore.use.clearConnectedWallet();
52
+ const [lastConnectedWalletWithNetwork, setLastConnectedWalletWithNetwork] =
53
+ useState<string>('');
54
+ const [disconnectedWallet, setDisconnectedWallet] = useState<WalletType>();
55
+ const currentPage = useUiStore.use.currentPage();
56
+
57
+ const evmBasedChainNames = blockchains
58
+ .filter(isEvmBlockchain)
59
+ .map((chain) => chain.name);
60
+
61
+ useMemo(() => {
62
+ if (config?.apiKey) {
63
+ initConfig({
64
+ API_KEY: config?.apiKey,
65
+ });
66
+ }
67
+ }, [config]);
68
+
69
+ const onUpdateState: EventHandler = (
70
+ type,
71
+ event,
72
+ value,
73
+ state,
74
+ supportedChains
75
+ ) => {
76
+ if (event === Events.ACCOUNTS) {
77
+ if (value) {
78
+ const supportedChainNames: Network[] | null =
79
+ walletAndSupportedChainsNames(supportedChains);
80
+ const data = prepareAccountsForWalletStore(
81
+ type,
82
+ value,
83
+ evmBasedChainNames,
84
+ supportedChainNames
85
+ );
86
+ connectWallet(data);
87
+ } else {
88
+ disconnectWallet(type);
89
+ }
90
+ }
91
+ if (event === Events.ACCOUNTS && state.connected) {
92
+ const key = `${type}-${state.network}-${value}`;
93
+
94
+ if (state.connected) {
95
+ setLastConnectedWalletWithNetwork(key);
96
+ }
97
+ }
98
+
99
+ if (event === Events.NETWORK && state.network) {
100
+ const key = `${type}-${state.network}`;
101
+ setLastConnectedWalletWithNetwork(key);
102
+ }
103
+ };
104
+ let providers = allProviders();
105
+
106
+ useEffect(() => {
107
+ const wallets = config?.wallets;
108
+ clearConnectedWallet();
109
+ providers = !wallets
110
+ ? allProviders()
111
+ : allProviders().filter((provider) => {
112
+ const type = provider.config.type;
113
+ return wallets.find((w) => w === type);
114
+ });
115
+ }, [config?.wallets]);
116
+
117
+ useEffect(() => {
118
+ changeLanguage(config?.language || 'en');
119
+ }, [config?.language]);
120
+
121
+ return (
122
+ <Provider
123
+ allBlockChains={blockchains}
124
+ providers={providers}
125
+ onUpdateState={onUpdateState}
126
+ >
127
+ <div id="swap-container" className={activeTheme}>
128
+ <QueueManager>
129
+ <SwapContainer fixedHeight={currentPage !== navigationRoutes.home}>
130
+ <AppRouter
131
+ lastConnectedWallet={lastConnectedWalletWithNetwork}
132
+ disconnectedWallet={disconnectedWallet}
133
+ clearDisconnectedWallet={() => {
134
+ setDisconnectedWallet(undefined);
135
+ }}
136
+ >
137
+ <Layout config={config} />
138
+ </AppRouter>
139
+ </SwapContainer>
140
+ </QueueManager>
141
+ </div>
142
+ </Provider>
143
+ );
144
+ };
@@ -1,4 +1,4 @@
1
- import React, { useEffect } from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  import { useNavigate } from 'react-router-dom';
3
3
  import { useBestRouteStore } from '../store/bestRoute';
4
4
  import { useWalletsStore } from '../store/wallets';
@@ -40,7 +40,7 @@ export function ConfirmSwapPage() {
40
40
  const setSelectedSwap = useUiStore.use.setSelectedSwap();
41
41
  const { blockchains, tokens } = useMetaStore.use.meta();
42
42
  const loadingMetaStatus = useMetaStore.use.loadingStatus();
43
- const accounts = useWalletsStore.use.accounts();
43
+ const connectedWallets = useWalletsStore.use.connectedWallets();
44
44
  const selectedWallets = useWalletsStore.use.selectedWallets();
45
45
  const initSelectedWallets = useWalletsStore.use.initSelectedWallets();
46
46
  const setSelectedWallet = useWalletsStore.use.setSelectedWallet();
@@ -49,7 +49,7 @@ export function ConfirmSwapPage() {
49
49
  const inputUsdValue = useBestRouteStore.use.inputUsdValue();
50
50
  const outputUsdValue = useBestRouteStore.use.outputUsdValue();
51
51
  const setInputAmount = useBestRouteStore.use.setInputAmount();
52
-
52
+ const [dbErrorMessage, setDbErrorMessage] = useState<string>('');
53
53
  const bestRouteloadingStatus = getBestRouteStatus(
54
54
  fetchingBestRoute,
55
55
  !!fetchingBestRouteError
@@ -87,7 +87,7 @@ export function ConfirmSwapPage() {
87
87
  }, []);
88
88
 
89
89
  const selectableWallets = getSelectableWallets(
90
- accounts,
90
+ connectedWallets,
91
91
  selectedWallets,
92
92
  getWalletInfo
93
93
  );
@@ -106,21 +106,25 @@ export function ConfirmSwapPage() {
106
106
  requiredWallets={getRequiredChains(bestRoute)}
107
107
  selectableWallets={selectableWallets}
108
108
  onBack={navigateBackFrom.bind(null, navigationRoutes.confirmSwap)}
109
- onConfirm={() => {
110
- confirmSwap?.().then((swap) => {
109
+ onConfirm={async () => {
110
+ confirmSwap?.().then(async (swap) => {
111
111
  if (swap) {
112
- manager?.create(
113
- 'swap',
114
- { swapDetails: swap },
115
- { id: swap.requestId }
116
- );
117
- setSelectedSwap(swap.requestId);
118
- navigate('/' + navigationRoutes.swaps + `/${swap.requestId}`, {
119
- replace: true,
120
- });
121
- setTimeout(() => {
122
- setInputAmount('');
123
- }, 0);
112
+ try {
113
+ await manager?.create(
114
+ 'swap',
115
+ { swapDetails: swap },
116
+ { id: swap.requestId }
117
+ );
118
+ setSelectedSwap(swap.requestId);
119
+ navigate('/' + navigationRoutes.swaps + `/${swap.requestId}`, {
120
+ replace: true,
121
+ });
122
+ setTimeout(() => {
123
+ setInputAmount('');
124
+ }, 0);
125
+ } catch (e) {
126
+ setDbErrorMessage('Error: ' + (e as any)?.message);
127
+ }
124
128
  }
125
129
  });
126
130
  }}
@@ -186,7 +190,11 @@ export function ConfirmSwapPage() {
186
190
  />
187
191
  }
188
192
  loading={fetchingConfirmedRoute}
189
- errors={ConfirmSwapErrors(errors)}
193
+ errors={
194
+ dbErrorMessage
195
+ ? [dbErrorMessage, ...ConfirmSwapErrors(errors)]
196
+ : ConfirmSwapErrors(errors)
197
+ }
190
198
  warnings={ConfirmSwapWarnings(warnings)}
191
199
  extraMessages={
192
200
  <>
@@ -83,7 +83,7 @@ export function Home() {
83
83
  const fetchingBestRoute = useBestRouteStore.use.loading();
84
84
  const bestRouteError = useBestRouteStore.use.error();
85
85
  const loadingMetaStatus = useMetaStore.use.loadingStatus();
86
- const accounts = useWalletsStore.use.accounts();
86
+ const connectedWallets = useWalletsStore.use.connectedWallets();
87
87
  const setCurrentPage = useUiStore.use.setCurrentPage();
88
88
  const switchFromAndTo = useBestRouteStore.use.switchFromAndTo();
89
89
 
@@ -113,7 +113,7 @@ export function Home() {
113
113
 
114
114
  const swapButtonState = getSwapButtonState(
115
115
  loadingMetaStatus,
116
- accounts,
116
+ connectedWallets,
117
117
  fetchingBestRoute,
118
118
  bestRoute,
119
119
  hasLimitError(bestRoute),
@@ -139,7 +139,9 @@ export function Home() {
139
139
  title="SWAP"
140
140
  suffix={
141
141
  <HeaderButtons
142
- onClickRefresh={!!bestRoute || bestRouteError ? fetchBestRoute : undefined}
142
+ onClickRefresh={
143
+ !!bestRoute || bestRouteError ? fetchBestRoute : undefined
144
+ }
143
145
  />
144
146
  }
145
147
  />
@@ -13,8 +13,9 @@ import {
13
13
  import { useNavigateBack } from '../hooks/useNavigateBack';
14
14
  interface PropTypes {
15
15
  supportedSwappers?: string[];
16
+ singleTheme?: boolean;
16
17
  }
17
- export function SettingsPage({ supportedSwappers }: PropTypes) {
18
+ export function SettingsPage({ supportedSwappers, singleTheme }: PropTypes) {
18
19
  const slippage = useSettingsStore.use.slippage();
19
20
  const setSlippage = useSettingsStore.use.setSlippage();
20
21
  const disabledLiquiditySources =
@@ -77,6 +78,7 @@ export function SettingsPage({ supportedSwappers }: PropTypes) {
77
78
  selectedLiquiditySources={supportedUniqueSwappersGroups.filter(
78
79
  (s) => s.selected
79
80
  )}
81
+ singleTheme={singleTheme}
80
82
  customSlippage={customSlippage || NaN}
81
83
  onCustomSlippageChange={setCustomSlippage}
82
84
  minSlippage={MIN_SLIPPGAE}
@@ -105,11 +105,11 @@ export const useBestRouteStore = createSelectors(
105
105
  set((state) => {
106
106
  if (state.fromChain?.name === chain?.name) return {};
107
107
  const tokens = useMetaStore.getState().meta.tokens;
108
- const balances = useWalletsStore.getState().balances;
108
+ const connectedWallets = useWalletsStore.getState().connectedWallets;
109
109
  const sortedTokens = getSortedTokens(
110
110
  chain,
111
111
  tokens,
112
- balances,
112
+ connectedWallets,
113
113
  state.destinationTokens
114
114
  );
115
115
  const fromToken = getDefaultToken(sortedTokens, state.toToken);
@@ -136,11 +136,11 @@ export const useBestRouteStore = createSelectors(
136
136
  set((state) => {
137
137
  if (state.toChain?.name === chain?.name) return {};
138
138
  const tokens = useMetaStore.getState().meta.tokens;
139
- const balances = useWalletsStore.getState().balances;
139
+ const connectedWallets = useWalletsStore.getState().connectedWallets;
140
140
  const sortedTokens = getSortedTokens(
141
141
  chain,
142
142
  tokens,
143
- balances,
143
+ connectedWallets,
144
144
  state.destinationTokens
145
145
  );
146
146
 
@@ -173,7 +173,7 @@ export const useBestRouteStore = createSelectors(
173
173
  },
174
174
  retry: (pendingSwap) => {
175
175
  const { tokens, blockchains } = useMetaStore.getState().meta;
176
- const balances = useWalletsStore.getState().balances;
176
+ const connectedWallets = useWalletsStore.getState().connectedWallets;
177
177
  const failedIndex =
178
178
  pendingSwap.status === 'failed'
179
179
  ? pendingSwap.steps.findIndex((s) => s.status === 'failed')
@@ -210,13 +210,13 @@ export const useBestRouteStore = createSelectors(
210
210
  const sortedSourceTokens = getSortedTokens(
211
211
  fromChain,
212
212
  tokens,
213
- balances,
213
+ connectedWallets,
214
214
  []
215
215
  );
216
216
  const sortedDestinationTokens = getSortedTokens(
217
217
  toChain,
218
218
  tokens,
219
- balances,
219
+ connectedWallets,
220
220
  []
221
221
  );
222
222
  const inputAmount = pendingSwap.inputAmount;
@@ -2,26 +2,20 @@ import { SelectableWallet } from '@rango-dev/ui';
2
2
  import { WalletType } from '@rango-dev/wallets-shared';
3
3
  import { create } from 'zustand';
4
4
  import { subscribeWithSelector } from 'zustand/middleware';
5
+ import { shallow } from 'zustand/shallow';
5
6
  import { httpService } from '../services/httpService';
6
7
  import {
7
8
  getRequiredChains,
8
9
  getTokensWithBalance,
9
- isAccountAndBalanceMatched,
10
+ isAccountAndWalletMatched,
10
11
  makeBalanceFor,
11
- resetBalanceState,
12
- SelectedWallet,
12
+ resetConnectedWalletState,
13
13
  sortTokens,
14
14
  } from '../utils/wallets';
15
15
  import { useBestRouteStore } from './bestRoute';
16
16
  import { useMetaStore } from './meta';
17
17
  import createSelectors from './selectors';
18
- import { shallow } from 'zustand/shallow';
19
-
20
- export interface Account {
21
- chain: string;
22
- address: string;
23
- walletType: WalletType;
24
- }
18
+ import { Wallet } from '../types';
25
19
 
26
20
  export type TokenBalance = {
27
21
  chain: string;
@@ -35,39 +29,33 @@ export type TokenBalance = {
35
29
  usdPrice: number | null;
36
30
  };
37
31
 
38
- export interface Balance {
32
+ export interface ConnectedWallet extends Wallet {
39
33
  balances: TokenBalance[] | null;
40
- address: string;
41
- chain: string;
42
34
  loading: boolean;
43
- walletType: WalletType;
44
35
  error: boolean;
45
36
  explorerUrl: string | null;
46
37
  }
47
38
 
48
39
  interface WalletsStore {
49
- accounts: Account[];
50
- balances: Balance[];
51
- selectedWallets: SelectedWallet[];
52
- connectWallet: (accounts: Account[]) => void;
40
+ connectedWallets: ConnectedWallet[];
41
+ selectedWallets: Wallet[];
42
+ connectWallet: (accounts: Wallet[]) => void;
53
43
  disconnectWallet: (walletType: WalletType) => void;
54
44
  initSelectedWallets: () => void;
55
45
  setSelectedWallet: (wallet: SelectableWallet) => void;
56
46
  clearConnectedWallet: () => void;
57
- getOneOfWalletsDetails: (account: Account) => void;
47
+ getOneOfWalletsDetails: (account: Wallet) => void;
58
48
  }
59
49
 
60
50
  export const useWalletsStore = createSelectors(
61
51
  create<WalletsStore>()(
62
52
  subscribeWithSelector((set, get) => ({
63
- accounts: [],
64
- balances: [],
53
+ connectedWallets: [],
65
54
  selectedWallets: [],
66
55
  connectWallet: (accounts) => {
67
56
  const getOneOfWalletsDetails = get().getOneOfWalletsDetails;
68
57
  set((state) => ({
69
- accounts: state.accounts.concat(accounts),
70
- balances: state.balances.concat(
58
+ connectedWallets: state.connectedWallets.concat(
71
59
  accounts.map((account) => ({
72
60
  balances: [],
73
61
  address: account.address,
@@ -83,10 +71,7 @@ export const useWalletsStore = createSelectors(
83
71
  },
84
72
  disconnectWallet: (walletType) => {
85
73
  set((state) => ({
86
- accounts: state.accounts.filter(
87
- (account) => account.walletType !== walletType
88
- ),
89
- balances: state.balances.filter(
74
+ connectedWallets: state.connectedWallets.filter(
90
75
  (balance) => balance.walletType !== walletType
91
76
  ),
92
77
  selectedWallets: state.selectedWallets.filter(
@@ -99,8 +84,8 @@ export const useWalletsStore = createSelectors(
99
84
  const requiredChains = getRequiredChains(
100
85
  useBestRouteStore.getState().bestRoute
101
86
  );
102
- const connectedWallets = state.accounts;
103
- const selectedWallets: SelectedWallet[] = [];
87
+ const connectedWallets = state.connectedWallets;
88
+ const selectedWallets: Wallet[] = [];
104
89
  requiredChains.forEach((chain) => {
105
90
  const anyWalletSelected = !!state.selectedWallets.find(
106
91
  (wallet) => wallet.chain === chain
@@ -134,14 +119,13 @@ export const useWalletsStore = createSelectors(
134
119
 
135
120
  clearConnectedWallet: () =>
136
121
  set(() => ({
137
- accounts: [],
138
- balances: [],
122
+ connectedWallets: [],
139
123
  selectedWallets: [],
140
124
  })),
141
- getOneOfWalletsDetails: async (account: Account) => {
125
+ getOneOfWalletsDetails: async (account: Wallet) => {
142
126
  const tokens = useMetaStore.getState().meta.tokens;
143
127
  set((state) => ({
144
- balances: state.balances.map((balance) => {
128
+ connectedWallets: state.connectedWallets.map((balance) => {
145
129
  return balance.address === account.address &&
146
130
  balance.chain === account.chain
147
131
  ? { ...balance, loading: true }
@@ -155,18 +139,20 @@ export const useWalletsStore = createSelectors(
155
139
  const retrivedBalance = response.wallets[0];
156
140
  if (retrivedBalance) {
157
141
  set((state) => ({
158
- balances: state.balances.map((balance) => {
159
- return isAccountAndBalanceMatched(account, balance)
160
- ? makeBalanceFor(account, retrivedBalance, tokens)
161
- : balance;
162
- }),
142
+ connectedWallets: state.connectedWallets.map(
143
+ (connectedWallet) => {
144
+ return isAccountAndWalletMatched(account, connectedWallet)
145
+ ? makeBalanceFor(account, retrivedBalance, tokens)
146
+ : connectedWallet;
147
+ }
148
+ ),
163
149
  }));
164
150
  } else throw new Error('Wallet not found');
165
151
  } catch (error) {
166
152
  set((state) => ({
167
- balances: state.balances.map((balance) => {
168
- return isAccountAndBalanceMatched(account, balance)
169
- ? resetBalanceState(balance)
153
+ connectedWallets: state.connectedWallets.map((balance) => {
154
+ return isAccountAndWalletMatched(account, balance)
155
+ ? resetConnectedWalletState(balance)
170
156
  : balance;
171
157
  }),
172
158
  }));
@@ -177,16 +163,16 @@ export const useWalletsStore = createSelectors(
177
163
  );
178
164
 
179
165
  useWalletsStore.subscribe(
180
- (state) => state.balances,
181
- (balances) => {
166
+ (state) => state.connectedWallets,
167
+ (connectedWallets) => {
182
168
  useBestRouteStore.setState(({ sourceTokens, destinationTokens }) => {
183
169
  const sourceTokensWithBalance = getTokensWithBalance(
184
170
  sourceTokens,
185
- balances
171
+ connectedWallets
186
172
  );
187
173
  const destinationTokensWithBalance = getTokensWithBalance(
188
174
  destinationTokens,
189
- balances
175
+ connectedWallets
190
176
  );
191
177
  return {
192
178
  sourceTokens: sortTokens(sourceTokensWithBalance),
@@ -200,4 +186,4 @@ useWalletsStore.subscribe(
200
186
  );
201
187
 
202
188
  export const fetchingBalanceSelector = (state: WalletsStore) =>
203
- !!state.balances.find((wallet) => wallet.loading);
189
+ !!state.connectedWallets.find((wallet) => wallet.loading);
@@ -9,6 +9,9 @@ import { WalletType } from '@rango-dev/wallets-shared';
9
9
  * @property {string} success
10
10
  * @property {string} error
11
11
  * @property {string} warning
12
+ * @property {string} surface
13
+ * @property {string} neutral
14
+
12
15
  */
13
16
  export type WidgetColors = {
14
17
  background?: string;
@@ -17,6 +20,8 @@ export type WidgetColors = {
17
20
  success?: string;
18
21
  error?: string;
19
22
  warning?: string;
23
+ surface?: string;
24
+ neutral?: string;
20
25
  };
21
26
 
22
27
  /**
@@ -33,14 +38,16 @@ export type WidgetColors = {
33
38
  * specifies the radius of the corners of a widget.
34
39
  * @property {number} width - The `width` property is a number that represents the width of the widget.
35
40
  * @property {number} height - The `height` property is a number that specifies the height of the widget.
41
+ * @property {boolean} singleTheme - The `singleTheme` property is a boolean that specifies the theme is support dark and light or only light.
36
42
  */
37
43
  export type WidgetTheme = {
38
44
  mode?: 'auto' | 'light' | 'dark';
39
45
  fontFamily?: string;
40
- colors?: WidgetColors;
46
+ colors?: { light: WidgetColors; dark: WidgetColors };
41
47
  borderRadius?: number;
42
48
  width?: number;
43
49
  height?: number;
50
+ singleTheme?: boolean;
44
51
  };
45
52
 
46
53
  /**
@@ -1,3 +1,4 @@
1
1
  export * from './swap';
2
2
  export * from './config';
3
3
  export * from './routing';
4
+ export * from './wallets';
@@ -0,0 +1,7 @@
1
+ import { WalletType } from '@rango-dev/wallets-shared';
2
+
3
+ export interface Wallet {
4
+ chain: string;
5
+ address: string;
6
+ walletType: WalletType;
7
+ }
@@ -10,29 +10,8 @@ export function areEqual(
10
10
  array1.length === array2.length && array1.every((v, i) => v === array2[i])
11
11
  );
12
12
  }
13
- export function shadeColor(color: string, percent: number) {
14
- var R = parseInt(color.substring(1, 3), 16);
15
- var G = parseInt(color.substring(3, 5), 16);
16
- var B = parseInt(color.substring(5, 7), 16);
17
13
 
18
- R = (R * (100 + percent)) / 100;
19
- G = (G * (100 + percent)) / 100;
20
- B = (B * (100 + percent)) / 100;
21
14
 
22
- R = R < 255 ? R : 255;
23
- G = G < 255 ? G : 255;
24
- B = B < 255 ? B : 255;
25
-
26
- R = Math.round(R);
27
- G = Math.round(G);
28
- B = Math.round(B);
29
-
30
- var RR = R.toString(16).length == 1 ? '0' + R.toString(16) : R.toString(16);
31
- var GG = G.toString(16).length == 1 ? '0' + G.toString(16) : G.toString(16);
32
- var BB = B.toString(16).length == 1 ? '0' + B.toString(16) : B.toString(16);
33
-
34
- return '#' + RR + GG + BB;
35
- }
36
15
 
37
16
  export function debounce(fn: Function, time: number) {
38
17
  let timeoutId: ReturnType<typeof setTimeout> | null;
@@ -5,8 +5,7 @@ import {
5
5
  import BigNumber from 'bignumber.js';
6
6
  import { BestRouteResponse, BlockchainMeta, Token } from 'rango-sdk';
7
7
  import { areEqual } from './common';
8
- import { SelectedWallet } from './wallets';
9
- import { BestRouteEqualityParams } from '../types';
8
+ import { BestRouteEqualityParams, Wallet } from '../types';
10
9
  import { numberToString } from './numbers';
11
10
  import { PendingSwap } from '@rango-dev/queue-manager-rango-preset';
12
11
 
@@ -96,7 +95,7 @@ export function outToRatioHasWarning(
96
95
  }
97
96
 
98
97
  export function getRequiredBalanceOfWallet(
99
- selectedWallet: SelectedWallet,
98
+ selectedWallet: Wallet,
100
99
  fee: SimulationValidationStatus[] | null
101
100
  ): SimulationAssetAndAmount[] | null {
102
101
  if (fee === null) return null;