@rango-dev/widget-embedded 0.20.1-next.4 → 0.20.1-next.6
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/containers/Wallets/Wallets.d.ts.map +1 -1
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.d.ts +2 -2
- package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/store/slices/data.d.ts.map +1 -1
- package/dist/types/config.d.ts +16 -3
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/configs.d.ts +8 -0
- package/dist/utils/configs.d.ts.map +1 -1
- package/dist/utils/settings.d.ts +1 -1
- package/package.json +7 -7
- package/src/containers/Wallets/Wallets.tsx +11 -2
- package/src/hooks/useSyncStoresWithConfig.ts +17 -34
- package/src/index.ts +2 -0
- package/src/store/slices/data.ts +5 -7
- package/src/types/config.ts +16 -3
- package/src/utils/configs.ts +41 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../src/store/slices/data.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../src/store/slices/data.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAQ5C,KAAK,iBAAiB,GAAG;IACvB,IAAI,CAAC,EAAE,QAAQ,GAAG,aAAa,CAAC;CACjC,CAAC;AAEF,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,QAAQ,GAAG,aAAa,CAAC;IAE/B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AACF,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;AAC3D,MAAM,WAAW,SAAS;IACxB,YAAY,EAAE,cAAc,EAAE,CAAC;IAC/B,OAAO,EAAE,KAAK,EAAE,CAAC;IACjB,cAAc,EAAE,KAAK,EAAE,CAAC;IACxB,SAAS,EAAE,WAAW,EAAE,CAAC;IACzB,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,EAAE,CAAC,OAAO,CAAC,EAAE,iBAAiB,KAAK,cAAc,EAAE,CAAC;IAC/D,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,YAAY,KAAK,KAAK,EAAE,CAAC;IAC5C,QAAQ,EAAE,MAAM,WAAW,EAAE,CAAC;IAC9B,aAAa,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,GAAG,aAAa,KAAK,OAAO,CAAC;IAEzE,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAED,eAAO,MAAM,eAAe,EAAE,YAAY,CACxC,SAAS,GAAG,WAAW,EACvB;CAAE,EACF;CAAE,EACF,SAAS,CAsMT,CAAC"}
|
package/dist/types/config.d.ts
CHANGED
|
@@ -68,6 +68,17 @@ export type WidgetAffiliate = {
|
|
|
68
68
|
[key: string]: string;
|
|
69
69
|
};
|
|
70
70
|
};
|
|
71
|
+
/**
|
|
72
|
+
* `Tokens`
|
|
73
|
+
*
|
|
74
|
+
* @property {boolean} isExcluded - This is a boolean property capable of removing tokens from all or a blockchain.
|
|
75
|
+
* @property {Asset[]} tokens - The `tokens` property is an array of `Asset` objects that
|
|
76
|
+
* you could use that to limit tokens to some limited ones.
|
|
77
|
+
*/
|
|
78
|
+
export type Tokens = {
|
|
79
|
+
isExcluded: boolean;
|
|
80
|
+
tokens: Asset[];
|
|
81
|
+
};
|
|
71
82
|
/**
|
|
72
83
|
* `BlockchainAndTokenConfig`
|
|
73
84
|
*
|
|
@@ -76,8 +87,8 @@ export type WidgetAffiliate = {
|
|
|
76
87
|
* which is selected. e.g. {blockchain: 'BSC', symbol: 'BNB', address: null}
|
|
77
88
|
* @property {string[]} blockchains - An optional array of strings representing the supported
|
|
78
89
|
* blockchains. e.g. ['BSC','ETHEREUM']
|
|
79
|
-
* @property {Asset[]} tokens - The `tokens` property is an optional array of `Asset` objects
|
|
80
|
-
* you could use that to limit tokens to some limited ones.
|
|
90
|
+
* @property {Asset[] |{ [blockchain: string]: Tokens }} tokens - The `tokens` property is an optional object of `blockchain` objects or array of `Asset` objects
|
|
91
|
+
* that you could use that to limit tokens to some limited ones.
|
|
81
92
|
* @property {Asset} pinnedTokens - The `pinnedTokens` property is an optional array of `Asset` objects that
|
|
82
93
|
* you could use to pin tokens of your choice to the top of the token list.
|
|
83
94
|
*/
|
|
@@ -85,8 +96,10 @@ export type BlockchainAndTokenConfig = {
|
|
|
85
96
|
blockchain?: string;
|
|
86
97
|
token?: Asset;
|
|
87
98
|
blockchains?: string[];
|
|
88
|
-
tokens?: Asset[];
|
|
89
99
|
pinnedTokens?: Asset[];
|
|
100
|
+
tokens?: Asset[] | {
|
|
101
|
+
[blockchain: string]: Tokens;
|
|
102
|
+
};
|
|
90
103
|
};
|
|
91
104
|
/**
|
|
92
105
|
* `Features`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAA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,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,OAAO,CAAC,EAAE,CAAC,UAAU,GAAG,iBAAiB,CAAC,EAAE,CAAC;IAC7C,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,CAAC"}
|
package/dist/utils/configs.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import type { Tokens } from '../types';
|
|
2
|
+
import type { Asset, BlockchainMeta, Token } from 'rango-sdk';
|
|
1
3
|
export interface Configs {
|
|
2
4
|
API_KEY: string;
|
|
3
5
|
BASE_URL?: string;
|
|
4
6
|
}
|
|
7
|
+
type TokensConfig = Asset[] | {
|
|
8
|
+
[blockchain: string]: Tokens;
|
|
9
|
+
};
|
|
5
10
|
export declare function getConfig(name: keyof Configs): string;
|
|
6
11
|
export declare function setConfig(name: keyof Configs, value: any): any;
|
|
7
12
|
/**
|
|
@@ -12,4 +17,7 @@ export declare const DEFAULT_PRIMARY_RADIUS = 20;
|
|
|
12
17
|
export declare const DEFAULT_SECONDARY_RADIUS = 25;
|
|
13
18
|
export declare const DEFAULT_FONT_FAMILY = "Roboto";
|
|
14
19
|
export declare const THEME_CLASS_NAME_PREFIX = "theme-widget";
|
|
20
|
+
export declare const isTokenExcludedInConfig: (token: Token | null, tokensConfig?: TokensConfig) => boolean;
|
|
21
|
+
export declare const isBlockchainExcludedInConfig: (blockchain: BlockchainMeta | null, blockchainsConfig?: string[]) => boolean | null | undefined;
|
|
22
|
+
export {};
|
|
15
23
|
//# sourceMappingURL=configs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../../src/utils/configs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../../src/utils/configs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAM9D,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,KAAK,YAAY,GACb,KAAK,EAAE,GACP;IACE,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;CAC9B,CAAC;AAMN,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,OAAO,UAE5C;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,OAAO,EAAE,KAAK,EAAE,GAAG,OAIxD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,OAAO,WAS9C;AAED,eAAO,MAAM,sBAAsB,KAAK,CAAC;AACzC,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAC3C,eAAO,MAAM,mBAAmB,WAAW,CAAC;AAE5C,eAAO,MAAM,uBAAuB,iBAAiB,CAAC;AAEtD,eAAO,MAAM,uBAAuB,UAC3B,KAAK,GAAG,IAAI,iBACJ,YAAY,YAe5B,CAAC;AAEF,eAAO,MAAM,4BAA4B,eAC3B,cAAc,GAAG,IAAI,sBACb,MAAM,EAAE,+BAO7B,CAAC"}
|
package/dist/utils/settings.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type UniqueSwappersGroupType = {
|
|
|
9
9
|
selected: boolean;
|
|
10
10
|
};
|
|
11
11
|
export declare function getUniqueSwappersGroups(swappers: SwapperMeta[], disabledLiquiditySources: string[]): UniqueSwappersGroupType[];
|
|
12
|
-
export declare function sortLiquiditySourcesByGroupTitle(a: SwapperMeta, b: SwapperMeta):
|
|
12
|
+
export declare function sortLiquiditySourcesByGroupTitle(a: SwapperMeta, b: SwapperMeta): 0 | 1 | -1;
|
|
13
13
|
export declare function isFeatureHidden(feature: keyof Features, features?: Features): boolean;
|
|
14
14
|
export declare function isFeatureEnabled(feature: keyof Features, features?: Features): boolean;
|
|
15
15
|
//# sourceMappingURL=settings.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/widget-embedded",
|
|
3
|
-
"version": "0.20.1-next.
|
|
3
|
+
"version": "0.20.1-next.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@lingui/core": "4.2.1",
|
|
23
23
|
"@lingui/react": "4.2.1",
|
|
24
|
-
"@rango-dev/provider-all": "^0.25.1-next.
|
|
24
|
+
"@rango-dev/provider-all": "^0.25.1-next.2",
|
|
25
25
|
"@rango-dev/queue-manager-core": "^0.25.0",
|
|
26
|
-
"@rango-dev/queue-manager-rango-preset": "^0.25.1-next.
|
|
26
|
+
"@rango-dev/queue-manager-rango-preset": "^0.25.1-next.1",
|
|
27
27
|
"@rango-dev/queue-manager-react": "^0.24.0",
|
|
28
|
-
"@rango-dev/ui": "^0.26.1-next.
|
|
29
|
-
"@rango-dev/wallets-react": "^0.11.1-next.
|
|
30
|
-
"@rango-dev/wallets-shared": "^0.25.1-next.
|
|
28
|
+
"@rango-dev/ui": "^0.26.1-next.3",
|
|
29
|
+
"@rango-dev/wallets-react": "^0.11.1-next.1",
|
|
30
|
+
"@rango-dev/wallets-shared": "^0.25.1-next.1",
|
|
31
31
|
"bignumber.js": "^9.1.1",
|
|
32
32
|
"copy-to-clipboard": "^3.3.3",
|
|
33
33
|
"dayjs": "^1.11.7",
|
|
@@ -47,4 +47,4 @@
|
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
}
|
|
50
|
-
}
|
|
50
|
+
}
|
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
PropTypes,
|
|
4
4
|
WidgetContextInterface,
|
|
5
5
|
} from './Wallets.types';
|
|
6
|
+
import type { Wallet } from '../../types/wallets';
|
|
6
7
|
import type { ProvidersOptions } from '../../utils/providers';
|
|
7
8
|
import type { EventHandler } from '@rango-dev/wallets-react';
|
|
8
9
|
import type { Network } from '@rango-dev/wallets-shared';
|
|
@@ -10,7 +11,7 @@ import type { PropsWithChildren } from 'react';
|
|
|
10
11
|
|
|
11
12
|
import { Events, Provider } from '@rango-dev/wallets-react';
|
|
12
13
|
import { isEvmBlockchain } from 'rango-sdk';
|
|
13
|
-
import React, { createContext, useEffect, useRef } from 'react';
|
|
14
|
+
import React, { createContext, useEffect, useRef, useState } from 'react';
|
|
14
15
|
|
|
15
16
|
import { useSyncStoresWithConfig } from '../../hooks/useSyncStoresWithConfig';
|
|
16
17
|
import { useWalletProviders } from '../../hooks/useWalletProviders';
|
|
@@ -34,6 +35,7 @@ function Main(props: PropsWithChildren<PropTypes>) {
|
|
|
34
35
|
const walletOptions: ProvidersOptions = {
|
|
35
36
|
walletConnectProjectId: props.config?.walletConnectProjectId,
|
|
36
37
|
};
|
|
38
|
+
const [accounts, setAccounts] = useState<Wallet[]>([]);
|
|
37
39
|
const { providers } = useWalletProviders(props.config.wallets, walletOptions);
|
|
38
40
|
const { connectWallet, disconnectWallet } = useWalletsStore();
|
|
39
41
|
const onConnectWalletHandler = useRef<OnConnectHandler>();
|
|
@@ -66,7 +68,7 @@ function Main(props: PropsWithChildren<PropTypes>) {
|
|
|
66
68
|
supportedChainNames,
|
|
67
69
|
meta.isContractWallet
|
|
68
70
|
);
|
|
69
|
-
|
|
71
|
+
setAccounts(data);
|
|
70
72
|
} else {
|
|
71
73
|
disconnectWallet(type);
|
|
72
74
|
}
|
|
@@ -99,6 +101,13 @@ function Main(props: PropsWithChildren<PropTypes>) {
|
|
|
99
101
|
props.onUpdateState(type, event, value, state, meta);
|
|
100
102
|
}
|
|
101
103
|
};
|
|
104
|
+
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (accounts.length) {
|
|
107
|
+
connectWallet(accounts, tokens);
|
|
108
|
+
}
|
|
109
|
+
}, [accounts, tokens]);
|
|
110
|
+
|
|
102
111
|
return (
|
|
103
112
|
<WidgetContext.Provider
|
|
104
113
|
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { Asset } from 'rango-sdk';
|
|
2
2
|
|
|
3
|
-
import { useEffect, useLayoutEffect,
|
|
3
|
+
import { useEffect, useLayoutEffect, useRef } from 'react';
|
|
4
4
|
|
|
5
5
|
import { useAppStore } from '../store/AppStore';
|
|
6
6
|
import { useQuoteStore } from '../store/quote';
|
|
7
|
+
import {
|
|
8
|
+
isBlockchainExcludedInConfig,
|
|
9
|
+
isTokenExcludedInConfig,
|
|
10
|
+
} from '../utils/configs';
|
|
7
11
|
import { tokensAreEqual } from '../utils/wallets';
|
|
8
12
|
|
|
9
13
|
export function useSyncStoresWithConfig() {
|
|
@@ -27,22 +31,10 @@ export function useSyncStoresWithConfig() {
|
|
|
27
31
|
const { setAffiliateRef, setAffiliatePercent, setAffiliateWallets } =
|
|
28
32
|
useAppStore();
|
|
29
33
|
|
|
30
|
-
const fromTokensConfig =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const fromBlockchainsConfig = useMemo(
|
|
35
|
-
() => config?.from?.blockchains,
|
|
36
|
-
[config?.from?.blockchains]
|
|
37
|
-
);
|
|
38
|
-
const toTokensConfig = useMemo(
|
|
39
|
-
() => config?.to?.tokens,
|
|
40
|
-
[config?.to?.tokens]
|
|
41
|
-
);
|
|
42
|
-
const toBlockchainsConfig = useMemo(
|
|
43
|
-
() => config?.to?.blockchains,
|
|
44
|
-
[config?.to?.blockchains]
|
|
45
|
-
);
|
|
34
|
+
const fromTokensConfig = config?.from?.tokens;
|
|
35
|
+
const fromBlockchainsConfig = config?.from?.blockchains;
|
|
36
|
+
const toTokensConfig = config?.to?.tokens;
|
|
37
|
+
const toBlockchainsConfig = config?.to?.blockchains;
|
|
46
38
|
const prevConfigFromToken = useRef<Asset | undefined>(undefined);
|
|
47
39
|
const prevConfigToToken = useRef<Asset | undefined>(undefined);
|
|
48
40
|
const prevConfigFromBlockchain = useRef<string | undefined>(undefined);
|
|
@@ -90,30 +82,21 @@ export function useSyncStoresWithConfig() {
|
|
|
90
82
|
]);
|
|
91
83
|
|
|
92
84
|
useEffect(() => {
|
|
93
|
-
if (fromToken
|
|
94
|
-
|
|
95
|
-
setFromToken({ token: null });
|
|
96
|
-
}
|
|
85
|
+
if (isTokenExcludedInConfig(fromToken, fromTokensConfig)) {
|
|
86
|
+
setFromToken({ token: null });
|
|
97
87
|
}
|
|
98
88
|
|
|
99
|
-
if (fromBlockchain
|
|
100
|
-
|
|
101
|
-
setFromBlockchain(null);
|
|
102
|
-
}
|
|
89
|
+
if (isBlockchainExcludedInConfig(fromBlockchain, fromBlockchainsConfig)) {
|
|
90
|
+
setFromBlockchain(null);
|
|
103
91
|
}
|
|
104
92
|
}, [fromTokensConfig, fromBlockchainsConfig]);
|
|
105
93
|
|
|
106
94
|
useEffect(() => {
|
|
107
|
-
if (toToken
|
|
108
|
-
|
|
109
|
-
setToToken({ token: null });
|
|
110
|
-
}
|
|
95
|
+
if (isTokenExcludedInConfig(toToken, toTokensConfig)) {
|
|
96
|
+
setFromToken({ token: null });
|
|
111
97
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (!toBlockchainsConfig.includes(toBlockchain.name)) {
|
|
115
|
-
setToBlockchain(null);
|
|
116
|
-
}
|
|
98
|
+
if (isBlockchainExcludedInConfig(toBlockchain, toBlockchainsConfig)) {
|
|
99
|
+
setToBlockchain(null);
|
|
117
100
|
}
|
|
118
101
|
}, [toTokensConfig, toBlockchainsConfig]);
|
|
119
102
|
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { WidgetProps } from './containers/Widget';
|
|
|
2
2
|
import type { ConnectedWallet } from './store/wallets';
|
|
3
3
|
import type {
|
|
4
4
|
BlockchainAndTokenConfig,
|
|
5
|
+
Tokens,
|
|
5
6
|
WidgetColors,
|
|
6
7
|
WidgetColorsKeys,
|
|
7
8
|
WidgetConfig,
|
|
@@ -86,6 +87,7 @@ export type {
|
|
|
86
87
|
StepOutputRevealedEvent,
|
|
87
88
|
HandleWalletsUpdate,
|
|
88
89
|
ConnectedWallet,
|
|
90
|
+
Tokens,
|
|
89
91
|
};
|
|
90
92
|
export {
|
|
91
93
|
Widget,
|
package/src/store/slices/data.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { StateCreator } from 'zustand';
|
|
|
6
6
|
|
|
7
7
|
import { httpService as sdk } from '../../services/httpService';
|
|
8
8
|
import { containsText } from '../../utils/common';
|
|
9
|
+
import { isTokenExcludedInConfig } from '../../utils/configs';
|
|
9
10
|
import { sortLiquiditySourcesByGroupTitle } from '../../utils/settings';
|
|
10
11
|
import { tokensAreEqual } from '../../utils/wallets';
|
|
11
12
|
|
|
@@ -81,21 +82,18 @@ export const createDataSlice: StateCreator<
|
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
const config = get().config;
|
|
84
|
-
const
|
|
85
|
+
const supportedTokensConfig =
|
|
85
86
|
(options.type === 'source' ? config.from?.tokens : config.to?.tokens) ??
|
|
86
|
-
|
|
87
|
+
{};
|
|
87
88
|
const blockchains = get().blockchains({
|
|
88
89
|
type: options.type,
|
|
89
90
|
});
|
|
90
91
|
|
|
91
92
|
const list = tokensFromState
|
|
92
93
|
.filter((token) => {
|
|
93
|
-
// If there is a list of tokens in config, we only keep them.
|
|
94
94
|
if (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return tokensAreEqual(asset, token);
|
|
98
|
-
})
|
|
95
|
+
supportedTokensConfig &&
|
|
96
|
+
isTokenExcludedInConfig(token, supportedTokensConfig)
|
|
99
97
|
) {
|
|
100
98
|
return false;
|
|
101
99
|
}
|
package/src/types/config.ts
CHANGED
|
@@ -67,6 +67,19 @@ export type WidgetAffiliate = {
|
|
|
67
67
|
wallets?: { [key: string]: string };
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
+
/**
|
|
71
|
+
* `Tokens`
|
|
72
|
+
*
|
|
73
|
+
* @property {boolean} isExcluded - This is a boolean property capable of removing tokens from all or a blockchain.
|
|
74
|
+
* @property {Asset[]} tokens - The `tokens` property is an array of `Asset` objects that
|
|
75
|
+
* you could use that to limit tokens to some limited ones.
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
export type Tokens = {
|
|
79
|
+
isExcluded: boolean;
|
|
80
|
+
tokens: Asset[];
|
|
81
|
+
};
|
|
82
|
+
|
|
70
83
|
/**
|
|
71
84
|
* `BlockchainAndTokenConfig`
|
|
72
85
|
*
|
|
@@ -75,8 +88,8 @@ export type WidgetAffiliate = {
|
|
|
75
88
|
* which is selected. e.g. {blockchain: 'BSC', symbol: 'BNB', address: null}
|
|
76
89
|
* @property {string[]} blockchains - An optional array of strings representing the supported
|
|
77
90
|
* blockchains. e.g. ['BSC','ETHEREUM']
|
|
78
|
-
* @property {Asset[]} tokens - The `tokens` property is an optional array of `Asset` objects
|
|
79
|
-
* you could use that to limit tokens to some limited ones.
|
|
91
|
+
* @property {Asset[] |{ [blockchain: string]: Tokens }} tokens - The `tokens` property is an optional object of `blockchain` objects or array of `Asset` objects
|
|
92
|
+
* that you could use that to limit tokens to some limited ones.
|
|
80
93
|
* @property {Asset} pinnedTokens - The `pinnedTokens` property is an optional array of `Asset` objects that
|
|
81
94
|
* you could use to pin tokens of your choice to the top of the token list.
|
|
82
95
|
*/
|
|
@@ -84,8 +97,8 @@ export type BlockchainAndTokenConfig = {
|
|
|
84
97
|
blockchain?: string;
|
|
85
98
|
token?: Asset;
|
|
86
99
|
blockchains?: string[];
|
|
87
|
-
tokens?: Asset[];
|
|
88
100
|
pinnedTokens?: Asset[];
|
|
101
|
+
tokens?: Asset[] | { [blockchain: string]: Tokens };
|
|
89
102
|
};
|
|
90
103
|
|
|
91
104
|
/**
|
package/src/utils/configs.ts
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
|
+
import type { Tokens } from '../types';
|
|
2
|
+
import type { Asset, BlockchainMeta, Token } from 'rango-sdk';
|
|
3
|
+
|
|
1
4
|
import { RANGO_PUBLIC_API_KEY } from '../constants';
|
|
2
5
|
|
|
6
|
+
import { tokensAreEqual } from './wallets';
|
|
7
|
+
|
|
3
8
|
export interface Configs {
|
|
4
9
|
API_KEY: string;
|
|
5
10
|
BASE_URL?: string;
|
|
6
11
|
}
|
|
7
12
|
|
|
13
|
+
type TokensConfig =
|
|
14
|
+
| Asset[]
|
|
15
|
+
| {
|
|
16
|
+
[blockchain: string]: Tokens;
|
|
17
|
+
};
|
|
18
|
+
|
|
8
19
|
let configs: Configs = {
|
|
9
20
|
API_KEY: RANGO_PUBLIC_API_KEY,
|
|
10
21
|
};
|
|
@@ -38,3 +49,33 @@ export const DEFAULT_SECONDARY_RADIUS = 25;
|
|
|
38
49
|
export const DEFAULT_FONT_FAMILY = 'Roboto';
|
|
39
50
|
|
|
40
51
|
export const THEME_CLASS_NAME_PREFIX = `theme-widget`;
|
|
52
|
+
|
|
53
|
+
export const isTokenExcludedInConfig = (
|
|
54
|
+
token: Token | null,
|
|
55
|
+
tokensConfig?: TokensConfig
|
|
56
|
+
) => {
|
|
57
|
+
let result = false;
|
|
58
|
+
if (tokensConfig && token) {
|
|
59
|
+
if (Array.isArray(tokensConfig)) {
|
|
60
|
+
result = !tokensConfig.some((asset) => tokensAreEqual(asset, token));
|
|
61
|
+
} else if (!Array.isArray(tokensConfig) && tokensConfig[token.blockchain]) {
|
|
62
|
+
result = tokensConfig[token.blockchain].tokens.some((asset) =>
|
|
63
|
+
tokensAreEqual(asset, token)
|
|
64
|
+
);
|
|
65
|
+
const isExcluded = tokensConfig[token.blockchain].isExcluded;
|
|
66
|
+
return (!isExcluded && !result) || (isExcluded && result);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const isBlockchainExcludedInConfig = (
|
|
73
|
+
blockchain: BlockchainMeta | null,
|
|
74
|
+
blockchainsConfig?: string[]
|
|
75
|
+
) => {
|
|
76
|
+
return (
|
|
77
|
+
blockchain &&
|
|
78
|
+
blockchainsConfig &&
|
|
79
|
+
!blockchainsConfig.includes(blockchain.name)
|
|
80
|
+
);
|
|
81
|
+
};
|