Avoid creating wallets with the same name

This commit is contained in:
Rene Vergara 2024-02-28 16:37:43 -06:00
parent bb05d269ac
commit 0de5dc4f9c
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2
3 changed files with 21 additions and 10 deletions

View file

@ -212,9 +212,7 @@ appEvent (BT.VtyEvent e) = do
V.EvKey V.KEnter [] -> do
fs <- BT.zoom inputForm $ BT.gets formState
nw <- liftIO $ addNewWallet (fs ^. dialogInput) s
BT.modify $ set wallets nw
printMsg $
"Creating new wallet " <> T.unpack (fs ^. dialogInput)
BT.put nw
BT.modify $ set dialogBox Blank
ev -> BT.zoom inputForm $ handleFormEvent (BT.VtyEvent ev)
AName -> do
@ -311,12 +309,24 @@ runZenithCLI host port dbFilePath = do
"No Zebra node available on port " <>
show port <> ". Check your configuration"
addNewWallet ::
T.Text -> State -> IO (L.GenericList Name Vec.Vector (Entity ZcashWallet))
addNewWallet :: T.Text -> State -> IO State
addNewWallet n s = do
sP <- generateWalletSeedPhrase
let bH = s ^. startBlock
let netName = read $ s ^. network
_ <- saveWallet (s ^. dbPath) $ ZcashWallet sP bH n netName
r <- saveWallet (s ^. dbPath) $ ZcashWallet sP bH n netName
case r of
Nothing -> do
wL <- getWallets (s ^. dbPath) netName
return $ L.listReplace (Vec.fromList wL) (Just 0) $ s ^. wallets
return $
(s & wallets .~ L.listReplace (Vec.fromList wL) (Just 0) (s ^. wallets)) &
msg .~
"Wallet already exists: " ++
T.unpack n
Just _ -> do
wL <- getWallets (s ^. dbPath) netName
return $
(s & wallets .~ L.listReplace (Vec.fromList wL) (Just 0) (s ^. wallets)) &
msg .~
"Created new wallet: " ++
T.unpack n

View file

@ -24,8 +24,8 @@ initDb dbName = do
saveWallet ::
T.Text -- ^ The database path to use
-> ZcashWallet -- ^ The wallet to add to the database
-> IO ZcashWalletId
saveWallet dbFp w = runSqlite dbFp $ insert w
-> IO (Maybe (Entity ZcashWallet))
saveWallet dbFp w = runSqlite dbFp $ insertUniqueEntity w
-- | Returns a list of accounts associated with the given wallet
getAccounts ::

View file

@ -34,6 +34,7 @@ share
birthdayHeight Int
name T.Text
network ZcashNet
UniqueWallet name network
deriving Show
ZcashAccount
walletId ZcashWalletId