Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
handle xswd disconnect before accepting
Browse files Browse the repository at this point in the history
  • Loading branch information
g45t345rt committed Mar 11, 2024
1 parent cacb27f commit 7e203ef
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
16 changes: 10 additions & 6 deletions containers/confirm_modal/confirm_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,21 @@ func (c *ConfirmModal) Open(confirmText ConfirmText) chan bool {
return c.resChan
}

func (c *ConfirmModal) Layout(gtx layout.Context, th *material.Theme) layout.Dimensions {
if c.buttonYes.Clicked(gtx) {
c.resChan <- true
func (c *ConfirmModal) Close(yes bool) {
if c.Modal.Visible {
c.resChan <- yes
c.Modal.SetVisible(false)
close(c.resChan)
}
}

func (c *ConfirmModal) Layout(gtx layout.Context, th *material.Theme) layout.Dimensions {
if c.buttonYes.Clicked(gtx) {
c.Close(true)
}

if c.buttonNo.Clicked(gtx) {
c.resChan <- false
c.Modal.SetVisible(false)
close(c.resChan)
c.Close(false)
}

var lblSize layout.Dimensions
Expand Down
21 changes: 14 additions & 7 deletions pages/wallet/page.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package page_wallet

import (
"fmt"
"image"
"image/color"
"strings"
Expand Down Expand Up @@ -320,25 +319,31 @@ func (p *Page) OpenXSWD() error {
Prompt: prompt,
})

go func() {
<-appData.OnClose
confirm_modal.Instance.Close(false)
}()

w.Invalidate()
yes := <-yesChan
go func() {
time.Sleep(100 * time.Millisecond)

time.AfterFunc(500*time.Millisecond, func() {
page_instance.pageXSWDManage.Load()
w.Invalidate()
}()
})

return yes
}

reqHandler := func(appData *xswd.ApplicationData, req *jrpc2.Request) (xswd.Permission, interface{}, error) {
fmt.Println(req.Method(), req.ParamString())
// fmt.Println(req.Method(), req.ParamString())

txt := lang.Translate("An app is requesting access for {}.")
txt = strings.Replace(txt, "{}", req.Method(), -1)
notify.Push("XSWD", txt)

switch req.Method() {
case "transfer":
notify.Push("XSWD", txt) // notify only for transfer or sc_invoke

var params rpc.Transfer_Params
err := req.UnmarshalParams(&params)
if err != nil {
Expand All @@ -362,6 +367,8 @@ func (p *Page) OpenXSWD() error {
res := <-transferResponse
return xswd.Allow, res.Result, res.Err
case "sc_invoke":
notify.Push("XSWD", txt)

var params rpc.SC_Invoke_Params
err := req.UnmarshalParams(&params)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions pages/wallet/xswd_manage.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"gioui.org/widget"
"gioui.org/widget/material"
"github.com/deroproject/derohe/walletapi/xswd"
"github.com/g45t345rt/g45w/app_instance"
"github.com/g45t345rt/g45w/components"
"github.com/g45t345rt/g45w/containers/notification_modal"
"github.com/g45t345rt/g45w/lang"
Expand Down Expand Up @@ -120,6 +121,8 @@ func (p *PageXSWDManage) Load() {
p.apps = append(p.apps, NewDAppItem(app))
}
}

app_instance.Window.Invalidate()
}

func (p *PageXSWDManage) Leave() {
Expand Down

0 comments on commit 7e203ef

Please sign in to comment.