@rango-dev/widget-embedded 0.5.1-next.1 → 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/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/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 +13 -7
- package/dist/mockData/pendingSwap.d.ts +0 -2
- package/dist/mockData/pendingSwap.d.ts.map +0 -1
- package/src/mockData/pendingSwap.ts +0 -607
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
|
@@ -93,13 +93,18 @@ export function prepareAccountsForWalletStore(
|
|
|
93
93
|
const result: Wallet[] = [];
|
|
94
94
|
|
|
95
95
|
function addAccount(network: Network, address: string) {
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
+
};
|
|
101
105
|
|
|
102
|
-
|
|
106
|
+
result.push(newAccount);
|
|
107
|
+
}
|
|
103
108
|
}
|
|
104
109
|
|
|
105
110
|
const supportedChains = supportedChainNames || [];
|
|
@@ -234,7 +239,8 @@ export function isAccountAndWalletMatched(
|
|
|
234
239
|
) {
|
|
235
240
|
return (
|
|
236
241
|
account.address === connectedWallet.address &&
|
|
237
|
-
account.chain === connectedWallet.chain
|
|
242
|
+
account.chain === connectedWallet.chain &&
|
|
243
|
+
account.walletType === connectedWallet.walletType
|
|
238
244
|
);
|
|
239
245
|
}
|
|
240
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"}
|