Skip to content

Commit

Permalink
finish welcome screen
Browse files Browse the repository at this point in the history
- users can now generate new accounts
- users can import nsec
- users can import private hex key
- users can import mnemonic (also with password)
  • Loading branch information
prolic committed Aug 12, 2024
1 parent ecb6687 commit 6ac604b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 37 deletions.
1 change: 0 additions & 1 deletion resources/qml/content/App.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ ApplicationWindow {
}

ErrorScreen {
id: errorScreen
visible: errorMsg != ""
}

Expand Down
29 changes: 10 additions & 19 deletions resources/qml/content/WelcomeScreen.ui.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ Rectangle {
Rectangle {
width: parent.parent.width - 20
height: 80
color: "#f0f0f0" // Light grey background
border.color: "#e0e0e0" // Slightly darker grey for border
color: "#f0f0f0"
border.color: "#e0e0e0"
border.width: 2
anchors.margins: 10

radius: 10 // Rounded corners
radius: 10

Column {
width: parent.width
Expand Down Expand Up @@ -62,10 +62,10 @@ Rectangle {
Rectangle {
width: parent.parent.width * 0.6 - 15
height: 400
color: "#f0f0f0" // Light grey background
border.color: "#e0e0e0" // Slightly darker grey for border
color: "#f0f0f0"
border.color: "#e0e0e0"
border.width: 2
radius: 10 // Rounded corners
radius: 10

ColumnLayout {
anchors.fill: parent
Expand Down Expand Up @@ -151,7 +151,7 @@ Rectangle {
if (radionsec.checked) {
importSecretKey(secretkey.text)
} else if (radioseedphrase.checked) {
importSeedPhrase(seedphrase.text,
importSeedphrase(seedphrase.text,
password.text)
}
}
Expand All @@ -163,10 +163,10 @@ Rectangle {
Rectangle {
width: parent.parent.width * 0.4 - 15
height: 400
color: "#f0f0f0" // Light grey background
border.color: "#e0e0e0" // Slightly darker grey for border
color: "#f0f0f0"
border.color: "#e0e0e0"
border.width: 2
radius: 10 // Rounded corners
radius: 10

ColumnLayout {
anchors.fill: parent
Expand Down Expand Up @@ -212,12 +212,3 @@ Rectangle {
}
}
}

/*##^##
Designer {
D{i:0;formeditorZoom:0.5}D{i:5}D{i:6}D{i:4}D{i:3}D{i:2}D{i:10}D{i:11}D{i:12}D{i:14}
D{i:15}D{i:13}D{i:16}D{i:17}D{i:18}D{i:19}D{i:20}D{i:9}D{i:8}D{i:23}D{i:24}D{i:25}
D{i:26}D{i:27}D{i:22}D{i:21}D{i:7}D{i:1}
}
##^##*/

42 changes: 25 additions & 17 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ type ModelVar = MVar AppModel

createContext :: ModelVar -> SignalKey (IO ()) -> IO (ObjRef ())
createContext modelVar changeKey = do
let handleError :: ObjRef() -> String -> IO ()
handleError obj err = do
model <- takeMVar modelVar
putMVar modelVar model { errorMsg = pack err }
fireSignal changeKey obj

rootClass <- newClass [
defPropertySigRW' "seedphrase" changeKey
(\_ -> do
Expand Down Expand Up @@ -82,9 +88,7 @@ createContext modelVar changeKey = do
(\_ -> do
model <- readMVar modelVar
return $ errorMsg model)
(\obj newErrorMsg -> do
modifyMVar_ modelVar $ \model -> return model { errorMsg = newErrorMsg }
fireSignal changeKey obj),
(\obj newErrorMsg -> handleError obj $ unpack newErrorMsg),

defMethod' "importSecretKey" $ \this (input :: Text) -> do
mkp <- importSecretKey input
Expand All @@ -93,28 +97,33 @@ createContext modelVar changeKey = do
model <- takeMVar modelVar
putMVar modelVar model { keyPair = mkp, currentScreen = HomeScreen }
fireSignal changeKey this
Nothing -> do
model <- takeMVar modelVar
putMVar modelVar model { errorMsg = "Error: Importing secret key failed" }
fireSignal changeKey this,
Nothing -> handleError this "Error: Importing secret key failed",

defMethod' "generateSeedphrase" $ \this -> do
let handleError :: String -> IO ()
handleError err = do
model <- takeMVar modelVar
putMVar modelVar model { errorMsg = "Error: " <> pack err }
fireSignal changeKey this
defMethod' "importSeedphrase" $ \this input pwd -> do
mkp <- mnemonicToKeyPair input pwd
case mkp of
Right kp -> do
let secKey = keyPairToSecKey kp
importSecretKey (secKeyToBech32 secKey) >>= \mkp' ->
case mkp' of
Just _ -> do
model <- takeMVar modelVar
putMVar modelVar model { keyPair = mkp', currentScreen = HomeScreen }
fireSignal changeKey this
Nothing -> handleError this "Unknown error generating new keys"
Left err -> handleError this err,

createMnemonic >>= either handleError (\m' -> do
mnemonicToKeyPair m' "" >>= either handleError (\mkp' -> do
defMethod' "generateSeedphrase" $ \this -> do
createMnemonic >>= either (handleError this) (\m' -> do
mnemonicToKeyPair m' "" >>= either (handleError this) (\mkp' -> do
let secKey = keyPairToSecKey mkp'
importSecretKey (secKeyToBech32 secKey) >>= \mkp ->
case mkp of
Just _ -> do
model <- takeMVar modelVar
putMVar modelVar model { seedphrase = m', keyPair = mkp }
fireSignal changeKey this
Nothing -> handleError "Unknown error generating new keys"
Nothing -> handleError this "Unknown error generating new keys"
)
)

Expand All @@ -123,7 +132,6 @@ createContext modelVar changeKey = do
newObject rootClass ()



importSecretKey :: Text -> IO (Maybe KeyPair)
importSecretKey input = do
let skMaybe = if "nsec" `isPrefixOf` input
Expand Down

0 comments on commit 6ac604b

Please sign in to comment.