From e85bc03fd0a05b3973cfc51a5a84849d6459e75a Mon Sep 17 00:00:00 2001 From: Mauricio Perdomo Date: Fri, 6 Mar 2020 11:55:11 -0500 Subject: [PATCH 1/4] Update history UI after every new transaction --- src/models/history/historyManager.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/models/history/historyManager.go b/src/models/history/historyManager.go index e1d7235d..23b0d5f4 100644 --- a/src/models/history/historyManager.go +++ b/src/models/history/historyManager.go @@ -129,9 +129,8 @@ func (hm *HistoryManager) updateTxns() { logHistoryManager.Warn("Couldn't get address iterator") continue } - var newTxnsFinded bool + for addressIterator.Next() { - newTxnsFinded = false txnsIterator := addressIterator.Value().GetCryptoAccount().ListTransactions() if txnsIterator == nil { logHistoryManager.Warn("Couldn't get transaction iterator") @@ -186,15 +185,10 @@ func (hm *HistoryManager) updateTxns() { if corrupted { continue } - newTxnsFinded = true + hm.NewTransactions() hm.txnFinded[txnsIterator.Value().GetId()] = struct{}{} } } - if newTxnsFinded { - models.Helper.RunInMain(func() { - hm.NewTransactions() - }) - } } } From 339a1bf5205f43ae9ca8f80fee493e6a64b3a42f Mon Sep 17 00:00:00 2001 From: Mauricio Perdomo Date: Fri, 6 Mar 2020 16:09:30 -0500 Subject: [PATCH 2/4] Add oredered addresses to wallet manager i order to keep order for addresses in UI --- src/models/walletsManager.go | 58 +++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/src/models/walletsManager.go b/src/models/walletsManager.go index 59cdfee7..c5499d62 100644 --- a/src/models/walletsManager.go +++ b/src/models/walletsManager.go @@ -43,20 +43,21 @@ type updateWalletInfo struct { } type WalletManager struct { qtCore.QObject - WalletEnv core.WalletEnv - SeedGenerator core.SeedGenerator - wallets []*QWallet - addresseseByWallets map[string](map[string]*QAddress) - utilByWallets map[string]*utilByWallet - markedAddress map[string]int - outputsByAddress map[string][]*QOutput - outputsByAddressMutex sync.Mutex - altManager core.AltcoinManager - signer core.BlockchainSignService - transactionAPI core.BlockchainTransactionAPI - walletsIterator core.WalletIterator - updaterChannel chan *updateWalletInfo - timerUpdate chan time.Duration + WalletEnv core.WalletEnv + SeedGenerator core.SeedGenerator + wallets []*QWallet + addresseseByWallets map[string](map[string]*QAddress) + orderedAddressesByWallets map[string][]*QAddress + utilByWallets map[string]*utilByWallet + markedAddress map[string]int + outputsByAddress map[string][]*QOutput + outputsByAddressMutex sync.Mutex + altManager core.AltcoinManager + signer core.BlockchainSignService + transactionAPI core.BlockchainTransactionAPI + walletsIterator core.WalletIterator + updaterChannel chan *updateWalletInfo + timerUpdate chan time.Duration _ func() `slot:"updateWalletEnvs"` _ func(wltId, address string) `slot:"updateOutputs"` @@ -123,6 +124,7 @@ func (walletM *WalletManager) init() { walletM.ConnectEditMarkAddress(walletM.editMarkAddress) walletM.ConnectMarkFieldOfAddress(walletM.markFieldOfAddress) walletM.addresseseByWallets = make(map[string](map[string]*QAddress), 0) + walletM.orderedAddressesByWallets = make(map[string][]*QAddress, 0) walletM.utilByWallets = make(map[string]*utilByWallet, 0) walletM.outputsByAddress = make(map[string][]*QOutput, 0) walletM.SeedGenerator = new(sky.SeedService) @@ -295,7 +297,8 @@ func (walletM *WalletManager) updateWalletEnvs() { func (walletM *WalletManager) initWalletAddresses(wltId string) { logWalletManager.Info("Updating Addresses") wlt := walletM.WalletEnv.GetWalletSet().GetWallet(wltId) - qAddresses := make(map[string]*QAddress, 0) + qAddresses1 := make(map[string]*QAddress, 0) + qAddresses2 := make([]*QAddress, 0) it, err := wlt.GetLoadedAddresses() if err != nil { logWalletManager.WithError(err).Warn("Couldn't loaded addresses") @@ -313,25 +316,27 @@ func (walletM *WalletManager) initWalletAddresses(wltId string) { qAddress.SetAddressCoinHours("N/A") qml.QQmlEngine_SetObjectOwnership(qAddress, qml.QQmlEngine__CppOwnership) - //qAddresses = append(qAddresses, qAddress) - qAddresses[addr.String()] = qAddress + qAddresses2 = append(qAddresses2, qAddress) + qAddresses1[addr.String()] = qAddress go walletM.getOutputs(wltId, addr.String()) } - walletM.addresseseByWallets[wltId] = qAddresses + walletM.addresseseByWallets[wltId] = qAddresses1 + walletM.orderedAddressesByWallets[wltId] = qAddresses2 } func (walletM *WalletManager) updateAddresses(wltId string) { - mutex := walletM.utilByWallets[wltId].m + mutex := &walletM.utilByWallets[wltId].m sendChan := walletM.utilByWallets[wltId].sendChannel addresses, ok := walletM.addresseseByWallets[wltId] if !ok { walletM.addresseseByWallets[wltId] = make(map[string]*QAddress) + walletM.orderedAddressesByWallets[wltId] = make([]*QAddress, 0) addresses = walletM.addresseseByWallets[wltId] } - mutex.Lock() - defer mutex.Unlock() + (*mutex).Lock() + defer (*mutex).Unlock() logWalletManager.Info("Updating Addresses") wlt := walletM.WalletEnv.GetWalletSet().GetWallet(wltId) if wlt == nil { @@ -1071,16 +1076,13 @@ func (walletM *WalletManager) editWallet(id, label string) *QWallet { } func (walletM *WalletManager) getAddresses(Id string) []*QAddress { - addrs, ok := walletM.addresseseByWallets[Id] + addrs, ok := walletM.orderedAddressesByWallets[Id] if !ok { walletM.updateAddresses(Id) - addrs = walletM.addresseseByWallets[Id] + addrs = walletM.orderedAddressesByWallets[Id] } - addresses := make([]*QAddress, 0) - for _, addr := range addrs { - addresses = append(addresses, addr) - } - return addresses + + return addrs } func fromWalletToQWallet(wlt core.Wallet, isEncrypted, withoutBalance bool) *QWallet { From 3224ab05dcfb6bfdd0017ad82ad07bb2ba5a39a8 Mon Sep 17 00:00:00 2001 From: Alvaro Denis Date: Mon, 9 Mar 2020 18:09:17 -0400 Subject: [PATCH 3/4] fix error checking in walletManager signTxn ref #353 --- src/models/walletsManager.go | 7 ++++++- src/models/walletsModel.go | 2 -- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/models/walletsManager.go b/src/models/walletsManager.go index c5499d62..83ca2e64 100644 --- a/src/models/walletsManager.go +++ b/src/models/walletsManager.go @@ -862,7 +862,12 @@ func (walletM *WalletManager) signTxn(wltIds, address []string, source string, t logWalletManager.WithError(err).Warnf("No signer %s for wallet %v", source, wlts[0]) return nil } - if suid, err := signer.GetSignerUID(); err != nil && wlts[0].GetId() == string(suid) { + signerUid, err := signer.GetSignerUID() + if err != nil { + logWalletManager.WithError(err).Errorln("unable to ger signer uuid") + return nil + } + if wlts[0].GetId() == string(signerUid) { // NOTE the signer is the wallet it self signer = nil } diff --git a/src/models/walletsModel.go b/src/models/walletsModel.go index 798f2c15..65ca9748 100644 --- a/src/models/walletsModel.go +++ b/src/models/walletsModel.go @@ -217,8 +217,6 @@ func (walletModel *WalletModel) data(index *core.QModelIndex, role int) *core.QV } return false } - // FIXME: consider a double checking here instead of hadHwConnected - // be careful this can have a big performance impact return core.NewQVariant1(valInSlice()) } case Expand: From 1051dfef4361ccb364681ab23c43636cef687390 Mon Sep 17 00:00:00 2001 From: Alvaro Denis Date: Mon, 9 Mar 2020 19:20:14 -0400 Subject: [PATCH 4/4] remove PersistibleSet ref #353 --- src/coin/mocks/PersistibleSet.go | 127 ------------------------------ src/coin/skycoin/models/wallet.go | 6 +- src/core/wallet.go | 5 -- src/models/walletsManager.go | 1 - 4 files changed, 1 insertion(+), 138 deletions(-) delete mode 100644 src/coin/mocks/PersistibleSet.go diff --git a/src/coin/mocks/PersistibleSet.go b/src/coin/mocks/PersistibleSet.go deleted file mode 100644 index 87125a38..00000000 --- a/src/coin/mocks/PersistibleSet.go +++ /dev/null @@ -1,127 +0,0 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. - -package mocks - -import core "github.com/fibercrypto/fibercryptowallet/src/core" -import mock "github.com/stretchr/testify/mock" - -// PersistibleSet is an autogenerated mock type for the PersistibleSet type -type PersistibleSet struct { - mock.Mock -} - -// CreateWallet provides a mock function with given fields: name, seed, walletType, isEncryptrd, pwd, scanAddressesN -func (_m *PersistibleSet) CreateWallet(name string, seed string, walletType string, isEncryptrd bool, pwd core.PasswordReader, scanAddressesN int) (core.Wallet, error) { - ret := _m.Called(name, seed, walletType, isEncryptrd, pwd, scanAddressesN) - - var r0 core.Wallet - if rf, ok := ret.Get(0).(func(string, string, string, bool, core.PasswordReader, int) core.Wallet); ok { - r0 = rf(name, seed, walletType, isEncryptrd, pwd, scanAddressesN) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(core.Wallet) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func(string, string, string, bool, core.PasswordReader, int) error); ok { - r1 = rf(name, seed, walletType, isEncryptrd, pwd, scanAddressesN) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// Decrypt provides a mock function with given fields: walletName, password -func (_m *PersistibleSet) Decrypt(walletName string, password core.PasswordReader) { - _m.Called(walletName, password) -} - -// DefaultWalletType provides a mock function with given fields: -func (_m *PersistibleSet) DefaultWalletType() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// Encrypt provides a mock function with given fields: walletName, password -func (_m *PersistibleSet) Encrypt(walletName string, password core.PasswordReader) { - _m.Called(walletName, password) -} - -// GetWallet provides a mock function with given fields: id -func (_m *PersistibleSet) GetWallet(id string) core.Wallet { - ret := _m.Called(id) - - var r0 core.Wallet - if rf, ok := ret.Get(0).(func(string) core.Wallet); ok { - r0 = rf(id) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(core.Wallet) - } - } - - return r0 -} - -// IsEncrypted provides a mock function with given fields: walletName -func (_m *PersistibleSet) IsEncrypted(walletName string) (bool, error) { - ret := _m.Called(walletName) - - var r0 bool - if rf, ok := ret.Get(0).(func(string) bool); ok { - r0 = rf(walletName) - } else { - r0 = ret.Get(0).(bool) - } - - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(walletName) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// ListWallets provides a mock function with given fields: -func (_m *PersistibleSet) ListWallets() core.WalletIterator { - ret := _m.Called() - - var r0 core.WalletIterator - if rf, ok := ret.Get(0).(func() core.WalletIterator); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(core.WalletIterator) - } - } - - return r0 -} - -// SupportedWalletTypes provides a mock function with given fields: -func (_m *PersistibleSet) SupportedWalletTypes() []string { - ret := _m.Called() - - var r0 []string - if rf, ok := ret.Get(0).(func() []string); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) - } - } - - return r0 -} diff --git a/src/coin/skycoin/models/wallet.go b/src/coin/skycoin/models/wallet.go index df8d106f..386c534d 100644 --- a/src/coin/skycoin/models/wallet.go +++ b/src/coin/skycoin/models/wallet.go @@ -825,11 +825,7 @@ func NewWalletDirectory(dirPath string) *WalletDirectory { type WalletDirectory struct { // Implements WallentEnv interface WalletDir string - wltService core.PersistibleSet -} - -func (wd *WalletDirectory) SetWltService(wltSrv core.PersistibleSet) { - wd.wltService = wltSrv + wltService *SkycoinLocalWallet } func lookupWallet(env core.WalletEnv, firstAddr string) (core.Wallet, error) { diff --git a/src/core/wallet.go b/src/core/wallet.go index 1f5a94d7..518dc0b5 100644 --- a/src/core/wallet.go +++ b/src/core/wallet.go @@ -24,11 +24,6 @@ type WalletSet interface { SupportedWalletTypes() []string } -type PersistibleSet interface { - WalletSet - WalletStorage -} - // WalletStorage provides access to the underlying wallets data store type WalletStorage interface { // Encrypt protects wallet data using cryptography diff --git a/src/models/walletsManager.go b/src/models/walletsManager.go index 83ca2e64..90d4e27c 100644 --- a/src/models/walletsManager.go +++ b/src/models/walletsManager.go @@ -799,7 +799,6 @@ func (walletM *WalletManager) sendTo(wltId, destinationAddress, amount string) * } logWalletManager.Info("Transaction created") return qTxn - } func (walletM *WalletManager) signTxn(wltIds, address []string, source string, tmpPwd interface{}, index []int, qTxn *QTransaction) *QTransaction {