fix(@desktop/wallet): crash adding an account via seed phrase fixed

This commit is contained in:
Sale Djenic 2022-09-23 13:13:15 +02:00 committed by saledjenic
parent f11ff29cb4
commit 4bff0b14ed
8 changed files with 26 additions and 9 deletions

View File

@ -167,7 +167,7 @@ proc newModule*[T](
result.walletSectionModule = wallet_section_module.newModule(
result, events, tokenService,
transactionService, collectible_service, walletAccountService,
settingsService, savedAddressService, networkService,
settingsService, savedAddressService, networkService, accountsService
)
result.browserSectionModule = browser_section_module.newModule(
result, events, bookmarkService, settingsService, networkService,

View File

@ -1,18 +1,23 @@
import io_interface
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ../../../../../app_service/service/accounts/service as accounts_service
type
Controller* = ref object of RootObj
delegate: io_interface.AccessInterface
walletAccountService: wallet_account_service.Service
accountsService: accounts_service.Service
proc newController*(
delegate: io_interface.AccessInterface,
walletAccountService: wallet_account_service.Service
walletAccountService: wallet_account_service.Service,
accountsService: accounts_service.Service
): Controller =
result = Controller()
result.delegate = delegate
result.walletAccountService = walletAccountService
result.accountsService = accountsService
proc delete*(self: Controller) =
discard
@ -47,4 +52,7 @@ method getDerivedAddressListForMnemonic*(self: Controller, mnemonic: string, pat
method getDerivedAddressForPrivateKey*(self: Controller, privateKey: string) =
self.walletAccountService.getDerivedAddressForPrivateKey(privateKey)
proc validSeedPhrase*(self: Controller, seedPhrase: string): bool =
let err = self.accountsService.validateMnemonic(seedPhrase)
return err.len == 0

View File

@ -45,3 +45,6 @@ method getDerivedAddressForPrivateKey*(self: AccessInterface, privateKey: string
# inheritance, which is not well supported in Nim.
method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method validSeedPhrase*(self: AccessInterface, value: string): bool {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -5,6 +5,7 @@ import ../io_interface as delegate_interface
import ../../../../global/global_singleton
import ../../../../core/eventemitter
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ../../../../../app_service/service/accounts/service as accounts_service
import ../../../shared_models/token_model as token_model
import ../../../shared_models/token_item as token_item
import ./compact_item as compact_item
@ -24,12 +25,13 @@ proc newModule*(
delegate: delegate_interface.AccessInterface,
events: EventEmitter,
walletAccountService: wallet_account_service.Service,
accountsService: accounts_service.Service
): Module =
result = Module()
result.delegate = delegate
result.events = events
result.view = newView(result)
result.controller = controller.newController(result, walletAccountService)
result.controller = controller.newController(result, events, walletAccountService, accountsService)
result.moduleLoaded = false
method delete*(self: Module) =
@ -168,6 +170,5 @@ method getDerivedAddressListForMnemonic*(self: Module, mnemonic: string, path: s
method getDerivedAddressForPrivateKey*(self: Module, privateKey: string) =
self.controller.getDerivedAddressForPrivateKey(privateKey)
method validSeedPhrase*(self: Module, value: string): bool =
return self.controller.validSeedPhrase(value)

View File

@ -275,3 +275,5 @@ QtObject:
proc getNextSelectableDerivedAddressIndex*(self: View): int {.slot.} =
return self.derivedAddresses.getNextSelectableDerivedAddressIndex()
proc validSeedPhrase*(self: View, value: string): bool {.slot.} =
return self.delegate.validSeedPhrase(value)

View File

@ -21,6 +21,7 @@ import ../../../../app_service/service/wallet_account/service as wallet_account_
import ../../../../app_service/service/settings/service as settings_service
import ../../../../app_service/service/saved_address/service as saved_address_service
import ../../../../app_service/service/network/service as network_service
import ../../../../app_service/service/accounts/service as accounts_service
import io_interface
export io_interface
@ -40,6 +41,7 @@ type
transactionsModule: transactions_module.AccessInterface
savedAddressesModule: saved_addresses_module.AccessInterface
buySellCryptoModule: buy_sell_crypto_module.AccessInterface
accountsService: accounts_service.Service
proc newModule*(
delegate: delegate_interface.AccessInterface,
@ -51,6 +53,7 @@ proc newModule*(
settingsService: settings_service.Service,
savedAddressService: saved_address_service.Service,
networkService: network_service.Service,
accountsService: accounts_service.Service
): Module =
result = Module()
result.delegate = delegate
@ -59,7 +62,7 @@ proc newModule*(
result.controller = newController(result, settingsService, walletAccountService, networkService)
result.view = newView(result)
result.accountsModule = accounts_module.newModule(result, events, walletAccountService)
result.accountsModule = accounts_module.newModule(result, events, walletAccountService, accountsService)
result.allTokensModule = all_tokens_module.newModule(result, events, tokenService, walletAccountService)
result.collectiblesModule = collectibles_module.newModule(result, events, collectibleService, walletAccountService)
result.currentAccountModule = current_account_module.newModule(result, events, walletAccountService)

View File

@ -37,7 +37,7 @@ StatusGridView {
if (!Utils.isMnemonic(mnemonicString)) {
_internal.errorString = qsTr("Invalid seed phrase")
} else {
if (!RootStore.validMnemonic(mnemonicString)) {
if (!RootStore.validSeedPhrase(mnemonicString)) {
_internal.errorString = qsTr("Invalid seed phrase") + '. ' +
qsTr("This seed phrase doesn't match our supported dictionary. Check for misspelled words.")
}

View File

@ -215,8 +215,8 @@ QtObject {
walletSectionAccounts.resetDerivedAddressModel()
}
function validMnemonic(mnemonic) {
return startupModule.validMnemonic(mnemonic)
function validSeedPhrase(mnemonic) {
return walletSectionAccounts.validSeedPhrase(mnemonic)
}
function getNextSelectableDerivedAddressIndex() {