Skip to content

Commit

Permalink
remove seed type dropdown on hex page and update logic decode seed me…
Browse files Browse the repository at this point in the history
…monic
  • Loading branch information
JustinBeBoy committed Apr 29, 2024
1 parent 75503b1 commit 885c9c7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 47 deletions.
20 changes: 10 additions & 10 deletions libwallet/assets/wallet/wallet_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,19 @@ func VerifySeed(seedMnemonic string, assetType utils.AssetType, seedType WordSee
func DecodeSeedMnemonic(seedMnemonic string, assetType utils.AssetType, seedType WordSeedType) (hashedSeed []byte, err error) {
switch assetType {
case utils.BTCWalletAsset, utils.DCRWalletAsset, utils.LTCWalletAsset:
words := strings.Split(strings.TrimSpace(seedMnemonic), " ")
if len(words) == 1 {
var err error
hashedSeed, err = hex.DecodeString(words[0])
if err != nil {
return nil, err
}
return hashedSeed, err
}
if seedType == WordSeed33 {
hashedSeed, err = walletseed.DecodeUserInput(seedMnemonic)
} else {
words := strings.Split(strings.TrimSpace(seedMnemonic), " ")
if len(words) == 1 {
var err error
hashedSeed, err = hex.DecodeString(words[0])
if err != nil {
return nil, err
}
} else {
hashedSeed, err = bip39.EntropyFromMnemonic(seedMnemonic)
}
hashedSeed, err = bip39.EntropyFromMnemonic(seedMnemonic)
}
default:
err = fmt.Errorf("%v: (%v)", utils.ErrAssetUnknown, assetType)
Expand Down
55 changes: 18 additions & 37 deletions ui/page/components/restore_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (pg *Restore) Layout(gtx C) D {
return cryptomaterial.UniformPadding(gtx, body, pg.IsMobileView())
}

func (pg *Restore) restoreLayout(gtx layout.Context) layout.Dimensions {
func (pg *Restore) restoreLayout(gtx C) D {
return pg.tabs.Layout(gtx, func(gtx C) D {
if pg.tabs.SelectedIndex() == 0 {
return pg.seedWordsLayout(gtx)
Expand All @@ -137,19 +137,19 @@ func (pg *Restore) restoreLayout(gtx layout.Context) layout.Dimensions {
func (pg *Restore) seedWordsLayout(gtx C) D {
textSize16 := values.TextSizeTransform(pg.IsMobileView(), values.TextSize16)
return layout.Stack{}.Layout(gtx,
layout.Expanded(func(gtx layout.Context) layout.Dimensions {
return layout.Inset{Top: values.MarginPadding50}.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
layout.Expanded(func(gtx C) D {
return layout.Inset{Top: values.MarginPadding50}.Layout(gtx, func(gtx C) D {
if pg.toggleSeedInput.IsChecked() {
return pg.seedInputLayout(gtx)
}
return layout.Inset{Top: values.MarginPadding5}.Layout(gtx, pg.indexLayout)
})
}),
layout.Expanded(func(gtx layout.Context) layout.Dimensions {
layout.Expanded(func(gtx C) D {
return layout.Flex{Alignment: layout.Middle, Spacing: layout.SpaceBetween}.Layout(gtx,
layout.Rigid(func(gtx C) D {
inset := layout.Inset{Top: values.MarginPadding8}
return inset.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return inset.Layout(gtx, func(gtx C) D {
return layout.Flex{}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Inset{Right: values.MarginPadding10}.Layout(gtx, pg.toggleSeedInput.Layout)
Expand All @@ -172,39 +172,20 @@ func (pg *Restore) seedInputLayout(gtx C) D {
pg.seedInputEditor.Hint = values.String(values.StrEnterWalletHex)
pg.confirmSeedButton.Text = values.String(values.StrValidateWalHex)
}
mt := values.MarginPadding56
isHideDropdown := pg.toggleSeedInput.IsChecked() && pg.tabIndex == 0
if isHideDropdown {
mt = values.MarginPadding5
}
return layout.Stack{}.Layout(gtx,
layout.Expanded(func(gtx layout.Context) layout.Dimensions {
return layout.Inset{
Top: mt,
}.Layout(gtx, func(gtx C) D {
return pg.Theme.Card().Layout(gtx, func(gtx C) D {
return HorizontalInset(values.MarginPadding16).Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(layout.Spacer{Height: values.MarginPadding24}.Layout),
layout.Rigid(pg.seedInputEditor.Layout),
layout.Rigid(func(gtx C) D {
gtx.Constraints.Min.X = gtx.Constraints.Max.X
return layout.E.Layout(gtx, func(gtx C) D {
return VerticalInset(values.MarginPadding16).Layout(gtx, pg.confirmSeedButton.Layout)
})
}),
)
return pg.Theme.Card().Layout(gtx, func(gtx C) D {
return HorizontalInset(values.MarginPadding16).Layout(gtx, func(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(layout.Spacer{Height: values.MarginPadding24}.Layout),
layout.Rigid(pg.seedInputEditor.Layout),
layout.Rigid(func(gtx C) D {
gtx.Constraints.Min.X = gtx.Constraints.Max.X
return layout.E.Layout(gtx, func(gtx C) D {
return VerticalInset(values.MarginPadding16).Layout(gtx, pg.confirmSeedButton.Layout)
})
})
})
}),
layout.Expanded(func(gtx layout.Context) layout.Dimensions {
if isHideDropdown {
return D{}
}
return layout.E.Layout(gtx, pg.seedTypeDropdown.Layout)
}),
)
}),
)
})
})
}

func (pg *Restore) indexLayout(gtx C) D {
Expand Down

0 comments on commit 885c9c7

Please sign in to comment.