@rango-dev/widget-embedded 0.5.1-next.0 → 0.5.1-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/Wallets.d.ts +13 -0
- package/dist/Wallets.d.ts.map +1 -0
- package/dist/Widget.d.ts +3 -2
- package/dist/Widget.d.ts.map +1 -1
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/WidgetEvents.d.ts +2 -0
- package/dist/components/WidgetEvents.d.ts.map +1 -0
- package/dist/hooks/useSelectLanguage.d.ts.map +1 -1
- package/dist/hooks/useWalletProviders.d.ts +6 -0
- package/dist/hooks/useWalletProviders.d.ts.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts +2 -2
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/config.d.ts +6 -1
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/providers.d.ts +11 -0
- package/dist/utils/providers.d.ts.map +1 -0
- package/dist/utils/wallets.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/QueueManager.tsx +0 -25
- package/src/Wallets.tsx +100 -0
- package/src/Widget.tsx +53 -91
- package/src/components/AppRouter.tsx +0 -2
- package/src/components/WidgetEvents.tsx +46 -0
- package/src/hooks/useSelectLanguage.ts +2 -0
- package/src/hooks/useWalletProviders.ts +20 -0
- package/src/index.ts +16 -1
- package/src/pages/ConfirmSwapPage.tsx +3 -4
- package/src/pages/Home.tsx +2 -4
- package/src/pages/WalletsPage.tsx +8 -4
- package/src/store/wallets.ts +4 -5
- package/src/types/config.ts +6 -1
- package/src/utils/providers.ts +53 -0
- package/src/utils/wallets.ts +17 -10
- package/dist/mockData/pendingSwap.d.ts +0 -2
- package/dist/mockData/pendingSwap.d.ts.map +0 -1
- package/src/mockData/pendingSwap.ts +0 -607
|
@@ -22,9 +22,11 @@ import { useTranslation } from 'react-i18next';
|
|
|
22
22
|
import { useMetaStore } from '../store/meta';
|
|
23
23
|
import { Spinner } from '@rango-dev/ui';
|
|
24
24
|
import { LoadingFailedAlert } from '@rango-dev/ui';
|
|
25
|
+
import { WidgetConfig } from '../types';
|
|
26
|
+
import { configWalletsToWalletName } from '../utils/providers';
|
|
25
27
|
|
|
26
28
|
interface PropTypes {
|
|
27
|
-
supportedWallets
|
|
29
|
+
supportedWallets: WidgetConfig['wallets'];
|
|
28
30
|
multiWallets: boolean;
|
|
29
31
|
}
|
|
30
32
|
|
|
@@ -48,13 +50,16 @@ const LoaderContainer = styled('div', {
|
|
|
48
50
|
const AlertContainer = styled('div', {
|
|
49
51
|
paddingBottom: '$16',
|
|
50
52
|
});
|
|
53
|
+
|
|
54
|
+
const ALL_SUPPORTED_WALLETS = Object.values(WalletTypes);
|
|
55
|
+
|
|
51
56
|
export function WalletsPage({ supportedWallets, multiWallets }: PropTypes) {
|
|
52
57
|
const { navigateBackFrom } = useNavigateBack();
|
|
53
58
|
const { state, disconnect, getWalletInfo, connect } = useWallets();
|
|
54
59
|
const wallets = getlistWallet(
|
|
55
60
|
state,
|
|
56
61
|
getWalletInfo,
|
|
57
|
-
supportedWallets ||
|
|
62
|
+
configWalletsToWalletName(supportedWallets) || ALL_SUPPORTED_WALLETS
|
|
58
63
|
);
|
|
59
64
|
const walletsRef = useRef<WalletInfo[]>();
|
|
60
65
|
|
|
@@ -112,8 +117,7 @@ export function WalletsPage({ supportedWallets, multiWallets }: PropTypes) {
|
|
|
112
117
|
<SecondaryPage
|
|
113
118
|
title={t('Select Wallet') || ''}
|
|
114
119
|
textField={false}
|
|
115
|
-
onBack={navigateBackFrom.bind(null, navigationRoutes.wallets)}
|
|
116
|
-
>
|
|
120
|
+
onBack={navigateBackFrom.bind(null, navigationRoutes.wallets)}>
|
|
117
121
|
<>
|
|
118
122
|
{walletErrorMessage && (
|
|
119
123
|
<AlertContainer>
|
package/src/store/wallets.ts
CHANGED
|
@@ -134,11 +134,10 @@ export const useWalletsStore = createSelectors(
|
|
|
134
134
|
getOneOfWalletsDetails: async (account: Wallet) => {
|
|
135
135
|
const tokens = useMetaStore.getState().meta.tokens;
|
|
136
136
|
set((state) => ({
|
|
137
|
-
connectedWallets: state.connectedWallets.map((
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
: balance;
|
|
137
|
+
connectedWallets: state.connectedWallets.map((wallet) => {
|
|
138
|
+
return isAccountAndWalletMatched(account, wallet)
|
|
139
|
+
? { ...wallet, loading: true }
|
|
140
|
+
: wallet;
|
|
142
141
|
}),
|
|
143
142
|
}));
|
|
144
143
|
try {
|
package/src/types/config.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Asset } from 'rango-sdk';
|
|
2
2
|
import { WalletType } from '@rango-dev/wallets-shared';
|
|
3
|
+
import { ProviderInterface } from '@rango-dev/wallets-core';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* The above type defines a set of optional color properties for a widget.
|
|
@@ -100,6 +101,9 @@ export type BlockchainAndTokenConfig = {
|
|
|
100
101
|
* @property {WidgetTheme} theme - The `theme` property is a part of the `WidgetConfig` type and is
|
|
101
102
|
* used to specify the visual theme of the widget. It is of type `WidgetTheme`, which is an interface
|
|
102
103
|
* that defines the various properties of the theme, such as colors, fonts, and others.
|
|
104
|
+
* @property {boolean} externalWallets
|
|
105
|
+
* If `externalWallets` is `true`, you should add `WidgetWallets` to your app.
|
|
106
|
+
|
|
103
107
|
*/
|
|
104
108
|
export type WidgetConfig = {
|
|
105
109
|
apiKey: string;
|
|
@@ -108,9 +112,10 @@ export type WidgetConfig = {
|
|
|
108
112
|
from?: BlockchainAndTokenConfig;
|
|
109
113
|
to?: BlockchainAndTokenConfig;
|
|
110
114
|
liquiditySources?: string[];
|
|
111
|
-
wallets?: WalletType[];
|
|
115
|
+
wallets?: (WalletType | ProviderInterface)[];
|
|
112
116
|
multiWallets?: boolean;
|
|
113
117
|
customDestination?: boolean;
|
|
114
118
|
language?: string;
|
|
115
119
|
theme?: WidgetTheme;
|
|
120
|
+
externalWallets?: boolean;
|
|
116
121
|
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { allProviders } from '@rango-dev/provider-all';
|
|
2
|
+
import { ProviderInterface } from '@rango-dev/wallets-core';
|
|
3
|
+
import { WidgetConfig } from '../types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* Generate a list of providers by passing a provider name (e.g. metamask) or a custom provider which implemented ProviderInterface.
|
|
8
|
+
* @returns ProviderInterface[] a list of ProviderInterface
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
export function matchAndGenerateProviders(
|
|
12
|
+
providers: WidgetConfig['wallets']
|
|
13
|
+
): ProviderInterface[] {
|
|
14
|
+
const all = allProviders();
|
|
15
|
+
|
|
16
|
+
if (providers) {
|
|
17
|
+
const selectedProviders: ProviderInterface[] = [];
|
|
18
|
+
|
|
19
|
+
providers.forEach((requestedProvider) => {
|
|
20
|
+
// There are two types of provider we get, the first one is only passing the wallet name
|
|
21
|
+
// then we will match the wallet name with our providers (@rango-dev/provider-*).
|
|
22
|
+
// The second way is passing a custom provider which implemented ProviderInterface.
|
|
23
|
+
if (typeof requestedProvider === 'string') {
|
|
24
|
+
const result: ProviderInterface | undefined = all.find((provider) => {
|
|
25
|
+
return provider.config.type === requestedProvider;
|
|
26
|
+
});
|
|
27
|
+
if (result) {
|
|
28
|
+
selectedProviders.push(result);
|
|
29
|
+
} else {
|
|
30
|
+
console.warn(
|
|
31
|
+
`Couldn't find ${requestedProvider} provider. Please make sure you are passing the correct name.`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
// It's a custom provider so we directly push it to the list.
|
|
36
|
+
selectedProviders.push(requestedProvider);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return selectedProviders;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return all;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function configWalletsToWalletName(
|
|
46
|
+
config: WidgetConfig['wallets']
|
|
47
|
+
): string[] {
|
|
48
|
+
const providers = matchAndGenerateProviders(config);
|
|
49
|
+
const names = providers.map((provider) => {
|
|
50
|
+
return provider.config.type;
|
|
51
|
+
});
|
|
52
|
+
return names;
|
|
53
|
+
}
|
package/src/utils/wallets.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
detectInstallLink,
|
|
9
9
|
WalletInfo,
|
|
10
10
|
WalletTypes,
|
|
11
|
+
Networks,
|
|
11
12
|
} from '@rango-dev/wallets-shared';
|
|
12
13
|
|
|
13
14
|
import {
|
|
@@ -77,7 +78,7 @@ export function walletAndSupportedChainsNames(
|
|
|
77
78
|
if (!supportedChains) return null;
|
|
78
79
|
let walletAndSupportedChainsNames: Network[] = [];
|
|
79
80
|
walletAndSupportedChainsNames = supportedChains.map(
|
|
80
|
-
(blockchainMeta) => blockchainMeta.name
|
|
81
|
+
(blockchainMeta) => blockchainMeta.name
|
|
81
82
|
);
|
|
82
83
|
|
|
83
84
|
return walletAndSupportedChainsNames;
|
|
@@ -92,13 +93,18 @@ export function prepareAccountsForWalletStore(
|
|
|
92
93
|
const result: Wallet[] = [];
|
|
93
94
|
|
|
94
95
|
function addAccount(network: Network, address: string) {
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
const accountForChainAlreadyExists = !!result.find(
|
|
97
|
+
(account) => account.chain === network
|
|
98
|
+
);
|
|
99
|
+
if (!accountForChainAlreadyExists) {
|
|
100
|
+
const newAccount: Wallet = {
|
|
101
|
+
address,
|
|
102
|
+
chain: network,
|
|
103
|
+
walletType: wallet,
|
|
104
|
+
};
|
|
100
105
|
|
|
101
|
-
|
|
106
|
+
result.push(newAccount);
|
|
107
|
+
}
|
|
102
108
|
}
|
|
103
109
|
|
|
104
110
|
const supportedChains = supportedChainNames || [];
|
|
@@ -108,7 +114,7 @@ export function prepareAccountsForWalletStore(
|
|
|
108
114
|
|
|
109
115
|
const hasLimitation = supportedChains.length > 0;
|
|
110
116
|
const isSupported = supportedChains.includes(network);
|
|
111
|
-
const isUnknown = network ===
|
|
117
|
+
const isUnknown = network === Networks.Unknown;
|
|
112
118
|
const notSupportedNetworkByWallet =
|
|
113
119
|
hasLimitation && !isSupported && !isUnknown;
|
|
114
120
|
|
|
@@ -121,7 +127,7 @@ export function prepareAccountsForWalletStore(
|
|
|
121
127
|
// Example: showing our evm compatible netwrok when the uknown network is evem.
|
|
122
128
|
// Otherwise, we stop executing this function.
|
|
123
129
|
const isUknownAndEvmBased =
|
|
124
|
-
network ===
|
|
130
|
+
network === Networks.Unknown && isEvmAddress(address);
|
|
125
131
|
if (isUnknown && !isUknownAndEvmBased) return;
|
|
126
132
|
|
|
127
133
|
const isEvmBasedChain = evmBasedChains.includes(network);
|
|
@@ -233,7 +239,8 @@ export function isAccountAndWalletMatched(
|
|
|
233
239
|
) {
|
|
234
240
|
return (
|
|
235
241
|
account.address === connectedWallet.address &&
|
|
236
|
-
account.chain === connectedWallet.chain
|
|
242
|
+
account.chain === connectedWallet.chain &&
|
|
243
|
+
account.walletType === connectedWallet.walletType
|
|
237
244
|
);
|
|
238
245
|
}
|
|
239
246
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pendingSwap.d.ts","sourceRoot":"","sources":["../../src/mockData/pendingSwap.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW,EAAE,GA6lBzB,CAAC"}
|