@rango-dev/widget-embedded 0.29.1-next.20 → 0.29.1-next.22
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/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +6 -0
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
- package/dist/components/Quote/Quote.d.ts.map +1 -1
- package/dist/components/SearchInput/SearchInput.types.d.ts +2 -0
- package/dist/components/SearchInput/SearchInput.types.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.helpers.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.d.ts +4 -0
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.d.ts.map +1 -0
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.styles.d.ts +325 -0
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.styles.d.ts.map +1 -0
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.types.d.ts +10 -0
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.types.d.ts.map +1 -0
- package/dist/components/WalletDerivationPathModal/index.d.ts +2 -0
- package/dist/components/WalletDerivationPathModal/index.d.ts.map +1 -0
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.d.ts.map +1 -1
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.types.d.ts +1 -1
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.types.d.ts.map +1 -1
- package/dist/constants/namespaces.d.ts +8 -0
- package/dist/constants/namespaces.d.ts.map +1 -0
- package/dist/hooks/useWalletList.d.ts +3 -3
- package/dist/hooks/useWalletList.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/types/wallets.d.ts +2 -1
- package/dist/types/wallets.d.ts.map +1 -1
- package/dist/utils/common.d.ts +2 -2
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +4 -4
- package/dist/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +6 -6
- package/src/components/ConfirmWalletsModal/WalletList.tsx +81 -14
- package/src/components/Quote/Quote.tsx +6 -9
- package/src/components/SearchInput/SearchInput.types.ts +2 -0
- package/src/components/SwapDetails/SwapDetails.helpers.tsx +8 -10
- package/src/components/SwapDetails/SwapDetails.tsx +1 -1
- package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +77 -11
- package/src/components/WalletDerivationPathModal/WalletDerivationPathModal.styles.ts +17 -0
- package/src/components/WalletDerivationPathModal/WalletDerivationPathModal.tsx +154 -0
- package/src/components/WalletDerivationPathModal/WalletDerivationPathModal.types.tsx +10 -0
- package/src/components/WalletDerivationPathModal/index.ts +1 -0
- package/src/components/WalletNamespacesModal/WalletNamespacesModal.tsx +9 -6
- package/src/components/WalletNamespacesModal/WalletNamespacesModal.types.tsx +1 -1
- package/src/constants/namespaces.ts +62 -0
- package/src/hooks/useWalletList.ts +5 -2
- package/src/index.ts +2 -2
- package/src/pages/WalletsPage.tsx +85 -19
- package/src/types/wallets.ts +2 -1
- package/src/utils/common.ts +2 -2
- package/src/utils/wallets.ts +7 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/widget-embedded",
|
|
3
|
-
"version": "0.29.1-next.
|
|
3
|
+
"version": "0.29.1-next.22",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"@lingui/core": "4.2.1",
|
|
26
26
|
"@lingui/react": "4.2.1",
|
|
27
27
|
"@rango-dev/logging-core": "^0.4.0",
|
|
28
|
-
"@rango-dev/provider-all": "^0.34.1-next.
|
|
28
|
+
"@rango-dev/provider-all": "^0.34.1-next.8",
|
|
29
29
|
"@rango-dev/queue-manager-core": "^0.26.0",
|
|
30
|
-
"@rango-dev/queue-manager-rango-preset": "^0.34.1-next.
|
|
30
|
+
"@rango-dev/queue-manager-rango-preset": "^0.34.1-next.8",
|
|
31
31
|
"@rango-dev/queue-manager-react": "^0.26.0",
|
|
32
32
|
"@rango-dev/signer-solana": "^0.29.1-next.1",
|
|
33
|
-
"@rango-dev/ui": "^0.35.1-next.
|
|
34
|
-
"@rango-dev/wallets-react": "^0.20.1-next.
|
|
35
|
-
"@rango-dev/wallets-shared": "^0.34.1-next.
|
|
33
|
+
"@rango-dev/ui": "^0.35.1-next.12",
|
|
34
|
+
"@rango-dev/wallets-react": "^0.20.1-next.6",
|
|
35
|
+
"@rango-dev/wallets-shared": "^0.34.1-next.6",
|
|
36
36
|
"bignumber.js": "^9.1.1",
|
|
37
37
|
"copy-to-clipboard": "^3.3.3",
|
|
38
38
|
"dayjs": "^1.11.7",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PropTypes } from './WalletList.type';
|
|
2
|
-
import type { Wallet,
|
|
2
|
+
import type { Wallet, WalletInfoWithExtra } from '../../types';
|
|
3
3
|
import type { Namespace, WalletType } from '@rango-dev/wallets-shared';
|
|
4
4
|
|
|
5
5
|
import { i18n } from '@lingui/core';
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
isExperimentalChain,
|
|
32
32
|
} from '../../utils/wallets';
|
|
33
33
|
import { WatermarkedModal } from '../common/WatermarkedModal';
|
|
34
|
+
import { WalletDerivationPathModal } from '../WalletDerivationPathModal';
|
|
34
35
|
import { WalletModal } from '../WalletModal';
|
|
35
36
|
import { WalletNamespacesModal } from '../WalletNamespacesModal';
|
|
36
37
|
|
|
@@ -42,12 +43,20 @@ import {
|
|
|
42
43
|
} from './WalletList.styles';
|
|
43
44
|
|
|
44
45
|
interface WalletNamespacesModalState {
|
|
46
|
+
open: boolean;
|
|
45
47
|
providerType: string;
|
|
46
48
|
providerImage: string;
|
|
47
49
|
availableNamespaces?: Namespace[];
|
|
48
50
|
singleNamespace?: boolean;
|
|
49
51
|
}
|
|
50
52
|
|
|
53
|
+
interface DerivationPathModalState {
|
|
54
|
+
open: boolean;
|
|
55
|
+
providerType: string;
|
|
56
|
+
providerImage: string;
|
|
57
|
+
namespace: Namespace;
|
|
58
|
+
}
|
|
59
|
+
|
|
51
60
|
const ACCOUNT_ADDRESS_MAX_CHARACTERS = 7;
|
|
52
61
|
export function WalletList(props: PropTypes) {
|
|
53
62
|
const { chain, isSelected, selectWallet, limit, onShowMore, onConnect } =
|
|
@@ -66,6 +75,8 @@ export function WalletList(props: PropTypes) {
|
|
|
66
75
|
useState<'in-progress' | 'completed' | 'rejected' | null>(null);
|
|
67
76
|
const [namespacesModalState, setNamespacesModalState] =
|
|
68
77
|
useState<WalletNamespacesModalState | null>(null);
|
|
78
|
+
const [derivationPathModalState, setDerivationPathModalState] =
|
|
79
|
+
useState<DerivationPathModalState | null>(null);
|
|
69
80
|
const { suggestAndConnect } = useWallets();
|
|
70
81
|
let modalTimerId: ReturnType<typeof setTimeout> | null = null;
|
|
71
82
|
const {
|
|
@@ -91,8 +102,7 @@ export function WalletList(props: PropTypes) {
|
|
|
91
102
|
}, TIME_TO_CLOSE_MODAL);
|
|
92
103
|
},
|
|
93
104
|
});
|
|
94
|
-
const [sortedList, setSortedList] =
|
|
95
|
-
useState<WalletInfoWithNamespaces[]>(list);
|
|
105
|
+
const [sortedList, setSortedList] = useState<WalletInfoWithExtra[]>(list);
|
|
96
106
|
const numberOfSupportedWallets = list.length;
|
|
97
107
|
const shouldShowMoreWallets = limit && numberOfSupportedWallets - limit > 0;
|
|
98
108
|
|
|
@@ -107,8 +117,27 @@ export function WalletList(props: PropTypes) {
|
|
|
107
117
|
}
|
|
108
118
|
};
|
|
109
119
|
|
|
110
|
-
const
|
|
120
|
+
const handleCloseNamespaceModal = () => {
|
|
121
|
+
if (namespacesModalState) {
|
|
122
|
+
setNamespacesModalState({
|
|
123
|
+
...namespacesModalState,
|
|
124
|
+
open: false,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const handleCloseDerivationPathModal = () => {
|
|
130
|
+
if (derivationPathModalState) {
|
|
131
|
+
setDerivationPathModalState({
|
|
132
|
+
...derivationPathModalState,
|
|
133
|
+
open: false,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const handleOpenNamespacesModal = (wallet: WalletInfoWithExtra) => {
|
|
111
139
|
setNamespacesModalState({
|
|
140
|
+
open: true,
|
|
112
141
|
providerType: wallet.type,
|
|
113
142
|
providerImage: wallet.image,
|
|
114
143
|
availableNamespaces: wallet.namespaces,
|
|
@@ -116,6 +145,42 @@ export function WalletList(props: PropTypes) {
|
|
|
116
145
|
});
|
|
117
146
|
};
|
|
118
147
|
|
|
148
|
+
const handleConfirmNamespaces = (selectedNamespaces: Namespace[]) => {
|
|
149
|
+
const wallet = sortedList.find(
|
|
150
|
+
(wallet) => wallet.type === namespacesModalState?.providerType
|
|
151
|
+
);
|
|
152
|
+
if (
|
|
153
|
+
wallet?.singleNamespace && // Currently we support derivation path only for single namespace wallets
|
|
154
|
+
wallet?.needsDerivationPath &&
|
|
155
|
+
selectedNamespaces[0]
|
|
156
|
+
) {
|
|
157
|
+
setDerivationPathModalState({
|
|
158
|
+
open: true,
|
|
159
|
+
providerType: wallet.type,
|
|
160
|
+
providerImage: wallet.image,
|
|
161
|
+
namespace: selectedNamespaces[0],
|
|
162
|
+
});
|
|
163
|
+
} else {
|
|
164
|
+
void handleClick(
|
|
165
|
+
namespacesModalState?.providerType as string,
|
|
166
|
+
selectedNamespaces.map((namespace) => ({
|
|
167
|
+
namespace,
|
|
168
|
+
}))
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
handleCloseNamespaceModal();
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const handleDerivationPathConfirm = (derivationPath: string) => {
|
|
175
|
+
if (derivationPath && derivationPathModalState?.namespace) {
|
|
176
|
+
void handleClick(derivationPathModalState.providerType, [
|
|
177
|
+
{ namespace: derivationPathModalState.namespace, derivationPath },
|
|
178
|
+
]);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
handleCloseDerivationPathModal();
|
|
182
|
+
};
|
|
183
|
+
|
|
119
184
|
useEffect(() => {
|
|
120
185
|
setSortedList((sortedList) => {
|
|
121
186
|
const selectedWalletIndex = list.findIndex((wallet) =>
|
|
@@ -238,19 +303,21 @@ export function WalletList(props: PropTypes) {
|
|
|
238
303
|
error={error}
|
|
239
304
|
/>
|
|
240
305
|
<WalletNamespacesModal
|
|
241
|
-
open={!!namespacesModalState}
|
|
242
|
-
onClose={
|
|
243
|
-
onConfirm={
|
|
244
|
-
void handleClick(
|
|
245
|
-
namespacesModalState?.providerType as string,
|
|
246
|
-
namespaces
|
|
247
|
-
);
|
|
248
|
-
setNamespacesModalState(null);
|
|
249
|
-
}}
|
|
306
|
+
open={!!namespacesModalState?.open}
|
|
307
|
+
onClose={handleCloseNamespaceModal}
|
|
308
|
+
onConfirm={handleConfirmNamespaces}
|
|
250
309
|
image={namespacesModalState?.providerImage}
|
|
251
|
-
|
|
310
|
+
availableNamespaces={namespacesModalState?.availableNamespaces}
|
|
252
311
|
singleNamespace={namespacesModalState?.singleNamespace}
|
|
253
312
|
/>
|
|
313
|
+
<WalletDerivationPathModal
|
|
314
|
+
open={!!derivationPathModalState?.open}
|
|
315
|
+
selectedNamespace={derivationPathModalState?.namespace}
|
|
316
|
+
type={derivationPathModalState?.providerType}
|
|
317
|
+
image={derivationPathModalState?.providerImage}
|
|
318
|
+
onClose={handleCloseDerivationPathModal}
|
|
319
|
+
onConfirm={handleDerivationPathConfirm}
|
|
320
|
+
/>
|
|
254
321
|
{!!experimentalChainWallet && (
|
|
255
322
|
<WatermarkedModal
|
|
256
323
|
open={!!experimentalChainWallet && showExperimentalChainModal}
|
|
@@ -155,16 +155,15 @@ export function Quote(props: QuoteProps) {
|
|
|
155
155
|
|
|
156
156
|
return {
|
|
157
157
|
swapper: {
|
|
158
|
-
displayName: getSwapperDisplayName(swap.swapperId, swappers),
|
|
158
|
+
displayName: getSwapperDisplayName(swap.swapperId, swappers) ?? '',
|
|
159
159
|
image: swap.swapperLogo,
|
|
160
160
|
},
|
|
161
161
|
from: {
|
|
162
162
|
token: { displayName: swap.from.symbol, image: swap.from.logo },
|
|
163
163
|
chain: {
|
|
164
|
-
displayName:
|
|
165
|
-
swap.from.blockchain,
|
|
166
|
-
|
|
167
|
-
),
|
|
164
|
+
displayName:
|
|
165
|
+
getBlockchainShortNameFor(swap.from.blockchain, blockchains) ??
|
|
166
|
+
'',
|
|
168
167
|
image: swap.from.blockchainLogo,
|
|
169
168
|
},
|
|
170
169
|
price: {
|
|
@@ -194,10 +193,8 @@ export function Quote(props: QuoteProps) {
|
|
|
194
193
|
to: {
|
|
195
194
|
token: { displayName: swap.to.symbol, image: swap.to.logo },
|
|
196
195
|
chain: {
|
|
197
|
-
displayName:
|
|
198
|
-
swap.to.blockchain,
|
|
199
|
-
blockchains
|
|
200
|
-
),
|
|
196
|
+
displayName:
|
|
197
|
+
getBlockchainShortNameFor(swap.to.blockchain, blockchains) || '',
|
|
201
198
|
image: swap.to.blockchainLogo,
|
|
202
199
|
},
|
|
203
200
|
price: {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type * as Stitches from '@stitches/react';
|
|
1
2
|
import type React from 'react';
|
|
2
3
|
|
|
3
4
|
export type PropTypes = {
|
|
@@ -7,4 +8,5 @@ export type PropTypes = {
|
|
|
7
8
|
size?: 'small' | 'large';
|
|
8
9
|
value: string;
|
|
9
10
|
setValue?: (value: string) => void;
|
|
11
|
+
style?: Stitches.CSS;
|
|
10
12
|
} & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size' | 'value'>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { GetStep } from '../SwapDetailsAlerts';
|
|
2
2
|
import type { Step, StepDetailsProps } from '@rango-dev/ui';
|
|
3
|
-
import type { PendingSwapStep } from 'rango-types';
|
|
3
|
+
import type { PendingSwapStep, SwapperType } from 'rango-types';
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
@@ -46,7 +46,7 @@ export const getSteps = ({
|
|
|
46
46
|
TOKEN_AMOUNT_MIN_DECIMALS,
|
|
47
47
|
TOKEN_AMOUNT_MAX_DECIMALS
|
|
48
48
|
),
|
|
49
|
-
realValue: amountToConvert,
|
|
49
|
+
realValue: amountToConvert ?? '',
|
|
50
50
|
},
|
|
51
51
|
},
|
|
52
52
|
to: {
|
|
@@ -63,13 +63,13 @@ export const getSteps = ({
|
|
|
63
63
|
TOKEN_AMOUNT_MAX_DECIMALS
|
|
64
64
|
),
|
|
65
65
|
realValue:
|
|
66
|
-
step.outputAmount || step.expectedOutputAmountHumanReadable,
|
|
66
|
+
step.outputAmount || step.expectedOutputAmountHumanReadable || '',
|
|
67
67
|
},
|
|
68
68
|
},
|
|
69
69
|
swapper: {
|
|
70
|
-
displayName: getSwapperDisplayName(step.swapperId, swappers),
|
|
70
|
+
displayName: getSwapperDisplayName(step.swapperId, swappers) ?? '',
|
|
71
71
|
image: step.swapperLogo ?? '',
|
|
72
|
-
type: step.swapperType,
|
|
72
|
+
type: step.swapperType as SwapperType,
|
|
73
73
|
},
|
|
74
74
|
internalSwaps: step.internalSwaps
|
|
75
75
|
? step.internalSwaps.map((internalSwap) => {
|
|
@@ -95,12 +95,10 @@ export const getSteps = ({
|
|
|
95
95
|
},
|
|
96
96
|
},
|
|
97
97
|
swapper: {
|
|
98
|
-
displayName:
|
|
99
|
-
internalSwap.swapperId,
|
|
100
|
-
swappers
|
|
101
|
-
),
|
|
98
|
+
displayName:
|
|
99
|
+
getSwapperDisplayName(internalSwap.swapperId, swappers) ?? '',
|
|
102
100
|
image: internalSwap.swapperLogo ?? '',
|
|
103
|
-
type: internalSwap.swapperType,
|
|
101
|
+
type: internalSwap.swapperType as SwapperType,
|
|
104
102
|
},
|
|
105
103
|
};
|
|
106
104
|
})
|
|
@@ -385,7 +385,7 @@ export function SwapDetails(props: SwapDetailsProps) {
|
|
|
385
385
|
),
|
|
386
386
|
usdValue: outputUsdValue,
|
|
387
387
|
realUsdValue: realOutputUsdValue,
|
|
388
|
-
realValue: outputAmount,
|
|
388
|
+
realValue: outputAmount || '',
|
|
389
389
|
},
|
|
390
390
|
token: {
|
|
391
391
|
displayName: steps[numberOfSteps - 1].to.token.displayName,
|
|
@@ -8,17 +8,26 @@ import React, { useState } from 'react';
|
|
|
8
8
|
|
|
9
9
|
import { getContainer } from '../../utils/common';
|
|
10
10
|
import { mapStatusToWalletState } from '../../utils/wallets';
|
|
11
|
+
import { WalletDerivationPathModal } from '../WalletDerivationPathModal';
|
|
11
12
|
import { WalletNamespacesModal } from '../WalletNamespacesModal';
|
|
12
13
|
|
|
13
14
|
import { WalletContainer } from './SwapDetailsModal.styles';
|
|
14
15
|
|
|
15
16
|
interface NamespacesModalState {
|
|
17
|
+
open: boolean;
|
|
16
18
|
providerType: string;
|
|
17
19
|
providerImage: string;
|
|
18
20
|
availableNamespaces?: Namespace[];
|
|
19
21
|
singleNamespace?: boolean;
|
|
20
22
|
}
|
|
21
23
|
|
|
24
|
+
interface DerivationPathModalState {
|
|
25
|
+
open: boolean;
|
|
26
|
+
providerType: string;
|
|
27
|
+
providerImage: string;
|
|
28
|
+
namespace: Namespace;
|
|
29
|
+
}
|
|
30
|
+
|
|
22
31
|
export const WalletStateContent = (props: WalletStateContentProps) => {
|
|
23
32
|
const {
|
|
24
33
|
type,
|
|
@@ -31,6 +40,8 @@ export const WalletStateContent = (props: WalletStateContentProps) => {
|
|
|
31
40
|
const { connect, getWalletInfo, state } = useWallets();
|
|
32
41
|
const [namespacesModalState, setNamespacesModalState] =
|
|
33
42
|
useState<NamespacesModalState | null>(null);
|
|
43
|
+
const [derivationPathModalState, setDerivationPathModalState] =
|
|
44
|
+
useState<DerivationPathModalState | null>(null);
|
|
34
45
|
const walletType = currentStepWallet?.walletType;
|
|
35
46
|
const walletState = walletType
|
|
36
47
|
? mapStatusToWalletState(state(walletType))
|
|
@@ -39,6 +50,59 @@ export const WalletStateContent = (props: WalletStateContentProps) => {
|
|
|
39
50
|
const shouldShowWallet =
|
|
40
51
|
showWalletButton && !!walletType && !!walletState && !!walletInfo;
|
|
41
52
|
|
|
53
|
+
const handleCloseNamespaceModal = () => {
|
|
54
|
+
if (namespacesModalState) {
|
|
55
|
+
setNamespacesModalState({
|
|
56
|
+
...namespacesModalState,
|
|
57
|
+
open: false,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const handleCloseDerivationPathModal = () => {
|
|
63
|
+
if (derivationPathModalState) {
|
|
64
|
+
setDerivationPathModalState({
|
|
65
|
+
...derivationPathModalState,
|
|
66
|
+
open: false,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const handleConfirmNamespaces = (selectedNamespaces: Namespace[]) => {
|
|
72
|
+
if (
|
|
73
|
+
!!walletInfo?.needsDerivationPath &&
|
|
74
|
+
walletInfo?.singleNamespace &&
|
|
75
|
+
selectedNamespaces[0] &&
|
|
76
|
+
walletType
|
|
77
|
+
) {
|
|
78
|
+
setDerivationPathModalState({
|
|
79
|
+
open: true,
|
|
80
|
+
providerType: walletType,
|
|
81
|
+
providerImage: walletInfo.img,
|
|
82
|
+
namespace: selectedNamespaces[0],
|
|
83
|
+
});
|
|
84
|
+
} else {
|
|
85
|
+
connect(
|
|
86
|
+
namespacesModalState?.providerType as string,
|
|
87
|
+
undefined,
|
|
88
|
+
selectedNamespaces.map((namespace) => ({
|
|
89
|
+
namespace,
|
|
90
|
+
}))
|
|
91
|
+
).catch((error) => debug(error));
|
|
92
|
+
}
|
|
93
|
+
handleCloseNamespaceModal();
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const handleDerivationPathConfirm = (derivationPath: string) => {
|
|
97
|
+
if (derivationPath && derivationPathModalState?.namespace) {
|
|
98
|
+
connect(derivationPathModalState?.providerType, undefined, [
|
|
99
|
+
{ namespace: derivationPathModalState.namespace, derivationPath },
|
|
100
|
+
]).catch((error) => debug(error));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
handleCloseDerivationPathModal();
|
|
104
|
+
};
|
|
105
|
+
|
|
42
106
|
return (
|
|
43
107
|
<>
|
|
44
108
|
<MessageBox type={type} title={title} description={message} />
|
|
@@ -56,6 +120,7 @@ export const WalletStateContent = (props: WalletStateContentProps) => {
|
|
|
56
120
|
onClick={async () => {
|
|
57
121
|
if (walletInfo.namespaces) {
|
|
58
122
|
setNamespacesModalState({
|
|
123
|
+
open: true,
|
|
59
124
|
providerType: walletType,
|
|
60
125
|
providerImage: walletInfo.img,
|
|
61
126
|
availableNamespaces: walletInfo.namespaces,
|
|
@@ -69,20 +134,21 @@ export const WalletStateContent = (props: WalletStateContentProps) => {
|
|
|
69
134
|
</WalletContainer>
|
|
70
135
|
)}
|
|
71
136
|
<WalletNamespacesModal
|
|
72
|
-
open={!!namespacesModalState}
|
|
73
|
-
onClose={
|
|
74
|
-
onConfirm={
|
|
75
|
-
connect(
|
|
76
|
-
namespacesModalState?.providerType as string,
|
|
77
|
-
undefined,
|
|
78
|
-
namespaces
|
|
79
|
-
).catch((error) => debug(error));
|
|
80
|
-
setNamespacesModalState(null);
|
|
81
|
-
}}
|
|
137
|
+
open={!!namespacesModalState?.open}
|
|
138
|
+
onClose={handleCloseNamespaceModal}
|
|
139
|
+
onConfirm={handleConfirmNamespaces}
|
|
82
140
|
image={namespacesModalState?.providerImage}
|
|
83
|
-
|
|
141
|
+
availableNamespaces={namespacesModalState?.availableNamespaces}
|
|
84
142
|
singleNamespace={namespacesModalState?.singleNamespace}
|
|
85
143
|
/>
|
|
144
|
+
<WalletDerivationPathModal
|
|
145
|
+
open={!!derivationPathModalState?.open}
|
|
146
|
+
selectedNamespace={derivationPathModalState?.namespace}
|
|
147
|
+
type={derivationPathModalState?.providerType}
|
|
148
|
+
image={derivationPathModalState?.providerImage}
|
|
149
|
+
onClose={handleCloseDerivationPathModal}
|
|
150
|
+
onConfirm={handleDerivationPathConfirm}
|
|
151
|
+
/>
|
|
86
152
|
</>
|
|
87
153
|
);
|
|
88
154
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { styled, Typography } from '@rango-dev/ui';
|
|
2
|
+
|
|
3
|
+
export const InputsContainer = styled('div', {
|
|
4
|
+
paddingTop: '$30',
|
|
5
|
+
paddingBottom: '$30',
|
|
6
|
+
zIndex: 10, // This property is added to solve inconsistency between Select child of this component and subsequent button
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export const InputLabel = styled(Typography, {
|
|
10
|
+
paddingLeft: '$10',
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export const derivationPathInputStyles = {
|
|
14
|
+
height: '$40',
|
|
15
|
+
backgroundColor: '$neutral200',
|
|
16
|
+
borderRadius: '$sm',
|
|
17
|
+
};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { PropTypes } from './WalletDerivationPathModal.types';
|
|
2
|
+
import type { DerivationPath, Namespace } from '@rango-dev/wallets-shared';
|
|
3
|
+
|
|
4
|
+
import { i18n } from '@lingui/core';
|
|
5
|
+
import {
|
|
6
|
+
Button,
|
|
7
|
+
Divider,
|
|
8
|
+
Image,
|
|
9
|
+
MessageBox,
|
|
10
|
+
Select,
|
|
11
|
+
TextField,
|
|
12
|
+
} from '@rango-dev/ui';
|
|
13
|
+
import React, { useEffect, useState } from 'react';
|
|
14
|
+
|
|
15
|
+
import { WIDGET_UI_ID } from '../../constants';
|
|
16
|
+
import { namespaces } from '../../constants/namespaces';
|
|
17
|
+
import { WatermarkedModal } from '../common/WatermarkedModal';
|
|
18
|
+
import {
|
|
19
|
+
LogoContainer,
|
|
20
|
+
Spinner,
|
|
21
|
+
WalletImageContainer,
|
|
22
|
+
} from '../WalletModal/WalletModalContent.styles';
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
derivationPathInputStyles,
|
|
26
|
+
InputLabel,
|
|
27
|
+
InputsContainer,
|
|
28
|
+
} from './WalletDerivationPathModal.styles';
|
|
29
|
+
|
|
30
|
+
const customDerivationPath: DerivationPath = {
|
|
31
|
+
id: 'custom',
|
|
32
|
+
label: 'Custom',
|
|
33
|
+
generateDerivationPath: (index: string) => index,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function getDerivationPaths(selectedNamespace?: Namespace) {
|
|
37
|
+
const selectedNamespaceDerivationPaths = selectedNamespace
|
|
38
|
+
? namespaces[selectedNamespace].derivationPaths
|
|
39
|
+
: null;
|
|
40
|
+
|
|
41
|
+
const derivationPaths: DerivationPath[] = !!selectedNamespaceDerivationPaths
|
|
42
|
+
? [...selectedNamespaceDerivationPaths, customDerivationPath]
|
|
43
|
+
: [];
|
|
44
|
+
|
|
45
|
+
return derivationPaths;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function WalletDerivationPathModal(props: PropTypes) {
|
|
49
|
+
const { onClose, onConfirm, selectedNamespace, image, type, open } = props;
|
|
50
|
+
|
|
51
|
+
const [selectedDerivationPathId, setSelectedDerivationPathId] = useState<
|
|
52
|
+
string | null
|
|
53
|
+
>(null);
|
|
54
|
+
const [derivationPathIndex, setDerivationPathIndex] = useState('0');
|
|
55
|
+
|
|
56
|
+
const isCustomOptionSelected =
|
|
57
|
+
selectedDerivationPathId === customDerivationPath.id;
|
|
58
|
+
|
|
59
|
+
const derivationPaths = getDerivationPaths(selectedNamespace);
|
|
60
|
+
|
|
61
|
+
const handleDerivationPathItemClick = ({ value }: { value: string }) => {
|
|
62
|
+
const selectedDerivationPath = derivationPaths?.find(
|
|
63
|
+
(derivationPath) => derivationPath.id === value
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
if (selectedDerivationPath) {
|
|
67
|
+
setSelectedDerivationPathId(selectedDerivationPath.id);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const handleConfirm = () => {
|
|
72
|
+
const selectedDerivationPath = derivationPaths.find(
|
|
73
|
+
(derivationPath) => derivationPath.id === selectedDerivationPathId
|
|
74
|
+
);
|
|
75
|
+
if (selectedDerivationPath) {
|
|
76
|
+
onConfirm(
|
|
77
|
+
selectedDerivationPath.generateDerivationPath(derivationPathIndex)
|
|
78
|
+
);
|
|
79
|
+
} else {
|
|
80
|
+
// Unreachable code
|
|
81
|
+
throw new Error('selectedDerivationPath can not be undefined');
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
setSelectedDerivationPathId(
|
|
87
|
+
getDerivationPaths(selectedNamespace)[0]?.id || null
|
|
88
|
+
);
|
|
89
|
+
}, [selectedNamespace]);
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<WatermarkedModal
|
|
93
|
+
open={open}
|
|
94
|
+
onClose={onClose}
|
|
95
|
+
container={
|
|
96
|
+
document.getElementById(WIDGET_UI_ID.SWAP_BOX_ID) || document.body
|
|
97
|
+
}>
|
|
98
|
+
<Divider size={20} />
|
|
99
|
+
<MessageBox
|
|
100
|
+
type="info"
|
|
101
|
+
title={i18n.t('Select Derivation Path')}
|
|
102
|
+
description={i18n.t(
|
|
103
|
+
`In order to connect to ${type}, you must first select a Derivation Path`
|
|
104
|
+
)}
|
|
105
|
+
icon={
|
|
106
|
+
<LogoContainer>
|
|
107
|
+
<WalletImageContainer>
|
|
108
|
+
<Image src={image} size={45} />
|
|
109
|
+
</WalletImageContainer>
|
|
110
|
+
<Spinner />
|
|
111
|
+
</LogoContainer>
|
|
112
|
+
}
|
|
113
|
+
/>
|
|
114
|
+
|
|
115
|
+
<InputsContainer>
|
|
116
|
+
<InputLabel variant="body" size="xsmall" color="$neutral600">
|
|
117
|
+
{i18n.t('Choose Derivation Path Template')}
|
|
118
|
+
</InputLabel>
|
|
119
|
+
<Select
|
|
120
|
+
value={selectedDerivationPathId || ''}
|
|
121
|
+
options={derivationPaths.map((derivationPath) => ({
|
|
122
|
+
value: derivationPath.id,
|
|
123
|
+
label: derivationPath.label,
|
|
124
|
+
}))}
|
|
125
|
+
variant="filled"
|
|
126
|
+
handleItemClick={handleDerivationPathItemClick}
|
|
127
|
+
styles={{ trigger: derivationPathInputStyles }}
|
|
128
|
+
/>
|
|
129
|
+
<Divider size={20} />
|
|
130
|
+
<InputLabel variant="body" size="xsmall" color="$neutral600">
|
|
131
|
+
{isCustomOptionSelected
|
|
132
|
+
? i18n.t('Enter Path')
|
|
133
|
+
: i18n.t('Enter Index')}
|
|
134
|
+
</InputLabel>
|
|
135
|
+
<TextField
|
|
136
|
+
type={isCustomOptionSelected ? 'text' : 'number'}
|
|
137
|
+
variant="contained"
|
|
138
|
+
value={derivationPathIndex}
|
|
139
|
+
onChange={(event) => setDerivationPathIndex(event.target.value)}
|
|
140
|
+
style={derivationPathInputStyles}
|
|
141
|
+
/>
|
|
142
|
+
</InputsContainer>
|
|
143
|
+
|
|
144
|
+
<Button
|
|
145
|
+
type="primary"
|
|
146
|
+
onClick={handleConfirm}
|
|
147
|
+
disabled={
|
|
148
|
+
!derivationPaths || !selectedDerivationPathId || !derivationPathIndex
|
|
149
|
+
}>
|
|
150
|
+
{i18n.t('Confirm')}
|
|
151
|
+
</Button>
|
|
152
|
+
</WatermarkedModal>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { WalletDerivationPathModal } from './WalletDerivationPathModal';
|
|
@@ -6,16 +6,17 @@ import { i18n } from '@lingui/core';
|
|
|
6
6
|
import {
|
|
7
7
|
Button,
|
|
8
8
|
Checkbox,
|
|
9
|
+
Divider,
|
|
9
10
|
Image,
|
|
10
11
|
ListItemButton,
|
|
11
12
|
MessageBox,
|
|
12
13
|
Radio,
|
|
13
14
|
RadioRoot,
|
|
14
15
|
} from '@rango-dev/ui';
|
|
15
|
-
import { namespaceMainBlockchain } from '@rango-dev/wallets-shared';
|
|
16
16
|
import React, { useMemo, useState } from 'react';
|
|
17
17
|
|
|
18
18
|
import { WIDGET_UI_ID } from '../../constants';
|
|
19
|
+
import { namespaces } from '../../constants/namespaces';
|
|
19
20
|
import { useAppStore } from '../../store/AppStore';
|
|
20
21
|
import { WatermarkedModal } from '../common/WatermarkedModal';
|
|
21
22
|
import { WalletImageContainer } from '../HeaderButtons/HeaderButtons.styles';
|
|
@@ -35,7 +36,7 @@ const getBlockchainLogo = (
|
|
|
35
36
|
};
|
|
36
37
|
|
|
37
38
|
export function WalletNamespacesModal(props: PropTypes) {
|
|
38
|
-
const { singleNamespace,
|
|
39
|
+
const { singleNamespace, availableNamespaces } = props;
|
|
39
40
|
|
|
40
41
|
const [selectedNamespaces, setSelectedNamespaces] = useState<Namespace[]>([]);
|
|
41
42
|
|
|
@@ -43,14 +44,15 @@ export function WalletNamespacesModal(props: PropTypes) {
|
|
|
43
44
|
|
|
44
45
|
const namespacesInfo = useMemo(
|
|
45
46
|
() =>
|
|
46
|
-
|
|
47
|
+
availableNamespaces?.map((namespace) => ({
|
|
47
48
|
name: namespace,
|
|
48
49
|
logo: getBlockchainLogo(
|
|
49
50
|
blockchains,
|
|
50
|
-
|
|
51
|
+
namespaces[namespace].mainBlockchain
|
|
51
52
|
),
|
|
53
|
+
title: namespaces[namespace].title,
|
|
52
54
|
})),
|
|
53
|
-
[
|
|
55
|
+
[availableNamespaces]
|
|
54
56
|
);
|
|
55
57
|
|
|
56
58
|
const onSelect = (namespace: Namespace) => {
|
|
@@ -80,6 +82,7 @@ export function WalletNamespacesModal(props: PropTypes) {
|
|
|
80
82
|
container={
|
|
81
83
|
document.getElementById(WIDGET_UI_ID.SWAP_BOX_ID) || document.body
|
|
82
84
|
}>
|
|
85
|
+
<Divider size={20} />
|
|
83
86
|
<MessageBox
|
|
84
87
|
type="info"
|
|
85
88
|
title={i18n.t('Select chain types')}
|
|
@@ -102,7 +105,7 @@ export function WalletNamespacesModal(props: PropTypes) {
|
|
|
102
105
|
<ListItemButton
|
|
103
106
|
key={namespaceInfoItem.name}
|
|
104
107
|
id={namespaceInfoItem.name}
|
|
105
|
-
title={namespaceInfoItem.
|
|
108
|
+
title={namespaceInfoItem.title}
|
|
106
109
|
hasDivider
|
|
107
110
|
style={{ height: 60 }}
|
|
108
111
|
onClick={() => onSelect(namespaceInfoItem.name)}
|