Skip to content

Commit

Permalink
fix: seed copy when change
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Jul 17, 2024
1 parent 33aeea0 commit f531bf9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changeset/dull-bobcats-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'renterd': patch
'hostd': patch
---

Copying the seed value is now only required if the value has changed.
20 changes: 13 additions & 7 deletions hostd/renderer/contexts/config/fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ export function getFields({
toggleShowMnemonic,
showHttpPassword,
toggleShowHttpPassword,
currentMnemonic,
}: {
defaultDataPath?: string
showMnemonic: boolean
toggleShowMnemonic: () => void
showHttpPassword: boolean
toggleShowHttpPassword: () => void
currentMnemonic?: string
}): ConfigFields<ConfigValues, never> {
return {
name: {
Expand Down Expand Up @@ -74,14 +76,18 @@ export function getFields({
'Example: tent small dress shop wealth fantasy wave mobile hint faith skirt derive',
validation: {
required: 'required',
validate: {
valid: async (value) => {
const valid = bip39.validateMnemonic(value as string)
return valid || 'should be 12 word BIP39 mnemonic'
validate: {
valid: async (value) => {
const valid = bip39.validateMnemonic(value as string)
return valid || 'should be 12 word BIP39 mnemonic'
},
copied: (value: string, values: ConfigValues) => {
if (value === currentMnemonic) {
return true
}
return values.hasCopied || 'Copy recovery phrase to continue'
}
},
copied: (_, values) =>
values.hasCopied || 'Copy recovery phrase to continue',
},
},
},
autoOpenWebUI: {
Expand Down
6 changes: 6 additions & 0 deletions hostd/renderer/contexts/config/useForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export function useForm({ resources }: { resources?: Resources }) {
}
}, [form])

const currentMnemonic = useMemo(() =>
resources?.config?.data?.recoveryPhrase
, [resources])

const fields = useMemo(
() =>
getFields({
Expand All @@ -80,8 +84,10 @@ export function useForm({ resources }: { resources?: Resources }) {
showMnemonic,
toggleShowHttpPassword,
showHttpPassword,
currentMnemonic,
}),
[
currentMnemonic,
dataDir,
resources,
copySeed,
Expand Down
10 changes: 8 additions & 2 deletions renterd/renderer/contexts/config/fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ export function getFields({
toggleShowMnemonic,
showHttpPassword,
toggleShowHttpPassword,
currentMnemonic,
}: {
s3Enabled: boolean
defaultDataPath?: string
showMnemonic: boolean
toggleShowMnemonic: () => void
showHttpPassword: boolean
toggleShowHttpPassword: () => void
currentMnemonic?: string
}): ConfigFields<ConfigValues, never> {
return {
dataDir: {
Expand Down Expand Up @@ -72,8 +74,12 @@ export function getFields({
const valid = bip39.validateMnemonic(value as string)
return valid || 'should be 12 word BIP39 mnemonic'
},
copied: (_, values: ConfigValues) =>
values.hasCopied || 'Copy recovery phrase to continue',
copied: (value: string, values: ConfigValues) => {
if (value === currentMnemonic) {
return true
}
return values.hasCopied || 'Copy recovery phrase to continue'
}
},
},
},
Expand Down
6 changes: 6 additions & 0 deletions renterd/renderer/contexts/config/useForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,14 @@ export function useForm({ resources }: { resources?: Resources }) {

const s3Enabled = form.watch('s3Enabled')

const currentMnemonic = useMemo(() =>
resources?.config?.data?.seed
, [resources])

const fields = useMemo(
() =>
getFields({
currentMnemonic,
s3Enabled,
defaultDataPath: resources?.defaultDataPath.data,
toggleShowMnemonic,
Expand All @@ -85,6 +90,7 @@ export function useForm({ resources }: { resources?: Resources }) {
showHttpPassword,
}),
[
currentMnemonic,
s3Enabled,
dataDir,
resources,
Expand Down

0 comments on commit f531bf9

Please sign in to comment.