Skip to content

Commit

Permalink
Merge pull request #54 from XDagger/develop
Browse files Browse the repository at this point in the history
add password confirm when show or export memonic
  • Loading branch information
swordlet authored Apr 8, 2023
2 parents 4d4d74b + 770b70b commit 24a2111
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 81 deletions.
80 changes: 53 additions & 27 deletions wallet/components/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,42 +51,47 @@ func AccountPage(address, balance string, w fyne.Window) *fyne.Container {
})
displayBtn := widget.NewButtonWithIcon(i18n.GetString("Display_Mnemonic"), theme.FileIcon(),
func() {
dialog.ShowCustom(i18n.GetString("Common_MessageTitle"), i18n.GetString("Common_Cancel"),
formatMnemonic(BipWallet.GetMnemonic()), w)
showPwdConfirm(w, func() {
dialog.ShowCustom(i18n.GetString("Common_MessageTitle"), i18n.GetString("Common_Cancel"),
formatMnemonic(BipWallet.GetMnemonic()), w)
})

})
displayBtn.Importance = widget.MediumImportance
exportBtn := widget.NewButtonWithIcon(i18n.GetString("Wallet_Export"), theme.FileIcon(),
func() {
dlgSave := dialog.NewFileSave(
func(uri fyne.URIWriteCloser, err error) {
defer func() {
w.Resize(fyne.NewSize(640, 480))
}()
if uri == nil || err != nil {
return
}
defer uri.Close()
if BipWallet.GetMnemonic() != "" {
_, err = io.WriteString(uri, BipWallet.GetMnemonic())
if err != nil {
xlog.Error(err)
showPwdConfirm(w, func() {
dlgSave := dialog.NewFileSave(
func(uri fyne.URIWriteCloser, err error) {
defer func() {
w.Resize(fyne.NewSize(640, 480))
}()
if uri == nil || err != nil {
return
}
defer uri.Close()
if BipWallet.GetMnemonic() != "" {
_, err = io.WriteString(uri, BipWallet.GetMnemonic())
if err != nil {
xlog.Error(err)
dialog.ShowInformation(i18n.GetString("Common_MessageTitle"),
i18n.GetString("WalletExport_File_Failed"), w)
return
}
} else {
xlog.Error("mnemonic is empty")
dialog.ShowInformation(i18n.GetString("Common_MessageTitle"),
i18n.GetString("WalletExport_File_Failed"), w)
return
}
} else {
xlog.Error("mnemonic is empty")
dialog.ShowInformation(i18n.GetString("Common_MessageTitle"),
i18n.GetString("WalletExport_File_Failed"), w)
return
}
dialog.ShowInformation(i18n.GetString("Common_MessageTitle"),
i18n.GetString("WalletExport_File_Success"), w)
}, w)
w.Resize(fyne.NewSize(800, 500))
dlgSave.Resize(fyne.NewSize(800, 500))
dlgSave.SetFileName("mnemonic-" + address[:6] + ".txt")
dlgSave.Show()
i18n.GetString("WalletExport_File_Success"), w)
}, w)
w.Resize(fyne.NewSize(800, 500))
dlgSave.Resize(fyne.NewSize(800, 500))
dlgSave.SetFileName("mnemonic-" + address[:6] + ".txt")
dlgSave.Show()
})
})
exportBtn.Importance = widget.HighImportance

Expand Down Expand Up @@ -137,3 +142,24 @@ func formatMnemonic(m string) fyne.CanvasObject {
}
return c
}

