Skip to content

Commit

Permalink
add debug
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeBoy committed May 23, 2024
1 parent a9aee92 commit 5bfcb2b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
4 changes: 3 additions & 1 deletion libwallet/assets/wallet/wallet_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func VerifyMnemonic(seedMnemonic string, assetType utils.AssetType, seedType Wor
}

func DecodeSeedMnemonic(seedMnemonic string, assetType utils.AssetType, seedType WordSeedType) (hashedSeed []byte, err error) {
seedMnemonic = strings.TrimSpace(seedMnemonic)
switch assetType {
case utils.BTCWalletAsset, utils.DCRWalletAsset, utils.LTCWalletAsset:
words := strings.Split(strings.TrimSpace(seedMnemonic), " ")
Expand All @@ -237,12 +238,13 @@ func DecodeSeedMnemonic(seedMnemonic string, assetType utils.AssetType, seedType
return nil, err
}
}

// seedMnemonic is list of words
if seedType == WordSeed33 {
hashedSeed, err = walletseed.DecodeUserInput(seedMnemonic)
} else {
fmt.Println("-------DecodeSeedMnemonic-----22222--->", seedMnemonic)
hashedSeed, err = bip39.NewSeedWithErrorChecking(seedMnemonic, "")
fmt.Println("------DecodeSeedMnemonic--22222--->", err)
}
default:
err = fmt.Errorf("%v: (%v)", utils.ErrAssetUnknown, assetType)
Expand Down
4 changes: 4 additions & 0 deletions libwallet/dcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package libwallet

import (
"context"
"fmt"

"decred.org/dcrwallet/v3/errors"
"decred.org/dcrwallet/v3/walletseed"
Expand Down Expand Up @@ -155,10 +156,13 @@ func (mgr *AssetsManager) DCRWalletWithSeed(seedMnemonic string, wordSeedType sh
func deriveBIP44AccountXPubsForDCR(seedMnemonic string, wordSeedType sharedW.WordSeedType, account uint32, params *chaincfg.Params) (string, string, error) {
var seed []byte
var err error
fmt.Println("-------deriveBIP44AccountXPubsForDCR-----wordSeedType--->", wordSeedType)
if wordSeedType == sharedW.WordSeed33 {
seed, err = walletseed.DecodeUserInput(seedMnemonic)
} else {
fmt.Println("-------deriveBIP44AccountXPubsForDCR-----seed--->", seedMnemonic)
seed, err = bip39.NewSeedWithErrorChecking(seedMnemonic, "")
fmt.Println("-------deriveBIP44AccountXPubsForDCR-----err--->", err)
}
if err != nil {
return "", "", err
Expand Down
8 changes: 7 additions & 1 deletion ui/page/components/restore_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ func (pg *Restore) restoreFromSeedEditor() {
pg.seedInputEditor.Editor.SetText("")
}

fmt.Println("--restoreFromSeedEditor--------------->")

seedOrHex := strings.TrimSpace(pg.seedInputEditor.Editor.Text())
// Check if the user did input a hex or seed. If its a hex set the correct tabindex.
if len(seedOrHex) > MaxSeedBytes {
Expand All @@ -310,6 +312,7 @@ func (pg *Restore) restoreFromSeedEditor() {
}

if !sharedW.VerifyMnemonic(seedOrHex, pg.walletType, wordSeedType) {
fmt.Println("--sharedW.VerifyMnemonic----->", seedOrHex)
errMsg := values.String(values.StrInvalidHex)
if pg.tabIndex == 0 {
errMsg = values.String(values.StrInvalidSeedPhrase)
Expand All @@ -320,7 +323,10 @@ func (pg *Restore) restoreFromSeedEditor() {
return
}

walletWithSameSeed, err := pg.AssetsManager.WalletWithSeed(pg.walletType, seedOrHex, pg.getWordSeedType())
fmt.Println("--aaaaaaaaaaaaaaaaaaaa----->")

walletWithSameSeed, err := pg.AssetsManager.WalletWithSeed(pg.walletType, seedOrHex, wordSeedType)
fmt.Println("---errerrerrerrerr----->", err)
if err != nil {
log.Error(err)
errMsg := values.String(values.StrInvalidHex)
Expand Down
16 changes: 9 additions & 7 deletions ui/page/components/seed_restore_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ type SeedRestore struct {
optionsMenuCard cryptomaterial.Card
window app.WindowNavigator

suggestions []string
allSuggestions []string
seedMenu []seedItemMenu
suggestions []string
// allSuggestions []string
seedMenu []seedItemMenu

seedPhrase string
walletName string
Expand Down Expand Up @@ -110,7 +110,7 @@ func NewSeedRestorePage(l *load.Load, walletName string, walletType libutils.Ass
pg.initSeedMenu()

// set suggestions
pg.allSuggestions = getWordSeedType().AllWords()
// pg.allSuggestions = getWordSeedType().AllWords()

return pg
}
Expand Down Expand Up @@ -407,7 +407,7 @@ func (pg SeedRestore) suggestionSeeds(text string) []string {
return seeds
}

for _, word := range pg.allSuggestions {
for _, word := range pg.getWordSeedType().AllWords() {
if strings.HasPrefix(strings.ToLower(word), strings.ToLower(text)) {
if len(seeds) < pg.suggestionLimit {
seeds = append(seeds, word)
Expand All @@ -426,7 +426,7 @@ func (pg *SeedRestore) updateSeedResetBtn() bool {

func (pg *SeedRestore) validateSeeds() (bool, string) {
seedPhrase := ""
allSuggestedWords := strings.Join(pg.allSuggestions, " ")
allSuggestedWords := strings.Join(pg.getWordSeedType().AllWords(), " ")
numberOfSeed := pg.getWordSeedType().ToInt()
for i, editor := range pg.seedEditors.editors {
if i >= numberOfSeed {
Expand All @@ -443,6 +443,7 @@ func (pg *SeedRestore) validateSeeds() (bool, string) {
}

func (pg *SeedRestore) verifySeeds() bool {
fmt.Println("------verifySeeds----------22222222--->")
isValid, seedphrase := pg.validateSeeds()
pg.seedPhrase = ""

Expand Down Expand Up @@ -473,7 +474,7 @@ func (pg *SeedRestore) verifySeeds() bool {
}

func (pg *SeedRestore) resetSeeds() {
pg.allSuggestions = pg.getWordSeedType().AllWords()
// pg.allSuggestions = pg.getWordSeedType().AllWords()
pg.seedEditors.focusIndex = -1
for i := 0; i < len(pg.seedEditors.editors); i++ {
pg.seedEditors.editors[i].Edit.Editor.SetText("")
Expand Down Expand Up @@ -520,6 +521,7 @@ func (pg *SeedRestore) HandleUserInteractions() {
}

if pg.validateSeed.Clicked() {
fmt.Println("------validateSeed----------111111--->")
if !pg.verifySeeds() {
return
}
Expand Down

0 comments on commit 5bfcb2b

Please sign in to comment.