-
Notifications
You must be signed in to change notification settings - Fork 46
feat(wp): hot and cold self managed #644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SimonVutovB
wants to merge
2
commits into
master
Choose a base branch
from
WP-1338-WRW-bugs-1-Build-Unsigned-Consolidation-screen
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,12 +7,15 @@ import { | |
| FormikTextarea, | ||
| FormikTextfield, | ||
| } from '~/components'; | ||
| import { getWalletTypeLabels, WalletType } from './useWalletTypeLabels'; | ||
| import { WalletTypeSelector } from './WalletTypeSelector'; | ||
|
|
||
| const validationSchema = Yup.object({ | ||
| userKey: Yup.string(), | ||
| backupKey: Yup.string(), | ||
| const getValidationSchema = (walletType: WalletType) => Yup.object({ | ||
| walletType: Yup.string().oneOf(['cold', 'hot']).required(), | ||
| userKey: Yup.string().required(), | ||
| backupKey: Yup.string().required(), | ||
| bitgoKey: Yup.string().required(), | ||
| walletPassphrase: Yup.string(), | ||
| walletPassphrase: walletType === 'hot' ? Yup.string().required() : Yup.string(), | ||
| startingScanIndex: Yup.number(), | ||
| endingScanIndex: Yup.number().moreThan( | ||
| Yup.ref('startingScanIndex'), | ||
|
|
@@ -21,7 +24,7 @@ const validationSchema = Yup.object({ | |
| seed: Yup.string(), | ||
| }).required(); | ||
|
|
||
| export type EcdsaFormValues = Yup.Asserts<typeof validationSchema>; | ||
| export type EcdsaFormValues = Yup.Asserts<ReturnType<typeof getValidationSchema>>; | ||
|
|
||
| export type GenericEcdsaFormValues = { | ||
| onSubmit: ( | ||
|
|
@@ -34,6 +37,7 @@ export function GenericEcdsaForm({ onSubmit }: GenericEcdsaFormValues) { | |
| const formik = useFormik<EcdsaFormValues>({ | ||
| onSubmit, | ||
| initialValues: { | ||
| walletType: 'cold' as WalletType, | ||
| userKey: '', | ||
| backupKey: '', | ||
| bitgoKey: '', | ||
|
|
@@ -42,18 +46,43 @@ export function GenericEcdsaForm({ onSubmit }: GenericEcdsaFormValues) { | |
| endingScanIndex: 21, | ||
| seed: undefined, | ||
| }, | ||
| validate: (values) => { | ||
| try { | ||
| getValidationSchema(values.walletType as WalletType).validateSync(values, { abortEarly: false }); | ||
| return {}; | ||
| } catch (error: any) { | ||
| const errors: Record<string, string> = {}; | ||
| error.inner?.forEach((err: any) => { | ||
| if (err.path) { | ||
| errors[err.path] = err.message; | ||
| } | ||
| }); | ||
| return errors; | ||
| } | ||
| }, | ||
|
||
| }); | ||
|
|
||
| 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" | ||
| /> | ||
|
|
@@ -68,28 +97,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" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,12 +7,15 @@ import { | |
| FormikTextarea, | ||
| FormikTextfield, | ||
| } from '~/components'; | ||
| import { getWalletTypeLabels, WalletType } from './useWalletTypeLabels'; | ||
| import { WalletTypeSelector } from './WalletTypeSelector'; | ||
|
|
||
| const validationSchema = Yup.object({ | ||
| userKey: Yup.string(), | ||
| backupKey: Yup.string(), | ||
| const getValidationSchema = (walletType: WalletType) => Yup.object({ | ||
| walletType: Yup.string().oneOf(['cold', 'hot']).required(), | ||
| userKey: Yup.string().required(), | ||
| backupKey: Yup.string().required(), | ||
| bitgoKey: Yup.string().required(), | ||
| walletPassphrase: Yup.string(), | ||
| walletPassphrase: walletType === 'hot' ? Yup.string().required() : Yup.string(), | ||
| apiKey: Yup.string().test( | ||
| 'not-url-or-alchemy', | ||
| 'API key should not be a URL', | ||
|
|
@@ -35,7 +38,7 @@ const validationSchema = Yup.object({ | |
| seed: Yup.string(), | ||
| }).required(); | ||
|
|
||
| export type SolFormValues = Yup.Asserts<typeof validationSchema>; | ||
| export type SolFormValues = Yup.Asserts<ReturnType<typeof getValidationSchema>>; | ||
|
|
||
| export type SolFormProps = { | ||
| onSubmit: ( | ||
|
|
@@ -48,6 +51,7 @@ export function SolForm({ onSubmit }: SolFormProps) { | |
| const formik = useFormik<SolFormValues>({ | ||
| onSubmit, | ||
| initialValues: { | ||
| walletType: 'cold' as WalletType, | ||
| userKey: '', | ||
| backupKey: '', | ||
| bitgoKey: '', | ||
|
|
@@ -61,18 +65,43 @@ export function SolForm({ onSubmit }: SolFormProps) { | |
| endingScanIndex: 21, | ||
| seed: undefined, | ||
| }, | ||
| validate: (values) => { | ||
| try { | ||
| getValidationSchema(values.walletType as WalletType).validateSync(values, { abortEarly: false }); | ||
| return {}; | ||
| } catch (error: any) { | ||
| const errors: Record<string, string> = {}; | ||
| error.inner?.forEach((err: any) => { | ||
| if (err.path) { | ||
| errors[err.path] = err.message; | ||
| } | ||
| }); | ||
| return errors; | ||
| } | ||
| }, | ||
| }); | ||
|
||
|
|
||
| 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" | ||
| /> | ||
|
|
@@ -87,20 +116,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" | ||
|
|
@@ -120,12 +141,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" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add
walletTypeas the form state, and default to cold. That way you won't need an extra state, and you won't need to add ahook, it could be a straight forward function (useWalletTypeLabels)