Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 39 additions & 17 deletions src/containers/BuildUnsignedConsolidation/GenericEcdsaForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ import {
FormikTextarea,
FormikTextfield,
} from '~/components';
import { getWalletTypeLabels, WalletType } from './useWalletTypeLabels';
import { WalletTypeSelector } from './WalletTypeSelector';

const validationSchema = Yup.object({
userKey: Yup.string(),
backupKey: Yup.string(),
walletType: Yup.string().oneOf(['cold', 'hot']).required(),
userKey: Yup.string().required(),
backupKey: Yup.string().required(),
bitgoKey: Yup.string().required(),
walletPassphrase: Yup.string(),
walletPassphrase: Yup.string().when('walletType', {
is: 'hot',
then: (schema) => schema.required('Wallet passphrase is required for hot wallets'),
otherwise: (schema) => schema,
}),
startingScanIndex: Yup.number(),
endingScanIndex: Yup.number().moreThan(
Yup.ref('startingScanIndex'),
Expand All @@ -34,6 +41,7 @@ export function GenericEcdsaForm({ onSubmit }: GenericEcdsaFormValues) {
const formik = useFormik<EcdsaFormValues>({
onSubmit,
initialValues: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add walletType as the form state, and default to cold. That way you won't need an extra state, and you won't need to add a hook, it could be a straight forward function (useWalletTypeLabels)

walletType: 'cold' as WalletType,
userKey: '',
backupKey: '',
bitgoKey: '',
Expand All @@ -42,18 +50,30 @@ export function GenericEcdsaForm({ onSubmit }: GenericEcdsaFormValues) {
endingScanIndex: 21,
seed: undefined,
},
validationSchema,
});

const {
userKeyLabel,
userKeyHelperText,
backupKeyLabel,
backupKeyHelperText,
bitgoKeyLabel,
bitgoKeyHelperText,
showWalletPassphrase,
} = getWalletTypeLabels(formik.values.walletType as WalletType);

return (
<FormikProvider value={formik}>
<Form>
<h4 className="tw-text-body tw-font-semibold tw-border-b-0.5 tw-border-solid tw-border-gray-700 tw-mb-4">
Self-managed cold or Hot wallet details
</h4>
<WalletTypeSelector />
<div className="tw-mb-4">
<FormikTextarea
HelperText="Your user public key, as found on your recovery KeyCard. Required for hot wallets."
Label="User Public Key (optional)"
HelperText={userKeyHelperText}
Label={userKeyLabel}
name="userKey"
Width="fill"
/>
Expand All @@ -68,28 +88,30 @@ export function GenericEcdsaForm({ onSubmit }: GenericEcdsaFormValues) {
</div>
<div className="tw-mb-4">
<FormikTextarea
HelperText="The backup public key for the wallet, as found on your recovery KeyCard. Required for hot wallets."
Label="Backup Public Key (optional)"
HelperText={backupKeyHelperText}
Label={backupKeyLabel}
name="backupKey"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikPasswordfield
HelperText="Your wallet passphrase, required for hot wallets."
Label="Wallet Passphrase (optional)"
name="walletPassphrase"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikTextfield
HelperText="The BitGo public key for the wallet, as found on your recovery KeyCard."
Label="BitGo Public Key"
HelperText={bitgoKeyHelperText}
Label={bitgoKeyLabel}
name="bitgoKey"
Width="fill"
/>
</div>
{showWalletPassphrase && (
<div className="tw-mb-4">
<FormikPasswordfield
HelperText="The wallet passphrase that you set when creating the wallet."
Label="Wallet Passphrase"
name="walletPassphrase"
Width="fill"
/>
</div>
)}
<div className="tw-mb-4">
<FormikTextfield
HelperText="The starting index (inclusive) of addresses to consolidate"
Expand Down
56 changes: 39 additions & 17 deletions src/containers/BuildUnsignedConsolidation/SolForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ import {
FormikTextarea,
FormikTextfield,
} from '~/components';
import { getWalletTypeLabels, WalletType } from './useWalletTypeLabels';
import { WalletTypeSelector } from './WalletTypeSelector';

const validationSchema = Yup.object({
userKey: Yup.string(),
backupKey: Yup.string(),
walletType: Yup.string().oneOf(['cold', 'hot']).required(),
userKey: Yup.string().required(),
backupKey: Yup.string().required(),
bitgoKey: Yup.string().required(),
walletPassphrase: Yup.string(),
walletPassphrase: Yup.string().when('walletType', {
is: 'hot',
then: (schema) => schema.required('Wallet passphrase is required for hot wallets'),
otherwise: (schema) => schema,
}),
apiKey: Yup.string().test(
'not-url-or-alchemy',
'API key should not be a URL',
Expand Down Expand Up @@ -48,6 +55,7 @@ export function SolForm({ onSubmit }: SolFormProps) {
const formik = useFormik<SolFormValues>({
onSubmit,
initialValues: {
walletType: 'cold' as WalletType,
userKey: '',
backupKey: '',
bitgoKey: '',
Expand All @@ -61,18 +69,30 @@ export function SolForm({ onSubmit }: SolFormProps) {
endingScanIndex: 21,
seed: undefined,
},
validationSchema,
});

const {
userKeyLabel,
userKeyHelperText,
backupKeyLabel,
backupKeyHelperText,
bitgoKeyLabel,
bitgoKeyHelperText,
showWalletPassphrase,
} = getWalletTypeLabels(formik.values.walletType as WalletType);

return (
<FormikProvider value={formik}>
<Form>
<h4 className="tw-text-body tw-font-semibold tw-border-b-0.5 tw-border-solid tw-border-gray-700 tw-mb-4">
Self-managed cold or Hot wallet details
</h4>
<WalletTypeSelector />
<div className="tw-mb-4">
<FormikTextarea
HelperText="Your user public key, as found on your recovery KeyCard. Required for hot wallets."
Label="User Public Key (optional)"
HelperText={userKeyHelperText}
Label={userKeyLabel}
name="userKey"
Width="fill"
/>
Expand All @@ -87,20 +107,12 @@ export function SolForm({ onSubmit }: SolFormProps) {
</div>
<div className="tw-mb-4">
<FormikTextarea
HelperText="The backup public key for the wallet, as found on your recovery KeyCard. Required for hot wallets."
Label="Backup Public Key (optional)"
HelperText={backupKeyHelperText}
Label={backupKeyLabel}
name="backupKey"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikPasswordfield
HelperText="Your wallet passphrase, required for hot wallets."
Label="Wallet Passphrase (optional)"
name="walletPassphrase"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikTextarea
HelperText="Public Keys for your durable Nonces"
Expand All @@ -120,12 +132,22 @@ export function SolForm({ onSubmit }: SolFormProps) {
</div>
<div className="tw-mb-4">
<FormikTextfield
HelperText="The BitGo public key for the wallet, as found on your recovery KeyCard."
Label="BitGo Public Key"
HelperText={bitgoKeyHelperText}
Label={bitgoKeyLabel}
name="bitgoKey"
Width="fill"
/>
</div>
{showWalletPassphrase && (
<div className="tw-mb-4">
<FormikPasswordfield
HelperText="The wallet passphrase that you set when creating the wallet."
Label="Wallet Passphrase"
name="walletPassphrase"
Width="fill"
/>
</div>
)}
<div className="tw-mb-4">
<FormikTextfield
HelperText="The starting index (inclusive) of addresses to consolidate"
Expand Down
56 changes: 39 additions & 17 deletions src/containers/BuildUnsignedConsolidation/SolTokenForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ import {
FormikTextarea,
FormikTextfield,
} from '~/components';
import { getWalletTypeLabels, WalletType } from './useWalletTypeLabels';
import { WalletTypeSelector } from './WalletTypeSelector';

const validationSchema = Yup.object({
userKey: Yup.string(),
backupKey: Yup.string(),
walletType: Yup.string().oneOf(['cold', 'hot']).required(),
userKey: Yup.string().required(),
backupKey: Yup.string().required(),
bitgoKey: Yup.string().required(),
walletPassphrase: Yup.string(),
walletPassphrase: Yup.string().when('walletType', {
is: 'hot',
then: (schema) => schema.required('Wallet passphrase is required for hot wallets'),
otherwise: (schema) => schema,
}),
apiKey: Yup.string().test(
'not-url-or-alchemy',
'API key should not be a URL',
Expand Down Expand Up @@ -51,6 +58,7 @@ export function SolTokenForm({ onSubmit }: SolFormProps) {
const formik = useFormik<SolFormValues>({
onSubmit,
initialValues: {
walletType: 'cold' as WalletType,
userKey: '',
backupKey: '',
bitgoKey: '',
Expand All @@ -66,18 +74,30 @@ export function SolTokenForm({ onSubmit }: SolFormProps) {
tokenProgramId: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
seed: undefined,
},
validationSchema,
});

const {
userKeyLabel,
userKeyHelperText,
backupKeyLabel,
backupKeyHelperText,
bitgoKeyLabel,
bitgoKeyHelperText,
showWalletPassphrase,
} = getWalletTypeLabels(formik.values.walletType as WalletType);

return (
<FormikProvider value={formik}>
<Form>
<h4 className="tw-text-body tw-font-semibold tw-border-b-0.5 tw-border-solid tw-border-gray-700 tw-mb-4">
Self-managed cold or Hot wallet details
</h4>
<WalletTypeSelector />
<div className="tw-mb-4">
<FormikTextarea
HelperText="Your user public key, as found on your recovery KeyCard. Required for hot wallets."
Label="User Public Key (optional)"
HelperText={userKeyHelperText}
Label={userKeyLabel}
name="userKey"
Width="fill"
/>
Expand All @@ -92,20 +112,12 @@ export function SolTokenForm({ onSubmit }: SolFormProps) {
</div>
<div className="tw-mb-4">
<FormikTextarea
HelperText="The backup public key for the wallet, as found on your recovery KeyCard. Required for hot wallets."
Label="Backup Public Key (optional)"
HelperText={backupKeyHelperText}
Label={backupKeyLabel}
name="backupKey"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikPasswordfield
HelperText="Your wallet passphrase, required for hot wallets."
Label="Wallet Passphrase (optional)"
name="walletPassphrase"
Width="fill"
/>
</div>
<div className="tw-mb-4">
<FormikTextarea
HelperText="Public Keys for your durable Nonces"
Expand All @@ -125,12 +137,22 @@ export function SolTokenForm({ onSubmit }: SolFormProps) {
</div>
<div className="tw-mb-4">
<FormikTextfield
HelperText="The BitGo public key for the wallet, as found on your recovery KeyCard."
Label="BitGo Public Key"
HelperText={bitgoKeyHelperText}
Label={bitgoKeyLabel}
name="bitgoKey"
Width="fill"
/>
</div>
{showWalletPassphrase && (
<div className="tw-mb-4">
<FormikPasswordfield
HelperText="The wallet passphrase that you set when creating the wallet."
Label="Wallet Passphrase"
name="walletPassphrase"
Width="fill"
/>
</div>
)}
<div className="tw-mb-4">
<FormikTextfield
HelperText="The address of the smart contract of the token to consolidate. This is unique to each token, and is NOT your wallet address."
Expand Down
Loading