Skip to content

Commit 2b6bd0f

Browse files
committed
feat(wp): hot and cold self managed
Ticket: WP-1338
1 parent 5947393 commit 2b6bd0f

File tree

8 files changed

+262
-80
lines changed

8 files changed

+262
-80
lines changed

src/containers/BuildUnsignedConsolidation/GenericEcdsaForm.tsx

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import {
77
FormikTextarea,
88
FormikTextfield,
99
} from '~/components';
10+
import { useWalletTypeLabels, WalletType } from './useWalletTypeLabels';
11+
import { WalletTypeSelector } from './WalletTypeSelector';
1012

11-
const validationSchema = Yup.object({
12-
userKey: Yup.string(),
13-
backupKey: Yup.string(),
13+
const getValidationSchema = (walletType: WalletType) => Yup.object({
14+
userKey: Yup.string().required(),
15+
backupKey: Yup.string().required(),
1416
bitgoKey: Yup.string().required(),
15-
walletPassphrase: Yup.string(),
17+
walletPassphrase: walletType === 'hot' ? Yup.string().required() : Yup.string(),
1618
startingScanIndex: Yup.number(),
1719
endingScanIndex: Yup.number().moreThan(
1820
Yup.ref('startingScanIndex'),
@@ -21,6 +23,8 @@ const validationSchema = Yup.object({
2123
seed: Yup.string(),
2224
}).required();
2325

26+
const validationSchema = getValidationSchema('cold');
27+
2428
export type EcdsaFormValues = Yup.Asserts<typeof validationSchema>;
2529

2630
export type GenericEcdsaFormValues = {
@@ -31,6 +35,18 @@ export type GenericEcdsaFormValues = {
3135
};
3236

3337
export function GenericEcdsaForm({ onSubmit }: GenericEcdsaFormValues) {
38+
const {
39+
walletType,
40+
handleWalletTypeChange,
41+
userKeyLabel,
42+
userKeyHelperText,
43+
backupKeyLabel,
44+
backupKeyHelperText,
45+
bitgoKeyLabel,
46+
bitgoKeyHelperText,
47+
showWalletPassphrase,
48+
} = useWalletTypeLabels();
49+
3450
const formik = useFormik<EcdsaFormValues>({
3551
onSubmit,
3652
initialValues: {
@@ -42,6 +58,8 @@ export function GenericEcdsaForm({ onSubmit }: GenericEcdsaFormValues) {
4258
endingScanIndex: 21,
4359
seed: undefined,
4460
},
61+
validationSchema: getValidationSchema(walletType),
62+
enableReinitialize: true,
4563
});
4664

4765
return (
@@ -50,10 +68,11 @@ export function GenericEcdsaForm({ onSubmit }: GenericEcdsaFormValues) {
5068
<h4 className="tw-text-body tw-font-semibold tw-border-b-0.5 tw-border-solid tw-border-gray-700 tw-mb-4">
5169
Self-managed cold or Hot wallet details
5270
</h4>
71+
<WalletTypeSelector value={walletType} onChange={handleWalletTypeChange} />
5372
<div className="tw-mb-4">
5473
<FormikTextarea
55-
HelperText="Your user public key, as found on your recovery KeyCard. Required for hot wallets."
56-
Label="User Public Key (optional)"
74+
HelperText={userKeyHelperText}
75+
Label={userKeyLabel}
5776
name="userKey"
5877
Width="fill"
5978
/>
@@ -68,28 +87,30 @@ export function GenericEcdsaForm({ onSubmit }: GenericEcdsaFormValues) {
6887
</div>
6988
<div className="tw-mb-4">
7089
<FormikTextarea
71-
HelperText="The backup public key for the wallet, as found on your recovery KeyCard. Required for hot wallets."
72-
Label="Backup Public Key (optional)"
90+
HelperText={backupKeyHelperText}
91+
Label={backupKeyLabel}
7392
name="backupKey"
7493
Width="fill"
7594
/>
7695
</div>
77-
<div className="tw-mb-4">
78-
<FormikPasswordfield
79-
HelperText="Your wallet passphrase, required for hot wallets."
80-
Label="Wallet Passphrase (optional)"
81-
name="walletPassphrase"
82-
Width="fill"
83-
/>
84-
</div>
8596
<div className="tw-mb-4">
8697
<FormikTextfield
87-
HelperText="The BitGo public key for the wallet, as found on your recovery KeyCard."
88-
Label="BitGo Public Key"
98+
HelperText={bitgoKeyHelperText}
99+
Label={bitgoKeyLabel}
89100
name="bitgoKey"
90101
Width="fill"
91102
/>
92103
</div>
104+
{showWalletPassphrase && (
105+
<div className="tw-mb-4">
106+
<FormikPasswordfield
107+
HelperText="The wallet passphrase that you set when creating the wallet."
108+
Label="Wallet Passphrase"
109+
name="walletPassphrase"
110+
Width="fill"
111+
/>
112+
</div>
113+
)}
93114
<div className="tw-mb-4">
94115
<FormikTextfield
95116
HelperText="The starting index (inclusive) of addresses to consolidate"

src/containers/BuildUnsignedConsolidation/SolForm.tsx

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import {
77
FormikTextarea,
88
FormikTextfield,
99
} from '~/components';
10+
import { useWalletTypeLabels, WalletType } from './useWalletTypeLabels';
11+
import { WalletTypeSelector } from './WalletTypeSelector';
1012

11-
const validationSchema = Yup.object({
12-
userKey: Yup.string(),
13-
backupKey: Yup.string(),
13+
const getValidationSchema = (walletType: WalletType) => Yup.object({
14+
userKey: Yup.string().required(),
15+
backupKey: Yup.string().required(),
1416
bitgoKey: Yup.string().required(),
15-
walletPassphrase: Yup.string(),
17+
walletPassphrase: walletType === 'hot' ? Yup.string().required() : Yup.string(),
1618
apiKey: Yup.string().test(
1719
'not-url-or-alchemy',
1820
'API key should not be a URL',
@@ -35,6 +37,8 @@ const validationSchema = Yup.object({
3537
seed: Yup.string(),
3638
}).required();
3739

40+
const validationSchema = getValidationSchema('cold');
41+
3842
export type SolFormValues = Yup.Asserts<typeof validationSchema>;
3943

4044
export type SolFormProps = {
@@ -45,6 +49,18 @@ export type SolFormProps = {
4549
};
4650

4751
export function SolForm({ onSubmit }: SolFormProps) {
52+
const {
53+
walletType,
54+
handleWalletTypeChange,
55+
userKeyLabel,
56+
userKeyHelperText,
57+
backupKeyLabel,
58+
backupKeyHelperText,
59+
bitgoKeyLabel,
60+
bitgoKeyHelperText,
61+
showWalletPassphrase,
62+
} = useWalletTypeLabels();
63+
4864
const formik = useFormik<SolFormValues>({
4965
onSubmit,
5066
initialValues: {
@@ -61,6 +77,8 @@ export function SolForm({ onSubmit }: SolFormProps) {
6177
endingScanIndex: 21,
6278
seed: undefined,
6379
},
80+
validationSchema: getValidationSchema(walletType),
81+
enableReinitialize: true,
6482
});
6583

6684
return (
@@ -69,10 +87,11 @@ export function SolForm({ onSubmit }: SolFormProps) {
6987
<h4 className="tw-text-body tw-font-semibold tw-border-b-0.5 tw-border-solid tw-border-gray-700 tw-mb-4">
7088
Self-managed cold or Hot wallet details
7189
</h4>
90+
<WalletTypeSelector value={walletType} onChange={handleWalletTypeChange} />
7291
<div className="tw-mb-4">
7392
<FormikTextarea
74-
HelperText="Your user public key, as found on your recovery KeyCard. Required for hot wallets."
75-
Label="User Public Key (optional)"
93+
HelperText={userKeyHelperText}
94+
Label={userKeyLabel}
7695
name="userKey"
7796
Width="fill"
7897
/>
@@ -87,20 +106,12 @@ export function SolForm({ onSubmit }: SolFormProps) {
87106
</div>
88107
<div className="tw-mb-4">
89108
<FormikTextarea
90-
HelperText="The backup public key for the wallet, as found on your recovery KeyCard. Required for hot wallets."
91-
Label="Backup Public Key (optional)"
109+
HelperText={backupKeyHelperText}
110+
Label={backupKeyLabel}
92111
name="backupKey"
93112
Width="fill"
94113
/>
95114
</div>
96-
<div className="tw-mb-4">
97-
<FormikPasswordfield
98-
HelperText="Your wallet passphrase, required for hot wallets."
99-
Label="Wallet Passphrase (optional)"
100-
name="walletPassphrase"
101-
Width="fill"
102-
/>
103-
</div>
104115
<div className="tw-mb-4">
105116
<FormikTextarea
106117
HelperText="Public Keys for your durable Nonces"
@@ -120,12 +131,22 @@ export function SolForm({ onSubmit }: SolFormProps) {
120131
</div>
121132
<div className="tw-mb-4">
122133
<FormikTextfield
123-
HelperText="The BitGo public key for the wallet, as found on your recovery KeyCard."
124-
Label="BitGo Public Key"
134+
HelperText={bitgoKeyHelperText}
135+
Label={bitgoKeyLabel}
125136
name="bitgoKey"
126137
Width="fill"
127138
/>
128139
</div>
140+
{showWalletPassphrase && (
141+
<div className="tw-mb-4">
142+
<FormikPasswordfield
143+
HelperText="The wallet passphrase that you set when creating the wallet."
144+
Label="Wallet Passphrase"
145+
name="walletPassphrase"
146+
Width="fill"
147+
/>
148+
</div>
149+
)}
129150
<div className="tw-mb-4">
130151
<FormikTextfield
131152
HelperText="The starting index (inclusive) of addresses to consolidate"

src/containers/BuildUnsignedConsolidation/SolTokenForm.tsx

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import {
88
FormikTextarea,
99
FormikTextfield,
1010
} from '~/components';
11+
import { useWalletTypeLabels, WalletType } from './useWalletTypeLabels';
12+
import { WalletTypeSelector } from './WalletTypeSelector';
1113

12-
const validationSchema = Yup.object({
13-
userKey: Yup.string(),
14-
backupKey: Yup.string(),
14+
const getValidationSchema = (walletType: WalletType) => Yup.object({
15+
userKey: Yup.string().required(),
16+
backupKey: Yup.string().required(),
1517
bitgoKey: Yup.string().required(),
16-
walletPassphrase: Yup.string(),
18+
walletPassphrase: walletType === 'hot' ? Yup.string().required() : Yup.string(),
1719
apiKey: Yup.string().test(
1820
'not-url-or-alchemy',
1921
'API key should not be a URL',
@@ -38,6 +40,8 @@ const validationSchema = Yup.object({
3840
seed: Yup.string(),
3941
}).required();
4042

43+
const validationSchema = getValidationSchema('cold');
44+
4145
export type SolFormValues = Yup.Asserts<typeof validationSchema>;
4246

4347
export type SolFormProps = {
@@ -48,6 +52,18 @@ export type SolFormProps = {
4852
};
4953

5054
export function SolTokenForm({ onSubmit }: SolFormProps) {
55+
const {
56+
walletType,
57+
handleWalletTypeChange,
58+
userKeyLabel,
59+
userKeyHelperText,
60+
backupKeyLabel,
61+
backupKeyHelperText,
62+
bitgoKeyLabel,
63+
bitgoKeyHelperText,
64+
showWalletPassphrase,
65+
} = useWalletTypeLabels();
66+
5167
const formik = useFormik<SolFormValues>({
5268
onSubmit,
5369
initialValues: {
@@ -66,6 +82,8 @@ export function SolTokenForm({ onSubmit }: SolFormProps) {
6682
tokenProgramId: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
6783
seed: undefined,
6884
},
85+
validationSchema: getValidationSchema(walletType),
86+
enableReinitialize: true,
6987
});
7088

7189
return (
@@ -74,10 +92,11 @@ export function SolTokenForm({ onSubmit }: SolFormProps) {
7492
<h4 className="tw-text-body tw-font-semibold tw-border-b-0.5 tw-border-solid tw-border-gray-700 tw-mb-4">
7593
Self-managed cold or Hot wallet details
7694
</h4>
95+
<WalletTypeSelector value={walletType} onChange={handleWalletTypeChange} />
7796
<div className="tw-mb-4">
7897
<FormikTextarea
79-
HelperText="Your user public key, as found on your recovery KeyCard. Required for hot wallets."
80-
Label="User Public Key (optional)"
98+
HelperText={userKeyHelperText}
99+
Label={userKeyLabel}
81100
name="userKey"
82101
Width="fill"
83102
/>
@@ -92,20 +111,12 @@ export function SolTokenForm({ onSubmit }: SolFormProps) {
92111
</div>
93112
<div className="tw-mb-4">
94113
<FormikTextarea
95-
HelperText="The backup public key for the wallet, as found on your recovery KeyCard. Required for hot wallets."
96-
Label="Backup Public Key (optional)"
114+
HelperText={backupKeyHelperText}
115+
Label={backupKeyLabel}
97116
name="backupKey"
98117
Width="fill"
99118
/>
100119
</div>
101-
<div className="tw-mb-4">
102-
<FormikPasswordfield
103-
HelperText="Your wallet passphrase, required for hot wallets."
104-
Label="Wallet Passphrase (optional)"
105-
name="walletPassphrase"
106-
Width="fill"
107-
/>
108-
</div>
109120
<div className="tw-mb-4">
110121
<FormikTextarea
111122
HelperText="Public Keys for your durable Nonces"
@@ -125,12 +136,22 @@ export function SolTokenForm({ onSubmit }: SolFormProps) {
125136
</div>
126137
<div className="tw-mb-4">
127138
<FormikTextfield
128-
HelperText="The BitGo public key for the wallet, as found on your recovery KeyCard."
129-
Label="BitGo Public Key"
139+
HelperText={bitgoKeyHelperText}
140+
Label={bitgoKeyLabel}
130141
name="bitgoKey"
131142
Width="fill"
132143
/>
133144
</div>
145+
{showWalletPassphrase && (
146+
<div className="tw-mb-4">
147+
<FormikPasswordfield
148+
HelperText="The wallet passphrase that you set when creating the wallet."
149+
Label="Wallet Passphrase"
150+
name="walletPassphrase"
151+
Width="fill"
152+
/>
153+
</div>
154+
)}
134155
<div className="tw-mb-4">
135156
<FormikTextfield
136157
HelperText="The address of the smart contract of the token to consolidate. This is unique to each token, and is NOT your wallet address."

0 commit comments

Comments
 (0)