func showPwdConfirm(parent fyne.Window, f func()) {
wgt := widget.NewEntry()
wgt.Password = true

dialog.ShowCustomConfirm(
i18n.GetString("PasswordWindow_InputPassword"),
i18n.GetString("Common_Confirm"),
i18n.GetString("Common_Cancel"),
wgt, func(b bool) {
if b {
str := wgt.Text
if PwdStr == str {
f()
} else {
dialog.ShowInformation(i18n.GetString("Common_MessageTitle"),
i18n.GetString("Message_PasswordIncorrect"), parent)
}
}
}, parent)
}
49 changes: 25 additions & 24 deletions wallet/components/donate.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,33 @@ func DonatePage(w fyne.Window) *fyne.Container {

btn := widget.NewButtonWithIcon(i18n.GetString("WalletWindow_TabDonate"), theme.ConfirmIcon(),
func() {
fromAccountPrivKey, fromAddress, fromValue := SelTransFromAddr()
if !checkInput(fromValue, DonaAddressEntry.Text, amount.Text, remark.Text, w) {
return
}
showPwdConfirm(w, func() {
fromAccountPrivKey, fromAddress, fromValue := SelTransFromAddr()
if !checkInput(fromValue, DonaAddressEntry.Text, amount.Text, remark.Text, fromAddress, w) {
return
}

message := fmt.Sprintf(i18n.GetString("TransferWindow_ConfirmTransfer"), amount.Text, DonaAddressEntry.Text)
//fmt.Println(message)
dialog.ShowConfirm(i18n.GetString("Common_ConfirmTitle"),
message, func(b bool) {
if b {
DonaTransProgressContainer.Show()
DonaTransBtnContainer.Hide()
TransProgressContainer.Show()
TransBtnContainer.Hide()
DonaTransStatus.Text = i18n.GetString("TransferWindow_CommittingTransaction")
TransStatus.Text = i18n.GetString("TransferWindow_CommittingTransaction")
err := TransferRpc(fromAddress, DonaAddressEntry.Text, amount.Text, remark.Text, fromAccountPrivKey)
if err == nil {
setTransferDone()
} else {
xlog.Error(err)
setTransferError(err.Error())
message := fmt.Sprintf(i18n.GetString("TransferWindow_ConfirmTransfer"), amount.Text, DonaAddressEntry.Text)
//fmt.Println(message)
dialog.ShowConfirm(i18n.GetString("Common_ConfirmTitle"),
message, func(b bool) {
if b {
DonaTransProgressContainer.Show()
DonaTransBtnContainer.Hide()
TransProgressContainer.Show()
TransBtnContainer.Hide()
DonaTransStatus.Text = i18n.GetString("TransferWindow_CommittingTransaction")
TransStatus.Text = i18n.GetString("TransferWindow_CommittingTransaction")
err := TransferRpc(fromAddress, DonaAddressEntry.Text, amount.Text, remark.Text, fromAccountPrivKey)
if err == nil {
setTransferDone()
} else {
xlog.Error(err)
setTransferError(err.Error())
}
}
}
}, w)

}, w)
})
})
btn.Importance = widget.HighImportance
DonaTransBtnContainer = container.New(layout.NewPaddedLayout(), btn)
Expand Down
8 changes: 6 additions & 2 deletions wallet/components/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,12 @@ func getUrl(apiUrl, address, query string, page int, body *[]byte) error {
var reader io.ReadCloser
switch resp.Header.Get("Content-Encoding") {
case "gzip":
reader, _ = gzip.NewReader(resp.Body)
defer reader.Close()
reader, err = gzip.NewReader(resp.Body)
if err == nil {
defer reader.Close()
} else {
return err
}
default:
reader = resp.Body
}
Expand Down
59 changes: 32 additions & 27 deletions wallet/components/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,34 +70,39 @@ func TransferPage(w fyne.Window) *fyne.Container {
//}
btn := widget.NewButtonWithIcon(i18n.GetString("TransferWindow_TransferTitle"), theme.ConfirmIcon(),
func() {
fromAccountPrivKey, fromAddress, fromValue := SelTransFromAddr()
showPwdConfirm(w, func() {

if !checkInput(fromValue, AddressEntry.Text, amount.Text, remark.Text, w) {
return
}
fromAccountPrivKey, fromAddress, fromValue := SelTransFromAddr()

message := fmt.Sprintf(i18n.GetString("TransferWindow_ConfirmTransfer"), amount.Text, AddressEntry.Text)
//fmt.Println(message)
dialog.ShowConfirm(i18n.GetString("Common_ConfirmTitle"),
message, func(b bool) {
if b {
TransProgressContainer.Show()
TransBtnContainer.Hide()
DonaTransProgressContainer.Show()
DonaTransBtnContainer.Hide()
TransStatus.Text = i18n.GetString("TransferWindow_CommittingTransaction")
DonaTransStatus.Text = i18n.GetString("TransferWindow_CommittingTransaction")
err := TransferRpc(fromAddress, AddressEntry.Text, amount.Text, remark.Text, fromAccountPrivKey)
if err == nil {
config.InsertAddress(AddressEntry.Text)
setTransferDone()
} else {
xlog.Error(err)
setTransferError(err.Error())
}
}
}, w)
if !checkInput(fromValue, AddressEntry.Text, amount.Text, remark.Text, fromAddress, w) {
return
}
if fromAddress == AddressEntry.Text {
return
}

message := fmt.Sprintf(i18n.GetString("TransferWindow_ConfirmTransfer"), amount.Text, AddressEntry.Text)
//fmt.Println(message)
dialog.ShowConfirm(i18n.GetString("Common_ConfirmTitle"),
message, func(b bool) {
if b {
TransProgressContainer.Show()
TransBtnContainer.Hide()
DonaTransProgressContainer.Show()
DonaTransBtnContainer.Hide()
TransStatus.Text = i18n.GetString("TransferWindow_CommittingTransaction")
DonaTransStatus.Text = i18n.GetString("TransferWindow_CommittingTransaction")
err := TransferRpc(fromAddress, AddressEntry.Text, amount.Text, remark.Text, fromAccountPrivKey)
if err == nil {
config.InsertAddress(AddressEntry.Text)
setTransferDone()
} else {
xlog.Error(err)
setTransferError(err.Error())
}
}
}, w)
})
})
btn.Importance = widget.HighImportance
TransBtnContainer = container.New(layout.NewPaddedLayout(), btn)
Expand Down Expand Up @@ -128,8 +133,8 @@ func TransferPage(w fyne.Window) *fyne.Container {
)
}

func checkInput(fromValue, toAddr, amount, remark string, window fyne.Window) bool {
if len(toAddr) == 0 || !ValidateBipAddress(toAddr) {
func checkInput(fromValue, toAddr, amount, remark, fromAddress string, window fyne.Window) bool {
if len(toAddr) == 0 || !ValidateBipAddress(toAddr) || fromAddress == toAddr {
dialog.ShowInformation(i18n.GetString("Common_MessageTitle"),
i18n.GetString("TransferWindow_AccountFormatError"), window)
return false
Expand Down
2 changes: 1 addition & 1 deletion wallet/wallet-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"pool_address": "https://mainnet-rpc.xdagj.org:10001",
"testnet_api_url": ""
},
"version": "0.6.0",
"version": "0.6.1",
"culture_info": "en-US",
"addresses": [],
"query": {
Expand Down

0 comments on commit 24a2111

Please sign in to comment.