@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.
- package/dist/QueueManager.d.ts.map +1 -1
- package/dist/components/Layout.d.ts.map +1 -1
- package/dist/components/TokenInfo.d.ts.map +1 -1
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/SettingsPage.d.ts +2 -1
- package/dist/pages/SettingsPage.d.ts.map +1 -1
- package/dist/store/wallets.d.ts +6 -15
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/config.d.ts +11 -1
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/wallets.d.ts +7 -0
- package/dist/types/wallets.d.ts.map +1 -0
- package/dist/utils/common.d.ts +0 -1
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/routing.d.ts +2 -3
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +8 -9
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +11 -12
- package/dist/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +161 -197
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +161 -197
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +162 -198
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +10 -13
- package/src/QueueManager.tsx +4 -6
- package/src/components/AppRoutes.tsx +1 -1
- package/src/components/BottomLogo.tsx +1 -1
- package/src/components/Layout.tsx +27 -23
- package/src/components/RoutesOverview.tsx +2 -2
- package/src/components/TokenInfo.tsx +14 -13
- package/src/components/TokenPreview.tsx +6 -6
- package/src/hooks/useConfirmSwap.ts +2 -2
- package/src/hooks/useTheme.ts +42 -59
- package/src/index.tsx +144 -14
- package/src/pages/ConfirmSwapPage.tsx +27 -19
- package/src/pages/Home.tsx +5 -3
- package/src/pages/SettingsPage.tsx +3 -1
- package/src/store/bestRoute.ts +7 -7
- package/src/store/wallets.ts +32 -46
- package/src/types/config.ts +8 -1
- package/src/types/index.ts +1 -0
- package/src/types/wallets.ts +7 -0
- package/src/utils/common.ts +0 -21
- package/src/utils/routing.ts +2 -3
- package/src/utils/swap.ts +12 -11
- package/src/utils/wallets.ts +60 -63
- package/dist/App.d.ts +0 -9
- package/dist/App.d.ts.map +0 -1
- package/dist/lib.d.ts +0 -10
- package/dist/lib.d.ts.map +0 -1
- package/src/App.tsx +0 -123
- package/src/app.css +0 -12
- package/src/lib.tsx +0 -144
package/src/utils/swap.ts
CHANGED
|
@@ -6,14 +6,14 @@ import {
|
|
|
6
6
|
SwapResult,
|
|
7
7
|
Token,
|
|
8
8
|
} from 'rango-sdk';
|
|
9
|
-
import {
|
|
9
|
+
import { ConnectedWallet } from '../store/wallets';
|
|
10
10
|
import { ZERO } from '../constants/numbers';
|
|
11
11
|
import { numberToString } from './numbers';
|
|
12
12
|
import { WalletType } from '@rango-dev/wallets-shared';
|
|
13
13
|
import { getRequiredBalanceOfWallet } from './routing';
|
|
14
|
-
import { getRequiredChains
|
|
14
|
+
import { getRequiredChains } from './wallets';
|
|
15
15
|
import { LoadingStatus } from '../store/meta';
|
|
16
|
-
import { ConvertedToken, SwapButtonState } from '../types';
|
|
16
|
+
import { ConvertedToken, SwapButtonState, Wallet } from '../types';
|
|
17
17
|
import {
|
|
18
18
|
PendingSwapNetworkStatus,
|
|
19
19
|
PendingSwapStep,
|
|
@@ -122,7 +122,7 @@ export function LimitErrorMessage(bestRoute: BestRouteResponse | null): {
|
|
|
122
122
|
|
|
123
123
|
export function getSwapButtonState(
|
|
124
124
|
loadingMetaStatus: LoadingStatus,
|
|
125
|
-
|
|
125
|
+
connectedWallets: ConnectedWallet[],
|
|
126
126
|
loading: boolean,
|
|
127
127
|
bestRoute: BestRouteResponse | null,
|
|
128
128
|
hasLimitError: boolean,
|
|
@@ -133,7 +133,8 @@ export function getSwapButtonState(
|
|
|
133
133
|
): SwapButtonState {
|
|
134
134
|
if (loadingMetaStatus !== 'success')
|
|
135
135
|
return { title: 'Connect Wallet', disabled: true };
|
|
136
|
-
if (
|
|
136
|
+
if (connectedWallets.length == 0)
|
|
137
|
+
return { title: 'Connect Wallet', disabled: false };
|
|
137
138
|
if (loading) return { title: 'Finding Best Route...', disabled: true };
|
|
138
139
|
else if (!inputAmount || inputAmount === '0')
|
|
139
140
|
return { title: 'Enter an amount', disabled: true };
|
|
@@ -276,7 +277,7 @@ export function hasProperSlippage(
|
|
|
276
277
|
|
|
277
278
|
export function hasEnoughBalance(
|
|
278
279
|
route: BestRouteResponse,
|
|
279
|
-
selectedWallets:
|
|
280
|
+
selectedWallets: Wallet[]
|
|
280
281
|
) {
|
|
281
282
|
const fee = route.validationStatus;
|
|
282
283
|
|
|
@@ -297,7 +298,7 @@ export function hasEnoughBalance(
|
|
|
297
298
|
|
|
298
299
|
export function hasEnoughBalanceAndProperSlippage(
|
|
299
300
|
route: BestRouteResponse,
|
|
300
|
-
selectedWallets:
|
|
301
|
+
selectedWallets: Wallet[],
|
|
301
302
|
userSlippage: string,
|
|
302
303
|
minRequiredSlippage: string | null
|
|
303
304
|
): boolean {
|
|
@@ -311,8 +312,8 @@ export function createBestRouteRequestBody(
|
|
|
311
312
|
fromToken: Token,
|
|
312
313
|
toToken: Token,
|
|
313
314
|
inputAmount: string,
|
|
314
|
-
wallets:
|
|
315
|
-
selectedWallets:
|
|
315
|
+
wallets: ConnectedWallet[],
|
|
316
|
+
selectedWallets: Wallet[],
|
|
316
317
|
disabledLiquiditySources: string[],
|
|
317
318
|
slippage: number,
|
|
318
319
|
affiliateRef: string | null,
|
|
@@ -379,7 +380,7 @@ export function createBestRouteRequestBody(
|
|
|
379
380
|
return requestBody;
|
|
380
381
|
}
|
|
381
382
|
|
|
382
|
-
export function getWalletsForNewSwap(selectedWallets:
|
|
383
|
+
export function getWalletsForNewSwap(selectedWallets: Wallet[]) {
|
|
383
384
|
const wallets = selectedWallets.reduce(
|
|
384
385
|
(
|
|
385
386
|
selectedWalletsMap: {
|
|
@@ -432,7 +433,7 @@ export function isOutputAmountChangedALot(
|
|
|
432
433
|
|
|
433
434
|
export function getBalanceWarnings(
|
|
434
435
|
route: BestRouteResponse,
|
|
435
|
-
selectedWallets:
|
|
436
|
+
selectedWallets: Wallet[]
|
|
436
437
|
) {
|
|
437
438
|
const fee = route.validationStatus;
|
|
438
439
|
const requiredWallets = getRequiredChains(route);
|
package/src/utils/wallets.ts
CHANGED
|
@@ -22,11 +22,12 @@ import {
|
|
|
22
22
|
} from 'rango-sdk';
|
|
23
23
|
import { isCosmosBlockchain } from 'rango-types';
|
|
24
24
|
import { readAccountAddress } from '@rango-dev/wallets-core';
|
|
25
|
-
import {
|
|
25
|
+
import { ConnectedWallet, TokenBalance } from '../store/wallets';
|
|
26
26
|
import { numberToString } from './numbers';
|
|
27
27
|
import BigNumber from 'bignumber.js';
|
|
28
28
|
import { TokenWithBalance } from '../pages/SelectTokenPage';
|
|
29
29
|
import { ZERO } from '../constants/numbers';
|
|
30
|
+
import { Wallet } from '../types';
|
|
30
31
|
|
|
31
32
|
export function getStateWallet(state: WalletState): WalletStatus {
|
|
32
33
|
switch (true) {
|
|
@@ -41,23 +42,13 @@ export function getStateWallet(state: WalletState): WalletStatus {
|
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
export const excludedWallets = [
|
|
45
|
-
WalletType.UNKNOWN,
|
|
46
|
-
WalletType.TERRA_STATION,
|
|
47
|
-
WalletType.LEAP,
|
|
48
|
-
];
|
|
45
|
+
export const excludedWallets = [WalletType.UNKNOWN, WalletType.LEAP];
|
|
49
46
|
|
|
50
47
|
export function getlistWallet(
|
|
51
48
|
getState: (type: WalletType) => WalletState,
|
|
52
49
|
getWalletInfo: (type: WalletType) => WalletInfo,
|
|
53
50
|
list: WalletType[]
|
|
54
51
|
): ModalWalletInfo[] {
|
|
55
|
-
const excludedWallets = [
|
|
56
|
-
WalletType.UNKNOWN,
|
|
57
|
-
WalletType.TERRA_STATION,
|
|
58
|
-
WalletType.LEAP,
|
|
59
|
-
];
|
|
60
|
-
|
|
61
52
|
return list
|
|
62
53
|
.filter((wallet) => !excludedWallets.includes(wallet))
|
|
63
54
|
.map((type) => {
|
|
@@ -96,11 +87,11 @@ export function prepareAccountsForWalletStore(
|
|
|
96
87
|
accounts: string[],
|
|
97
88
|
evmBasedChains: string[],
|
|
98
89
|
supportedChainNames: Network[] | null
|
|
99
|
-
):
|
|
100
|
-
const result:
|
|
90
|
+
): Wallet[] {
|
|
91
|
+
const result: Wallet[] = [];
|
|
101
92
|
|
|
102
93
|
function addAccount(network: Network, address: string) {
|
|
103
|
-
const newAccount:
|
|
94
|
+
const newAccount: Wallet = {
|
|
104
95
|
address,
|
|
105
96
|
chain: network,
|
|
106
97
|
walletType: wallet,
|
|
@@ -171,56 +162,57 @@ export function getRequiredChains(route: BestRouteResponse | null) {
|
|
|
171
162
|
return wallets;
|
|
172
163
|
}
|
|
173
164
|
|
|
174
|
-
|
|
175
|
-
type Blockchain = { name: string; accounts: Balance[] };
|
|
165
|
+
type Blockchain = { name: string; accounts: ConnectedWallet[] };
|
|
176
166
|
|
|
177
167
|
export function getSelectableWallets(
|
|
178
|
-
|
|
179
|
-
selectedWallets:
|
|
168
|
+
connectedWallets: ConnectedWallet[],
|
|
169
|
+
selectedWallets: Wallet[],
|
|
180
170
|
getWalletInfo: (type: WalletType) => WalletInfo
|
|
181
171
|
): SelectableWallet[] {
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
172
|
+
const selectableWallets: SelectableWallet[] = connectedWallets.map(
|
|
173
|
+
(connectedWallet) => ({
|
|
174
|
+
address: connectedWallet.address,
|
|
175
|
+
walletType: connectedWallet.walletType,
|
|
176
|
+
chain: connectedWallet.chain,
|
|
177
|
+
image: getWalletInfo(connectedWallet.walletType).img,
|
|
178
|
+
name: getWalletInfo(connectedWallet.walletType).name,
|
|
179
|
+
selected: !!selectedWallets.find(
|
|
180
|
+
(selectedWallet) =>
|
|
181
|
+
selectedWallet.chain === connectedWallet.chain &&
|
|
182
|
+
selectedWallet.walletType === connectedWallet.walletType
|
|
183
|
+
),
|
|
184
|
+
})
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
return selectableWallets;
|
|
196
188
|
}
|
|
197
189
|
|
|
198
190
|
export function getBalanceFromWallet(
|
|
199
|
-
|
|
191
|
+
connectedWallets: ConnectedWallet[],
|
|
200
192
|
chain: string,
|
|
201
193
|
symbol: string,
|
|
202
194
|
address: string | null
|
|
203
195
|
): TokenBalance | null {
|
|
204
|
-
if (
|
|
196
|
+
if (connectedWallets.length === 0) return null;
|
|
205
197
|
|
|
206
|
-
const
|
|
207
|
-
(
|
|
198
|
+
const selectedChainWallets = connectedWallets.filter(
|
|
199
|
+
(wallet) => wallet.chain === chain
|
|
208
200
|
);
|
|
209
|
-
if (
|
|
201
|
+
if (selectedChainWallets.length === 0) return null;
|
|
210
202
|
|
|
211
203
|
return (
|
|
212
|
-
|
|
204
|
+
selectedChainWallets
|
|
213
205
|
.map(
|
|
214
|
-
(
|
|
215
|
-
|
|
216
|
-
(
|
|
217
|
-
(address !== null &&
|
|
206
|
+
(wallet) =>
|
|
207
|
+
wallet.balances?.find(
|
|
208
|
+
(balance) =>
|
|
209
|
+
(address !== null && balance.address === address) ||
|
|
218
210
|
(address === null &&
|
|
219
|
-
|
|
220
|
-
|
|
211
|
+
balance.address === address &&
|
|
212
|
+
balance.symbol === symbol)
|
|
221
213
|
) || null
|
|
222
214
|
)
|
|
223
|
-
.filter((
|
|
215
|
+
.filter((balance) => balance !== null)
|
|
224
216
|
.sort(
|
|
225
217
|
(a, b) => parseFloat(b?.amount || '0') - parseFloat(a?.amount || '1')
|
|
226
218
|
)
|
|
@@ -228,19 +220,22 @@ export function getBalanceFromWallet(
|
|
|
228
220
|
);
|
|
229
221
|
}
|
|
230
222
|
|
|
231
|
-
export function
|
|
223
|
+
export function isAccountAndWalletMatched(
|
|
224
|
+
account: Wallet,
|
|
225
|
+
connectedWallet: ConnectedWallet
|
|
226
|
+
) {
|
|
232
227
|
return (
|
|
233
|
-
account.address ===
|
|
234
|
-
account.chain ===
|
|
235
|
-
account.walletType ===
|
|
228
|
+
account.address === connectedWallet.address &&
|
|
229
|
+
account.chain === connectedWallet.chain &&
|
|
230
|
+
account.walletType === connectedWallet.walletType
|
|
236
231
|
);
|
|
237
232
|
}
|
|
238
233
|
|
|
239
234
|
export function makeBalanceFor(
|
|
240
|
-
|
|
235
|
+
wallet: Wallet,
|
|
241
236
|
retrivedBalance: WalletDetail,
|
|
242
237
|
tokens: Token[]
|
|
243
|
-
):
|
|
238
|
+
): ConnectedWallet {
|
|
244
239
|
const {
|
|
245
240
|
address,
|
|
246
241
|
blockChain: chain,
|
|
@@ -253,7 +248,7 @@ export function makeBalanceFor(
|
|
|
253
248
|
loading: false,
|
|
254
249
|
error: false,
|
|
255
250
|
explorerUrl,
|
|
256
|
-
walletType:
|
|
251
|
+
walletType: wallet.walletType,
|
|
257
252
|
balances:
|
|
258
253
|
balances?.map((tokenBalance) => ({
|
|
259
254
|
chain,
|
|
@@ -277,14 +272,16 @@ export function makeBalanceFor(
|
|
|
277
272
|
};
|
|
278
273
|
}
|
|
279
274
|
|
|
280
|
-
export function
|
|
281
|
-
|
|
275
|
+
export function resetConnectedWalletState(
|
|
276
|
+
connectedWallet: ConnectedWallet
|
|
277
|
+
): ConnectedWallet {
|
|
278
|
+
return { ...connectedWallet, loading: false, error: true };
|
|
282
279
|
}
|
|
283
280
|
|
|
284
|
-
export const calculateWalletUsdValue = (
|
|
281
|
+
export const calculateWalletUsdValue = (connectedWallet: ConnectedWallet[]) => {
|
|
285
282
|
const uniqueAccountAddresses = new Set<string | null>();
|
|
286
|
-
const uniqueBalane:
|
|
287
|
-
(acc:
|
|
283
|
+
const uniqueBalane: ConnectedWallet[] = connectedWallet?.reduce(
|
|
284
|
+
(acc: ConnectedWallet[], current: ConnectedWallet) => {
|
|
288
285
|
return acc.findIndex(
|
|
289
286
|
(i) => i.address === current.address && i.chain === current.chain
|
|
290
287
|
) === -1
|
|
@@ -391,13 +388,13 @@ export const getKeplrCompatibleConnectedWallets = (
|
|
|
391
388
|
|
|
392
389
|
export function getTokensWithBalance(
|
|
393
390
|
tokens: TokenWithBalance[],
|
|
394
|
-
|
|
391
|
+
connectedWallets: ConnectedWallet[]
|
|
395
392
|
): TokenWithBalance[] {
|
|
396
393
|
return tokens.map(({ balance, ...otherProps }) => {
|
|
397
394
|
const tokenAmount = numberToString(
|
|
398
395
|
new BigNumber(
|
|
399
396
|
getBalanceFromWallet(
|
|
400
|
-
|
|
397
|
+
connectedWallets,
|
|
401
398
|
otherProps.blockchain,
|
|
402
399
|
otherProps.symbol,
|
|
403
400
|
otherProps.address
|
|
@@ -410,7 +407,7 @@ export function getTokensWithBalance(
|
|
|
410
407
|
tokenUsdValue = numberToString(
|
|
411
408
|
new BigNumber(
|
|
412
409
|
getBalanceFromWallet(
|
|
413
|
-
|
|
410
|
+
connectedWallets,
|
|
414
411
|
otherProps.blockchain,
|
|
415
412
|
otherProps.symbol,
|
|
416
413
|
otherProps.address
|
|
@@ -430,7 +427,7 @@ export function getTokensWithBalance(
|
|
|
430
427
|
export function getSortedTokens(
|
|
431
428
|
chain: BlockchainMeta | null,
|
|
432
429
|
tokens: Token[],
|
|
433
|
-
|
|
430
|
+
connectedWallets: ConnectedWallet[],
|
|
434
431
|
otherChainTokens: TokenWithBalance[]
|
|
435
432
|
): TokenWithBalance[] {
|
|
436
433
|
const fromChainEqueulsToToChain = chain?.name === otherChainTokens[0]?.name;
|
|
@@ -438,7 +435,7 @@ export function getSortedTokens(
|
|
|
438
435
|
const filteredTokens = tokens.filter(
|
|
439
436
|
(token) => token.blockchain === chain?.name
|
|
440
437
|
);
|
|
441
|
-
return sortTokens(getTokensWithBalance(filteredTokens,
|
|
438
|
+
return sortTokens(getTokensWithBalance(filteredTokens, connectedWallets));
|
|
442
439
|
}
|
|
443
440
|
|
|
444
441
|
export function tokensAreEqual(
|
package/dist/App.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import './app.css';
|
|
3
|
-
import { WidgetConfig } from './types';
|
|
4
|
-
import './i18n';
|
|
5
|
-
export declare type WidgetProps = {
|
|
6
|
-
config?: WidgetConfig;
|
|
7
|
-
};
|
|
8
|
-
export declare function App({ config }: WidgetProps): JSX.Element;
|
|
9
|
-
//# sourceMappingURL=App.d.ts.map
|
package/dist/App.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["src/App.tsx"],"names":[],"mappings":";AAIA,OAAO,WAAW,CAAC;AAenB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,QAAQ,CAAC;AAOhB,oBAAY,WAAW,GAAG;IACxB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,CAAC;AAEF,wBAAgB,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,WAAW,eA2F1C"}
|
package/dist/lib.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { WalletType } from '@rango-dev/wallets-shared';
|
|
3
|
-
import { WidgetTheme, WidgetConfig, WidgetColors, BlockchainAndTokenConfig } from './types';
|
|
4
|
-
import './i18n';
|
|
5
|
-
export { WidgetConfig, WalletType, WidgetTheme, WidgetColors, BlockchainAndTokenConfig, };
|
|
6
|
-
export declare type WidgetProps = {
|
|
7
|
-
config?: WidgetConfig;
|
|
8
|
-
};
|
|
9
|
-
export declare const Widget: React.FC<WidgetProps>;
|
|
10
|
-
//# sourceMappingURL=lib.d.ts.map
|
package/dist/lib.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["src/lib.tsx"],"names":[],"mappings":"AACA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAM5D,OAAO,EAAW,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAUhE,OAAO,EACL,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAEjB,OAAO,QAAQ,CAAC;AAMhB,OAAO,EACL,YAAY,EACZ,UAAU,EACV,WAAW,EACX,YAAY,EACZ,wBAAwB,GACzB,CAAC;AAEF,oBAAY,WAAW,GAAG;IACxB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAqGxC,CAAC"}
|
package/src/App.tsx
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
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 './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, WalletType } 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 } from './globalStyles';
|
|
17
|
-
import { useTheme } from './hooks/useTheme';
|
|
18
|
-
import QueueManager from './QueueManager';
|
|
19
|
-
import { isEvmBlockchain } from 'rango-sdk';
|
|
20
|
-
import { WidgetConfig } from './types';
|
|
21
|
-
import './i18n';
|
|
22
|
-
import { useUiStore } from './store/ui';
|
|
23
|
-
import { navigationRoutes } from './constants/navigationRoutes';
|
|
24
|
-
import { initConfig } from './utils/configs';
|
|
25
|
-
|
|
26
|
-
const providers = allProviders();
|
|
27
|
-
|
|
28
|
-
export type WidgetProps = {
|
|
29
|
-
config?: WidgetConfig;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export function App({ config }: WidgetProps) {
|
|
33
|
-
globalFont(config?.theme?.fontFamily || 'Roboto');
|
|
34
|
-
const { activeTheme } = useTheme({ ...config?.theme });
|
|
35
|
-
useMemo(() => {
|
|
36
|
-
if (config?.apiKey) {
|
|
37
|
-
initConfig({
|
|
38
|
-
API_KEY: config?.apiKey,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}, [config]);
|
|
42
|
-
|
|
43
|
-
const { blockchains } = useMetaStore.use.meta();
|
|
44
|
-
const disconnectWallet = useWalletsStore.use.disconnectWallet();
|
|
45
|
-
const connectWallet = useWalletsStore.use.connectWallet();
|
|
46
|
-
const currentPage = useUiStore.use.currentPage();
|
|
47
|
-
|
|
48
|
-
const [lastConnectedWalletWithNetwork, setLastConnectedWalletWithNetwork] =
|
|
49
|
-
useState<string>('');
|
|
50
|
-
const [disconnectedWallet, setDisconnectedWallet] = useState<WalletType>();
|
|
51
|
-
|
|
52
|
-
const evmBasedChainNames = blockchains
|
|
53
|
-
.filter(isEvmBlockchain)
|
|
54
|
-
.map((chain) => chain.name);
|
|
55
|
-
|
|
56
|
-
const themeBackground = activeTheme?.colors?.background?.value;
|
|
57
|
-
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
document.body.style.background = themeBackground;
|
|
60
|
-
}, [themeBackground]);
|
|
61
|
-
|
|
62
|
-
const onUpdateState: EventHandler = (
|
|
63
|
-
type,
|
|
64
|
-
event,
|
|
65
|
-
value,
|
|
66
|
-
state,
|
|
67
|
-
supportedChains
|
|
68
|
-
) => {
|
|
69
|
-
if (event === Events.ACCOUNTS) {
|
|
70
|
-
if (value) {
|
|
71
|
-
const supportedChainNames: Network[] | null =
|
|
72
|
-
walletAndSupportedChainsNames(supportedChains);
|
|
73
|
-
const data = prepareAccountsForWalletStore(
|
|
74
|
-
type,
|
|
75
|
-
value,
|
|
76
|
-
evmBasedChainNames,
|
|
77
|
-
supportedChainNames
|
|
78
|
-
);
|
|
79
|
-
connectWallet(data);
|
|
80
|
-
} else {
|
|
81
|
-
disconnectWallet(type);
|
|
82
|
-
setDisconnectedWallet(type);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (event === Events.ACCOUNTS && state.connected) {
|
|
87
|
-
const key = `${type}-${state.network}-${value}`;
|
|
88
|
-
|
|
89
|
-
if (state.connected) {
|
|
90
|
-
setLastConnectedWalletWithNetwork(key);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (event === Events.NETWORK && state.network) {
|
|
95
|
-
const key = `${type}-${state.network}`;
|
|
96
|
-
setLastConnectedWalletWithNetwork(key);
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
return (
|
|
101
|
-
<Provider
|
|
102
|
-
allBlockChains={blockchains}
|
|
103
|
-
providers={providers}
|
|
104
|
-
onUpdateState={onUpdateState}
|
|
105
|
-
>
|
|
106
|
-
<div id="pageContainer" className={activeTheme}>
|
|
107
|
-
<QueueManager>
|
|
108
|
-
<SwapContainer fixedHeight={currentPage !== navigationRoutes.home}>
|
|
109
|
-
<AppRouter
|
|
110
|
-
lastConnectedWallet={lastConnectedWalletWithNetwork}
|
|
111
|
-
disconnectedWallet={disconnectedWallet}
|
|
112
|
-
clearDisconnectedWallet={() => {
|
|
113
|
-
setDisconnectedWallet(undefined);
|
|
114
|
-
}}
|
|
115
|
-
>
|
|
116
|
-
<Layout config={config} />
|
|
117
|
-
</AppRouter>
|
|
118
|
-
</SwapContainer>
|
|
119
|
-
</QueueManager>
|
|
120
|
-
</div>
|
|
121
|
-
</Provider>
|
|
122
|
-
);
|
|
123
|
-
}
|
package/src/app.css
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
#app {
|
|
4
|
-
height: 100vh;
|
|
5
|
-
}
|
|
6
|
-
#pageContainer {
|
|
7
|
-
display: flex;
|
|
8
|
-
align-items: center;
|
|
9
|
-
justify-content: center;
|
|
10
|
-
height: 100%;
|
|
11
|
-
width: 100%;
|
|
12
|
-
}
|
package/src/lib.tsx
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
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 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
|
-
};
|