Skip to content

Commit

Permalink
integrate custom input reader into qml implementation ref #255
Browse files Browse the repository at this point in the history
  • Loading branch information
stdevAlDen committed Jan 22, 2020
1 parent f3f29e3 commit cf25102
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/models/bridgeModel.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package models

import (
"errors"
"github.com/fibercrypto/skywallet-go/src/skywallet"
"sync"

"github.com/therecipe/qt/core"
Expand Down Expand Up @@ -61,7 +61,8 @@ func (b *QBridge) getResult() string {

func (b *QBridge) getOptionalResult() (string, error) {
if len(b.ErrMessage()) > 0 {
return "", errors.New(b.ErrMessage())
logWalletsModel.Warningln(b.ErrMessage())
return "", skywallet.ErrUserCancelledFromInputReader
}
return b.result, nil
}
Expand Down
9 changes: 8 additions & 1 deletion src/models/device_interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package models

import (
hardware "github.com/fibercrypto/fibercryptowallet/src/contrib/hardware-wallet/skywallet"
"github.com/fibercrypto/skywallet-go/src/skywallet"
messages "github.com/fibercrypto/skywallet-protob/go"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/qml"
Expand Down Expand Up @@ -63,7 +64,13 @@ func (devI *QDeviceInteraction) changePin() {
devI.OperationDone()
return data
}).Catch(func(err error) error {
logWalletsModel.WithError(err).Errorln("unable to change pin")
if err == skywallet.ErrUserCancelledFromInputReader {
logWalletsModel.WithError(err).Infoln("unable to change pin")
} else if err == skywallet.ErrUserCancelledWithDeviceButton {
logWalletsModel.WithError(err).Warningln("unable to change pin")
} else {
logWalletsModel.WithError(err).Errorln("unable to change pin")
}
devI.OperationDone()
return err
})
Expand Down
4 changes: 2 additions & 2 deletions src/models/walletsModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func createSkyHardwareWallet(bridgeForPassword *QBridge) {
pass, err := bridgeForPassword.getOptionalResult()
bridgeForPassword.unlock()
if err != nil {
logWalletsModel.WithError(err).Errorln("error handling user interaction")
logWalletsModel.WithError(err).Warningln("error handling user interaction")
return "", skyWallet.ErrUserCancelledFromInputReader
}
return pass, nil
Expand Down Expand Up @@ -389,4 +389,4 @@ func (walletModel *WalletModel) loadModel(wallets []*QWallet) {

walletModel.EndResetModel()
walletModel.SetCount(len(walletModel.Wallets()))
}
}
9 changes: 8 additions & 1 deletion src/ui/Dialogs/NumPadDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Dialog {
readonly property string numPadButtonText: "#"
readonly property real numPadButtonImplicitSize: 50
readonly property real numPadButtonPointSize: 18
property alias pin: textInput.text

function clear(newTitle) {
textInput.clear()
Expand All @@ -44,6 +43,14 @@ Dialog {
onAboutToShow: {
textInput.forceActiveFocus()
}
onRejected: {
bridgeForPassword.errMessage = "Action canceled";
bridgeForPassword.unlock()
}
onAccepted: {
bridgeForPassword.setResult(textInput.text)
bridgeForPassword.unlock()
}

Flickable {
id: flickable
Expand Down
42 changes: 39 additions & 3 deletions src/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Qt.labs.settings 1.0
import WalletsManager 1.0
import Config 1.0
import Utils 1.0
import DeviceInteraction 1.0

// Resource imports
// import "qrc:/ui/src/ui/Dialogs"
Expand Down Expand Up @@ -152,6 +153,30 @@ ApplicationWindow {
+ "eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, "
+ "sunt in culpa qui officia deserunt mollit anim id est laborum.")
}
MsgDialog {
id: requestCancel
anchors.centerIn: Overlay.overlay
width: applicationWindow.width > 440 ? 440 - 40 : applicationWindow.width - 40
height: applicationWindow.height > 280 ? 280 - 40 : applicationWindow.height - 40
focus: true
modal: true
standardButtons: Dialog.Cancel
onRejected: {
deviceInteraction.cancelCommand()
}
}
MsgDialog {
id: requestConfirmation
anchors.centerIn: Overlay.overlay
width: applicationWindow.width > 440 ? 440 - 40 : applicationWindow.width - 40
height: applicationWindow.height > 280 ? 280 - 40 : applicationWindow.height - 40
focus: true
modal: true
standardButtons: Dialog.Ok | Dialog.Cancel
onRejected: {
deviceInteraction.cancelCommand()
}
}

// QR
DialogQR {
Expand All @@ -176,6 +201,9 @@ ApplicationWindow {
modal: true
}

DeviceInteraction {
id: deviceInteraction
}
QBridge{
id: bridgeForPassword

Expand All @@ -189,7 +217,16 @@ ApplicationWindow {
msgDialog.text = message
msgDialog.open()
}

onDeviceRequireConfirmableAction: {
requestConfirmation.title = title
requestConfirmation.text = message
requestConfirmation.open()
}
onDeviceRequireCancelableAction: {
requestCancel.title = title
requestCancel.text = message
requestCancel.open()
}
onGetSkyHardwareWalletPin: {
numPadDialog.clear(title)
numPadDialog.open()
Expand Down Expand Up @@ -223,8 +260,7 @@ ApplicationWindow {
focus: true
modal: true
onClosed: {
bridgeForPassword.setResult(numPadDialog.pin)
bridgeForPassword.unlock()
msgDialog.close()
}
}

Expand Down

0 comments on commit cf25102

Please sign in to comment.