@rango-dev/widget-embedded 0.36.0 → 0.36.1-next.1
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/CHANGELOG.md +17 -0
- package/dist/QueueManager.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
- package/dist/components/Layout/Layout.d.ts.map +1 -1
- package/dist/components/Quote/Quote.styles.d.ts +1 -1
- package/dist/components/RefreshModal/RefreshModal.styles.d.ts +1 -1
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.d.ts.map +1 -1
- package/dist/containers/Inputs/Inputs.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
- package/dist/containers/WidgetInfo/WidgetInfo.d.ts.map +1 -1
- package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts +2 -2
- package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts.map +1 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
- package/dist/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.d.ts.map +1 -1
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/hooks/useWalletList.d.ts.map +1 -1
- package/dist/hooks/useWalletProviders/useWalletProviders.d.ts +1 -2
- package/dist/hooks/useWalletProviders/useWalletProviders.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
- package/dist/store/app.d.ts +2 -4
- package/dist/store/app.d.ts.map +1 -1
- package/dist/store/slices/config.d.ts.map +1 -1
- package/dist/store/slices/types.d.ts +6 -0
- package/dist/store/slices/types.d.ts.map +1 -0
- package/dist/store/slices/wallets.d.ts +58 -0
- package/dist/store/slices/wallets.d.ts.map +1 -0
- package/dist/store/utils/wallets.d.ts +17 -0
- package/dist/store/utils/wallets.d.ts.map +1 -0
- package/dist/types/config.d.ts +6 -3
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/wallets.d.ts +1 -1
- package/dist/types/wallets.d.ts.map +1 -1
- package/dist/utils/hub.d.ts +4 -0
- package/dist/utils/hub.d.ts.map +1 -0
- package/dist/utils/providers.d.ts +3 -8
- package/dist/utils/providers.d.ts.map +1 -1
- package/dist/utils/settings.d.ts +1 -0
- package/dist/utils/settings.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +1 -1
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +12 -14
- package/dist/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +7 -7
- package/src/QueueManager.tsx +12 -7
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +3 -5
- package/src/components/ConfirmWalletsModal/WalletList.tsx +10 -7
- package/src/components/Layout/Layout.tsx +1 -3
- package/src/components/SwapDetails/SwapDetails.tsx +6 -1
- package/src/components/SwapDetailsAlerts/SwapDetailsAlerts.types.ts +1 -1
- package/src/components/TokenList/TokenList.tsx +4 -27
- package/src/containers/Inputs/Inputs.tsx +20 -7
- package/src/containers/Wallets/Wallets.tsx +20 -14
- package/src/containers/WidgetInfo/WidgetInfo.tsx +10 -8
- package/src/containers/WidgetInfo/WidgetInfo.types.ts +2 -2
- package/src/hooks/useStatefulConnect/useStatefulConnect.ts +40 -2
- package/src/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.ts +7 -6
- package/src/hooks/useSwapInput.ts +1 -2
- package/src/hooks/useWalletList.ts +1 -3
- package/src/hooks/useWalletProviders/useWalletProviders.ts +3 -7
- package/src/index.ts +1 -1
- package/src/pages/Home.tsx +5 -3
- package/src/pages/SelectSwapItemsPage.tsx +1 -2
- package/src/store/app.ts +4 -4
- package/src/store/slices/config.ts +3 -0
- package/src/store/slices/types.ts +9 -0
- package/src/store/slices/wallets.ts +477 -0
- package/src/store/utils/wallets.ts +108 -0
- package/src/types/config.ts +7 -3
- package/src/types/wallets.ts +1 -1
- package/src/utils/hub.ts +22 -0
- package/src/utils/providers.ts +68 -12
- package/src/utils/settings.ts +4 -0
- package/src/utils/swap.ts +1 -1
- package/src/utils/wallets.ts +74 -137
- package/dist/hooks/useObserveBalanceChanges/index.d.ts +0 -2
- package/dist/hooks/useObserveBalanceChanges/index.d.ts.map +0 -1
- package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts +0 -4
- package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts.map +0 -1
- package/dist/store/wallets.d.ts +0 -66
- package/dist/store/wallets.d.ts.map +0 -1
- package/src/hooks/useObserveBalanceChanges/index.ts +0 -1
- package/src/hooks/useObserveBalanceChanges/useObserveBalanceChanges.ts +0 -68
- package/src/store/wallets.ts +0 -268
package/src/types/config.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Language, theme } from '@rango-dev/ui';
|
|
2
|
-
import type {
|
|
2
|
+
import type { LegacyProviderInterface } from '@rango-dev/wallets-core/dist/legacy/mod';
|
|
3
3
|
import type { WalletType } from '@rango-dev/wallets-shared';
|
|
4
4
|
import type { Asset } from 'rango-sdk';
|
|
5
5
|
|
|
@@ -129,6 +129,9 @@ export type SignersConfig = {
|
|
|
129
129
|
*
|
|
130
130
|
* @property {'visible' | 'hidden'} [liquiditySource]
|
|
131
131
|
* - The visibility state for the liquiditySource feature. Optional property.
|
|
132
|
+
*
|
|
133
|
+
* @property {'disabled' | 'enabled'} [experimentalWallet]
|
|
134
|
+
* - Enable our experimental version of wallets. Default: disable on production, enabled on dev.
|
|
132
135
|
*/
|
|
133
136
|
export type Features = Partial<
|
|
134
137
|
Record<
|
|
@@ -140,7 +143,8 @@ export type Features = Partial<
|
|
|
140
143
|
| 'customTokens',
|
|
141
144
|
'visible' | 'hidden'
|
|
142
145
|
>
|
|
143
|
-
|
|
146
|
+
> &
|
|
147
|
+
Partial<Record<'experimentalWallet', 'disabled' | 'enabled'>>;
|
|
144
148
|
|
|
145
149
|
/**
|
|
146
150
|
* `Routing`
|
|
@@ -253,7 +257,7 @@ export type WidgetConfig = {
|
|
|
253
257
|
from?: BlockchainAndTokenConfig;
|
|
254
258
|
to?: BlockchainAndTokenConfig;
|
|
255
259
|
liquiditySources?: string[];
|
|
256
|
-
wallets?: (WalletType |
|
|
260
|
+
wallets?: (WalletType | LegacyProviderInterface)[];
|
|
257
261
|
multiWallets?: boolean;
|
|
258
262
|
customDestination?: boolean;
|
|
259
263
|
defaultCustomDestinations?: { [blockchain: string]: string };
|
package/src/types/wallets.ts
CHANGED
package/src/utils/hub.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CommonNamespaceKeys } from '@rango-dev/wallets-core';
|
|
2
|
+
|
|
3
|
+
import { Namespace } from '@rango-dev/wallets-shared';
|
|
4
|
+
|
|
5
|
+
export function convertCommonNamespacesKeysToLegacyNamespace(
|
|
6
|
+
namespaces: CommonNamespaceKeys[]
|
|
7
|
+
): Namespace[] {
|
|
8
|
+
return namespaces.map((namespace) => {
|
|
9
|
+
switch (namespace) {
|
|
10
|
+
case 'evm':
|
|
11
|
+
return Namespace.Evm;
|
|
12
|
+
case 'solana':
|
|
13
|
+
return Namespace.Solana;
|
|
14
|
+
case 'cosmos':
|
|
15
|
+
return Namespace.Cosmos;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
throw new Error(
|
|
19
|
+
'Can not convert this common namespace key to a proper legacy key.'
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
}
|
package/src/utils/providers.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { WidgetConfig } from '../types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { LegacyProviderInterface } from '@rango-dev/wallets-core/legacy';
|
|
3
3
|
|
|
4
4
|
import { allProviders } from '@rango-dev/provider-all';
|
|
5
|
+
import {
|
|
6
|
+
defineVersions,
|
|
7
|
+
pickVersion,
|
|
8
|
+
Provider,
|
|
9
|
+
type VersionedProviders,
|
|
10
|
+
} from '@rango-dev/wallets-core';
|
|
5
11
|
|
|
6
12
|
export interface ProvidersOptions {
|
|
7
13
|
walletConnectProjectId?: WidgetConfig['walletConnectProjectId'];
|
|
@@ -10,19 +16,21 @@ export interface ProvidersOptions {
|
|
|
10
16
|
>['walletConnectListedDesktopWalletLink'];
|
|
11
17
|
trezorManifest: WidgetConfig['trezorManifest'];
|
|
12
18
|
tonConnect: WidgetConfig['tonConnect'];
|
|
19
|
+
experimentalWallet?: 'enabled' | 'disabled';
|
|
13
20
|
}
|
|
14
21
|
|
|
15
22
|
/**
|
|
16
23
|
*
|
|
17
24
|
* Generate a list of providers by passing a provider name (e.g. metamask) or a custom provider which implemented ProviderInterface.
|
|
18
|
-
* @returns
|
|
25
|
+
* @returns BothProvidersInterface[] a list of BothProvidersInterface
|
|
19
26
|
*
|
|
20
27
|
*/
|
|
28
|
+
type BothProvidersInterface = LegacyProviderInterface | Provider;
|
|
21
29
|
export function matchAndGenerateProviders(
|
|
22
30
|
providers: WidgetConfig['wallets'],
|
|
23
31
|
options?: ProvidersOptions
|
|
24
|
-
):
|
|
25
|
-
const
|
|
32
|
+
): VersionedProviders[] {
|
|
33
|
+
const envs = {
|
|
26
34
|
walletconnect2: {
|
|
27
35
|
WC_PROJECT_ID: options?.walletConnectProjectId || '',
|
|
28
36
|
DISABLE_MODAL_AND_OPEN_LINK:
|
|
@@ -35,10 +43,12 @@ export function matchAndGenerateProviders(
|
|
|
35
43
|
tonConnect: options?.tonConnect?.manifestUrl
|
|
36
44
|
? { manifestUrl: options?.tonConnect.manifestUrl }
|
|
37
45
|
: undefined,
|
|
38
|
-
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const all = allProviders(envs);
|
|
39
49
|
|
|
40
50
|
if (providers) {
|
|
41
|
-
const selectedProviders:
|
|
51
|
+
const selectedProviders: VersionedProviders[] = [];
|
|
42
52
|
|
|
43
53
|
providers.forEach((requestedProvider) => {
|
|
44
54
|
/*
|
|
@@ -47,11 +57,24 @@ export function matchAndGenerateProviders(
|
|
|
47
57
|
* The second way is passing a custom provider which implemented ProviderInterface.
|
|
48
58
|
*/
|
|
49
59
|
if (typeof requestedProvider === 'string') {
|
|
50
|
-
const result:
|
|
51
|
-
|
|
52
|
-
|
|
60
|
+
const result: BothProvidersInterface | undefined =
|
|
61
|
+
pickVersionWithFallbackToLegacy(all, options).find((provider) => {
|
|
62
|
+
if (provider instanceof Provider) {
|
|
63
|
+
return provider.id === requestedProvider;
|
|
64
|
+
}
|
|
65
|
+
return provider.config.type === requestedProvider;
|
|
66
|
+
});
|
|
67
|
+
|
|
53
68
|
if (result) {
|
|
54
|
-
|
|
69
|
+
if (result instanceof Provider) {
|
|
70
|
+
selectedProviders.push(
|
|
71
|
+
defineVersions().version('1.0.0', result).build()
|
|
72
|
+
);
|
|
73
|
+
} else {
|
|
74
|
+
selectedProviders.push(
|
|
75
|
+
defineVersions().version('0.0.0', result).build()
|
|
76
|
+
);
|
|
77
|
+
}
|
|
55
78
|
} else {
|
|
56
79
|
console.warn(
|
|
57
80
|
`Couldn't find ${requestedProvider} provider. Please make sure you are passing the correct name.`
|
|
@@ -59,21 +82,54 @@ export function matchAndGenerateProviders(
|
|
|
59
82
|
}
|
|
60
83
|
} else {
|
|
61
84
|
// It's a custom provider so we directly push it to the list.
|
|
62
|
-
|
|
85
|
+
if (requestedProvider instanceof Provider) {
|
|
86
|
+
selectedProviders.push(
|
|
87
|
+
defineVersions().version('1.0.0', requestedProvider).build()
|
|
88
|
+
);
|
|
89
|
+
} else {
|
|
90
|
+
selectedProviders.push(
|
|
91
|
+
defineVersions().version('0.0.0', requestedProvider).build()
|
|
92
|
+
);
|
|
93
|
+
}
|
|
63
94
|
}
|
|
64
95
|
});
|
|
96
|
+
|
|
65
97
|
return selectedProviders;
|
|
66
98
|
}
|
|
67
99
|
|
|
68
100
|
return all;
|
|
69
101
|
}
|
|
70
102
|
|
|
103
|
+
// TODO: this is a duplication with what we do in core.
|
|
104
|
+
function pickVersionWithFallbackToLegacy(
|
|
105
|
+
providers: VersionedProviders[],
|
|
106
|
+
options?: ProvidersOptions
|
|
107
|
+
): BothProvidersInterface[] {
|
|
108
|
+
const { experimentalWallet = 'enabled' } = options || {};
|
|
109
|
+
|
|
110
|
+
return providers.map((provider) => {
|
|
111
|
+
const version = experimentalWallet == 'disabled' ? '0.0.0' : '1.0.0';
|
|
112
|
+
try {
|
|
113
|
+
return pickVersion(provider, version)[1];
|
|
114
|
+
} catch {
|
|
115
|
+
// Fallback to legacy version, if target version doesn't exists.
|
|
116
|
+
return pickVersion(provider, '0.0.0')[1];
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
71
121
|
export function configWalletsToWalletName(
|
|
72
122
|
config: WidgetConfig['wallets'],
|
|
73
123
|
options?: ProvidersOptions
|
|
74
124
|
): string[] {
|
|
75
|
-
const providers =
|
|
125
|
+
const providers = pickVersionWithFallbackToLegacy(
|
|
126
|
+
matchAndGenerateProviders(config, options),
|
|
127
|
+
options
|
|
128
|
+
);
|
|
76
129
|
const names = providers.map((provider) => {
|
|
130
|
+
if (provider instanceof Provider) {
|
|
131
|
+
return provider.id;
|
|
132
|
+
}
|
|
77
133
|
return provider.config.type;
|
|
78
134
|
});
|
|
79
135
|
return names;
|
package/src/utils/settings.ts
CHANGED
|
@@ -72,6 +72,10 @@ export function isFeatureHidden(feature: keyof Features, features?: Features) {
|
|
|
72
72
|
return features?.[feature] === 'hidden';
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
export function isFeatureEnabled(feature: keyof Features, features?: Features) {
|
|
76
|
+
return features?.[feature] === 'enabled';
|
|
77
|
+
}
|
|
78
|
+
|
|
75
79
|
export function isRoutingEnabled(item: keyof Routing, routing?: Routing) {
|
|
76
80
|
return routing?.[item] === 'enabled';
|
|
77
81
|
}
|
package/src/utils/swap.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
2
|
import type { FeesGroup, NameOfFees } from '../constants/quote';
|
|
3
3
|
import type { FetchStatus, FindToken } from '../store/slices/data';
|
|
4
|
-
import type { ConnectedWallet } from '../store/wallets';
|
|
4
|
+
import type { ConnectedWallet } from '../store/slices/wallets';
|
|
5
5
|
import type {
|
|
6
6
|
ConvertedToken,
|
|
7
7
|
QuoteError,
|
package/src/utils/wallets.ts
CHANGED
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ConnectedWallet, TokenBalance } from '../store/wallets';
|
|
1
|
+
import type { BalanceState, ConnectedWallet } from '../store/slices/wallets';
|
|
3
2
|
import type {
|
|
4
3
|
Balance,
|
|
5
4
|
SelectedQuote,
|
|
6
|
-
TokensBalance,
|
|
7
5
|
Wallet,
|
|
8
6
|
WalletInfoWithExtra,
|
|
9
7
|
} from '../types';
|
|
10
|
-
import type {
|
|
8
|
+
import type { ExtendedWalletInfo } from '@rango-dev/wallets-react';
|
|
11
9
|
import type {
|
|
12
10
|
Network,
|
|
13
|
-
WalletInfo,
|
|
14
11
|
WalletState,
|
|
15
12
|
WalletType,
|
|
16
13
|
WalletTypes,
|
|
17
14
|
} from '@rango-dev/wallets-shared';
|
|
18
|
-
import type {
|
|
19
|
-
BlockchainMeta,
|
|
20
|
-
Token,
|
|
21
|
-
TransactionType,
|
|
22
|
-
WalletDetail,
|
|
23
|
-
} from 'rango-sdk';
|
|
15
|
+
import type { BlockchainMeta, Token, TransactionType } from 'rango-sdk';
|
|
24
16
|
|
|
25
17
|
import {
|
|
26
18
|
BlockchainCategories,
|
|
@@ -47,9 +39,11 @@ import {
|
|
|
47
39
|
import { EXCLUDED_WALLETS } from '../constants/wallets';
|
|
48
40
|
|
|
49
41
|
import { isBlockchainTypeInCategory, removeDuplicateFrom } from './common';
|
|
50
|
-
import { createTokenHash } from './meta';
|
|
51
42
|
import { numberToString } from './numbers';
|
|
52
43
|
|
|
44
|
+
export type ExtendedModalWalletInfo = WalletInfoWithExtra &
|
|
45
|
+
Pick<ExtendedWalletInfo, 'properties' | 'isHub'>;
|
|
46
|
+
|
|
53
47
|
export function mapStatusToWalletState(state: WalletState): WalletStatus {
|
|
54
48
|
switch (true) {
|
|
55
49
|
case state.connected:
|
|
@@ -65,10 +59,10 @@ export function mapStatusToWalletState(state: WalletState): WalletStatus {
|
|
|
65
59
|
|
|
66
60
|
export function mapWalletTypesToWalletInfo(
|
|
67
61
|
getState: (type: WalletType) => WalletState,
|
|
68
|
-
getWalletInfo: (type: WalletType) =>
|
|
62
|
+
getWalletInfo: (type: WalletType) => ExtendedWalletInfo,
|
|
69
63
|
list: WalletType[],
|
|
70
64
|
chain?: string
|
|
71
|
-
):
|
|
65
|
+
): ExtendedModalWalletInfo[] {
|
|
72
66
|
return list
|
|
73
67
|
.filter((wallet) => !EXCLUDED_WALLETS.includes(wallet as WalletTypes))
|
|
74
68
|
.filter((wallet) => {
|
|
@@ -97,6 +91,8 @@ export function mapWalletTypesToWalletInfo(
|
|
|
97
91
|
singleNamespace,
|
|
98
92
|
supportedChains,
|
|
99
93
|
needsDerivationPath,
|
|
94
|
+
properties,
|
|
95
|
+
isHub,
|
|
100
96
|
} = getWalletInfo(type);
|
|
101
97
|
const blockchainTypes = removeDuplicateFrom(
|
|
102
98
|
supportedChains.map((item) => item.type)
|
|
@@ -114,6 +110,8 @@ export function mapWalletTypesToWalletInfo(
|
|
|
114
110
|
singleNamespace,
|
|
115
111
|
blockchainTypes,
|
|
116
112
|
needsDerivationPath,
|
|
113
|
+
properties,
|
|
114
|
+
isHub,
|
|
117
115
|
};
|
|
118
116
|
});
|
|
119
117
|
}
|
|
@@ -265,8 +263,6 @@ export function getQuoteWallets(params: {
|
|
|
265
263
|
return Array.from(wallets);
|
|
266
264
|
}
|
|
267
265
|
|
|
268
|
-
type Blockchain = { name: string; accounts: ConnectedWallet[] };
|
|
269
|
-
|
|
270
266
|
export function isAccountAndWalletMatched(
|
|
271
267
|
account: Wallet,
|
|
272
268
|
connectedWallet: ConnectedWallet
|
|
@@ -278,74 +274,18 @@ export function isAccountAndWalletMatched(
|
|
|
278
274
|
);
|
|
279
275
|
}
|
|
280
276
|
|
|
281
|
-
export function makeBalanceFor(
|
|
282
|
-
retrievedBalance: WalletDetail,
|
|
283
|
-
findToken: FindToken
|
|
284
|
-
): TokenBalance[] {
|
|
285
|
-
const { blockChain: chain, balances = [] } = retrievedBalance;
|
|
286
|
-
return (
|
|
287
|
-
balances?.map((tokenBalance) => ({
|
|
288
|
-
chain,
|
|
289
|
-
symbol: tokenBalance.asset.symbol,
|
|
290
|
-
ticker: tokenBalance.asset.symbol,
|
|
291
|
-
address: tokenBalance.asset.address || null,
|
|
292
|
-
rawAmount: tokenBalance.amount.amount,
|
|
293
|
-
decimal: tokenBalance.amount.decimals,
|
|
294
|
-
amount: new BigNumber(tokenBalance.amount.amount)
|
|
295
|
-
.shiftedBy(-tokenBalance.amount.decimals)
|
|
296
|
-
.toFixed(),
|
|
297
|
-
logo: '',
|
|
298
|
-
usdPrice: findToken(tokenBalance.asset)?.usdPrice || null,
|
|
299
|
-
})) || []
|
|
300
|
-
);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
277
|
export function resetConnectedWalletState(
|
|
304
278
|
connectedWallet: ConnectedWallet
|
|
305
279
|
): ConnectedWallet {
|
|
306
280
|
return { ...connectedWallet, loading: false, error: true };
|
|
307
281
|
}
|
|
308
282
|
|
|
309
|
-
export const calculateWalletUsdValue = (
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
return acc.findIndex(
|
|
314
|
-
(i) => i.address === current.address && i.chain === current.chain
|
|
315
|
-
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
316
|
-
) === -1
|
|
317
|
-
? [...acc, current]
|
|
318
|
-
: acc;
|
|
319
|
-
},
|
|
320
|
-
[]
|
|
321
|
-
);
|
|
283
|
+
export const calculateWalletUsdValue = (balances: BalanceState) => {
|
|
284
|
+
const total = Object.values(balances).reduce((prev, balance) => {
|
|
285
|
+
return balance.usdValue ? prev.plus(balance.usdValue) : prev;
|
|
286
|
+
}, new BigNumber(ZERO));
|
|
322
287
|
|
|
323
|
-
|
|
324
|
-
const modifiedWalletBlockchain: Blockchain = {
|
|
325
|
-
name: chain.chain,
|
|
326
|
-
accounts: [],
|
|
327
|
-
};
|
|
328
|
-
if (!uniqueAccountAddresses.has(chain.address)) {
|
|
329
|
-
uniqueAccountAddresses.add(chain.address);
|
|
330
|
-
}
|
|
331
|
-
uniqueAccountAddresses.forEach((accountAddress) => {
|
|
332
|
-
if (chain.address === accountAddress) {
|
|
333
|
-
modifiedWalletBlockchain.accounts.push(chain);
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
return modifiedWalletBlockchain;
|
|
337
|
-
});
|
|
338
|
-
const total = numberToString(
|
|
339
|
-
modifiedWalletBlockchains
|
|
340
|
-
?.flatMap((b) => b.accounts)
|
|
341
|
-
?.flatMap((a) => a?.balances)
|
|
342
|
-
?.map((b) =>
|
|
343
|
-
new BigNumber(b?.amount || ZERO).multipliedBy(b?.usdPrice || 0)
|
|
344
|
-
)
|
|
345
|
-
?.reduce((a, b) => a.plus(b), ZERO) || ZERO
|
|
346
|
-
).toString();
|
|
347
|
-
|
|
348
|
-
return numberWithThousandSeparator(total);
|
|
288
|
+
return numberWithThousandSeparator(total.toString());
|
|
349
289
|
};
|
|
350
290
|
|
|
351
291
|
function numberWithThousandSeparator(number: string | number): string {
|
|
@@ -384,19 +324,31 @@ export const getKeplrCompatibleConnectedWallets = (
|
|
|
384
324
|
};
|
|
385
325
|
|
|
386
326
|
export function formatBalance(balance: Balance | null): Balance | null {
|
|
327
|
+
if (!balance) {
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const amount = new BigNumber(balance.amount)
|
|
332
|
+
.shiftedBy(-balance.decimals)
|
|
333
|
+
.toFixed();
|
|
334
|
+
const usdValue = balance.usdValue
|
|
335
|
+
? new BigNumber(balance.usdValue).shiftedBy(-balance.decimals).toFixed()
|
|
336
|
+
: null;
|
|
337
|
+
const formattedAmount = numberToString(
|
|
338
|
+
amount,
|
|
339
|
+
BALANCE_MIN_DECIMALS,
|
|
340
|
+
BALANCE_MAX_DECIMALS
|
|
341
|
+
);
|
|
342
|
+
// null is using for detecing uknown prices
|
|
343
|
+
const formattedUsdValue = usdValue
|
|
344
|
+
? numberToString(usdValue, USD_VALUE_MIN_DECIMALS, USD_VALUE_MAX_DECIMALS)
|
|
345
|
+
: null;
|
|
346
|
+
|
|
387
347
|
const formattedBalance: Balance | null = balance
|
|
388
348
|
? {
|
|
389
349
|
...balance,
|
|
390
|
-
amount:
|
|
391
|
-
|
|
392
|
-
BALANCE_MIN_DECIMALS,
|
|
393
|
-
BALANCE_MAX_DECIMALS
|
|
394
|
-
),
|
|
395
|
-
usdValue: numberToString(
|
|
396
|
-
balance.usdValue,
|
|
397
|
-
USD_VALUE_MIN_DECIMALS,
|
|
398
|
-
USD_VALUE_MAX_DECIMALS
|
|
399
|
-
),
|
|
350
|
+
amount: formattedAmount,
|
|
351
|
+
usdValue: formattedUsdValue,
|
|
400
352
|
}
|
|
401
353
|
: null;
|
|
402
354
|
|
|
@@ -408,17 +360,39 @@ export function compareTokenBalance(
|
|
|
408
360
|
token2Balance: Balance | null
|
|
409
361
|
): number {
|
|
410
362
|
if (token1Balance?.usdValue || token2Balance?.usdValue) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
363
|
+
const token1UsdValue =
|
|
364
|
+
!!token1Balance && !!token1Balance.usdValue
|
|
365
|
+
? new BigNumber(token1Balance.usdValue).shiftedBy(
|
|
366
|
+
-token1Balance.decimals
|
|
367
|
+
)
|
|
368
|
+
: ZERO;
|
|
369
|
+
const token2UsdValue =
|
|
370
|
+
!!token2Balance && !!token2Balance.usdValue
|
|
371
|
+
? new BigNumber(token2Balance.usdValue).shiftedBy(
|
|
372
|
+
-token2Balance.decimals
|
|
373
|
+
)
|
|
374
|
+
: ZERO;
|
|
375
|
+
|
|
376
|
+
if (token1UsdValue.isEqualTo(token2UsdValue)) {
|
|
377
|
+
return 0;
|
|
378
|
+
}
|
|
379
|
+
return token1UsdValue.isGreaterThan(token2UsdValue) ? -1 : 1;
|
|
415
380
|
}
|
|
416
381
|
|
|
417
382
|
if (token1Balance?.amount || token2Balance?.amount) {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
383
|
+
const token1Amount =
|
|
384
|
+
!!token1Balance && !!token1Balance.amount
|
|
385
|
+
? new BigNumber(token1Balance.amount).shiftedBy(-token1Balance.decimals)
|
|
386
|
+
: ZERO;
|
|
387
|
+
const token2Amount =
|
|
388
|
+
!!token2Balance && !!token2Balance.amount
|
|
389
|
+
? new BigNumber(token2Balance.amount).shiftedBy(-token2Balance.decimals)
|
|
390
|
+
: ZERO;
|
|
391
|
+
|
|
392
|
+
if (token1Amount.isEqualTo(token2Amount)) {
|
|
393
|
+
return 0;
|
|
394
|
+
}
|
|
395
|
+
return token1Amount.isGreaterThan(token2Amount) ? -1 : 1;
|
|
422
396
|
}
|
|
423
397
|
|
|
424
398
|
return 0;
|
|
@@ -436,8 +410,8 @@ export function areTokensEqual(
|
|
|
436
410
|
}
|
|
437
411
|
|
|
438
412
|
export function sortWalletsBasedOnConnectionState(
|
|
439
|
-
wallets:
|
|
440
|
-
):
|
|
413
|
+
wallets: ExtendedModalWalletInfo[]
|
|
414
|
+
): ExtendedModalWalletInfo[] {
|
|
441
415
|
return wallets.sort(
|
|
442
416
|
(a, b) =>
|
|
443
417
|
Number(b.state === WalletStatus.CONNECTED) -
|
|
@@ -484,43 +458,6 @@ export function getAddress({
|
|
|
484
458
|
)?.address;
|
|
485
459
|
}
|
|
486
460
|
|
|
487
|
-
export function makeTokensBalance(connectedWallets: ConnectedWallet[]) {
|
|
488
|
-
return connectedWallets
|
|
489
|
-
.flatMap((wallet) => wallet.balances)
|
|
490
|
-
.reduce((balances: TokensBalance, balance) => {
|
|
491
|
-
const currentBalance = {
|
|
492
|
-
amount: balance?.amount ?? '',
|
|
493
|
-
decimals: balance?.decimal ?? 0,
|
|
494
|
-
usdValue: balance?.usdPrice
|
|
495
|
-
? new BigNumber(balance?.usdPrice ?? ZERO)
|
|
496
|
-
.multipliedBy(balance?.amount)
|
|
497
|
-
.toString()
|
|
498
|
-
: '',
|
|
499
|
-
};
|
|
500
|
-
|
|
501
|
-
const tokenHash = balance
|
|
502
|
-
? createTokenHash({
|
|
503
|
-
symbol: balance.symbol,
|
|
504
|
-
blockchain: balance.chain,
|
|
505
|
-
address: balance.address,
|
|
506
|
-
})
|
|
507
|
-
: null;
|
|
508
|
-
|
|
509
|
-
const prevBalance = tokenHash ? balances[tokenHash] : null;
|
|
510
|
-
|
|
511
|
-
const shouldUpdateBalance =
|
|
512
|
-
tokenHash &&
|
|
513
|
-
(!prevBalance ||
|
|
514
|
-
(prevBalance && prevBalance.amount < currentBalance.amount));
|
|
515
|
-
|
|
516
|
-
if (shouldUpdateBalance) {
|
|
517
|
-
balances[tokenHash] = currentBalance;
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
return balances;
|
|
521
|
-
}, {});
|
|
522
|
-
}
|
|
523
|
-
|
|
524
461
|
export const isFetchingBalance = (
|
|
525
462
|
connectedWallets: ConnectedWallet[],
|
|
526
463
|
blockchain: string
|
|
@@ -529,12 +466,12 @@ export const isFetchingBalance = (
|
|
|
529
466
|
(wallet) => wallet.chain === blockchain && wallet.loading
|
|
530
467
|
);
|
|
531
468
|
|
|
532
|
-
export function hashWalletsState(walletsInfo:
|
|
469
|
+
export function hashWalletsState(walletsInfo: WalletInfoWithExtra[]) {
|
|
533
470
|
return walletsInfo.map((w) => w.state).join('-');
|
|
534
471
|
}
|
|
535
472
|
|
|
536
473
|
export function filterBlockchainsByWalletTypes(
|
|
537
|
-
wallets:
|
|
474
|
+
wallets: WalletInfoWithExtra[],
|
|
538
475
|
blockchains: BlockchainMeta[]
|
|
539
476
|
) {
|
|
540
477
|
const uniqueBlockchainTypes = new Set<TransactionType>();
|
|
@@ -551,7 +488,7 @@ export function filterBlockchainsByWalletTypes(
|
|
|
551
488
|
}
|
|
552
489
|
|
|
553
490
|
export function filterWalletsByCategory(
|
|
554
|
-
wallets:
|
|
491
|
+
wallets: ExtendedModalWalletInfo[],
|
|
555
492
|
category: string
|
|
556
493
|
) {
|
|
557
494
|
if (category === BlockchainCategories.ALL) {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/useObserveBalanceChanges/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useObserveBalanceChanges.d.ts","sourceRoot":"","sources":["../../../src/hooks/useObserveBalanceChanges/useObserveBalanceChanges.ts"],"names":[],"mappings":"AAUA,wBAAgB,wBAAwB,CAAC,kBAAkB,CAAC,EAAE,MAAM;;EAyDnE"}
|
package/dist/store/wallets.d.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type { FindToken } from './slices/data';
|
|
2
|
-
import type { Balance, TokensBalance, Wallet } from '../types';
|
|
3
|
-
import type { WalletType } from '@rango-dev/wallets-shared';
|
|
4
|
-
import type { Token } from 'rango-sdk';
|
|
5
|
-
export type TokenBalance = {
|
|
6
|
-
chain: string;
|
|
7
|
-
symbol: string;
|
|
8
|
-
ticker: string;
|
|
9
|
-
address: string | null;
|
|
10
|
-
rawAmount: string;
|
|
11
|
-
decimal: number | null;
|
|
12
|
-
amount: string;
|
|
13
|
-
logo: string | null;
|
|
14
|
-
usdPrice: number | null;
|
|
15
|
-
};
|
|
16
|
-
export interface ConnectedWallet extends Wallet {
|
|
17
|
-
balances: TokenBalance[] | null;
|
|
18
|
-
explorerUrl: string | null;
|
|
19
|
-
selected: boolean;
|
|
20
|
-
loading: boolean;
|
|
21
|
-
error: boolean;
|
|
22
|
-
}
|
|
23
|
-
interface WalletsStore {
|
|
24
|
-
connectedWallets: ConnectedWallet[];
|
|
25
|
-
balances: TokensBalance;
|
|
26
|
-
loading: boolean;
|
|
27
|
-
connectWallet: (accounts: Wallet[], findToken: FindToken) => void;
|
|
28
|
-
disconnectWallet: (walletType: WalletType) => void;
|
|
29
|
-
selectWallets: (wallets: {
|
|
30
|
-
walletType: string;
|
|
31
|
-
chain: string;
|
|
32
|
-
}[]) => void;
|
|
33
|
-
clearConnectedWallet: () => void;
|
|
34
|
-
getWalletsDetails: (accounts: Wallet[], findToken: FindToken, shouldRetry?: boolean) => void;
|
|
35
|
-
getBalanceFor: (token: Token) => Balance | null;
|
|
36
|
-
}
|
|
37
|
-
export declare const useWalletsStore: {
|
|
38
|
-
(): WalletsStore;
|
|
39
|
-
<U>(selector: (state: WalletsStore) => U): U;
|
|
40
|
-
<U_1>(selector: (state: WalletsStore) => U_1, equalityFn: (a: U_1, b: U_1) => boolean): U_1;
|
|
41
|
-
} & Omit<import("zustand").StoreApi<WalletsStore>, "subscribe"> & {
|
|
42
|
-
subscribe: {
|
|
43
|
-
(listener: (selectedState: WalletsStore, previousSelectedState: WalletsStore) => void): () => void;
|
|
44
|
-
<U_2>(selector: (state: WalletsStore) => U_2, listener: (selectedState: U_2, previousSelectedState: U_2) => void, options?: {
|
|
45
|
-
equalityFn?: ((a: U_2, b: U_2) => boolean) | undefined;
|
|
46
|
-
fireImmediately?: boolean | undefined;
|
|
47
|
-
} | undefined): () => void;
|
|
48
|
-
};
|
|
49
|
-
} & {
|
|
50
|
-
use: {
|
|
51
|
-
connectedWallets: () => ConnectedWallet[];
|
|
52
|
-
balances: () => TokensBalance;
|
|
53
|
-
loading: () => boolean;
|
|
54
|
-
connectWallet: () => (accounts: Wallet[], findToken: FindToken) => void;
|
|
55
|
-
disconnectWallet: () => (walletType: WalletType) => void;
|
|
56
|
-
selectWallets: () => (wallets: {
|
|
57
|
-
walletType: string;
|
|
58
|
-
chain: string;
|
|
59
|
-
}[]) => void;
|
|
60
|
-
clearConnectedWallet: () => () => void;
|
|
61
|
-
getWalletsDetails: () => (accounts: Wallet[], findToken: FindToken, shouldRetry?: boolean) => void;
|
|
62
|
-
getBalanceFor: () => (token: Token) => Balance | null;
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
export {};
|
|
66
|
-
//# sourceMappingURL=wallets.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wallets.d.ts","sourceRoot":"","sources":["../../src/store/wallets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAkBvC,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AAEF,MAAM,WAAW,eAAgB,SAAQ,MAAM;IAC7C,QAAQ,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;CAChB;AACD,UAAU,YAAY;IACpB,gBAAgB,EAAE,eAAe,EAAE,CAAC;IACpC,QAAQ,EAAE,aAAa,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;IAClE,gBAAgB,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;IACnD,aAAa,EAAE,CAAC,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,KAAK,IAAI,CAAC;IAC1E,oBAAoB,EAAE,MAAM,IAAI,CAAC;IACjC,iBAAiB,EAAE,CACjB,QAAQ,EAAE,MAAM,EAAE,EAClB,SAAS,EAAE,SAAS,EACpB,WAAW,CAAC,EAAE,OAAO,KAClB,IAAI,CAAC;IACV,aAAa,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,GAAG,IAAI,CAAC;CACjD;AAED,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;wCAZA,MAAM,EAAE,aAAa,SAAS,KAAK,IAAI;6CAClC,UAAU,KAAK,IAAI;uCACzB;YAAE,UAAU,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,EAAE,KAAK,IAAI;0CAC7C,IAAI;4CAEpB,MAAM,EAAE,aACP,SAAS,gBACN,OAAO,KAClB,IAAI;qCACc,KAAK,KAAK,OAAO,GAAG,IAAI;;CAsNhD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useObserveBalanceChanges } from './useObserveBalanceChanges';
|