only send insert card error if not found in 150ms

This commit is contained in:
Michele Balistreri 2022-08-29 14:03:15 +02:00
parent 33e7ae0fe0
commit c8b38fe24a

10
flow.go
View File

@ -2,6 +2,7 @@ package statuskeycardgo
import (
"errors"
"time"
"github.com/status-im/status-keycard-go/signal"
)
@ -186,7 +187,9 @@ func (f *KeycardFlow) connect() (*keycardContext, error) {
return nil, errors.New(ErrorConnection)
}
f.pause(InsertCard, ErrorConnection, FlowParams{})
t := time.NewTimer(150 * time.Millisecond)
for {
select {
case <-f.wakeUp:
if f.state != Cancelling {
@ -197,10 +200,13 @@ func (f *KeycardFlow) connect() (*keycardContext, error) {
if kc.runErr != nil {
return nil, restartErr()
}
t.Stop()
f.state = Running
signal.Send(CardInserted, FlowStatus{})
return kc, nil
case <-t.C:
f.pause(InsertCard, ErrorConnection, FlowParams{})
}
}
}