fix: stop if serial port cannot be open

This commit is contained in:
Vlad Stan 2022-07-27 15:15:56 +03:00
parent 3054248858
commit d541bebf38
3 changed files with 8 additions and 10 deletions

View File

@ -83,7 +83,8 @@ async function payment(path) {
this.showChecking = true
try {
if (!this.serialSignerRef.isConnected()) {
await this.serialSignerRef.openSerialPort()
const portOpen = await this.serialSignerRef.openSerialPort()
if (!portOpen) return
}
if (!this.serialSignerRef.isAuthenticated()) {
await this.serialSignerRef.hwwShowPasswordDialog()

View File

@ -46,7 +46,7 @@
v-if="!selectedPort"
clickable
v-close-popup
@click="openSerialPort()"
@click="openSerialPort"
>
<q-item-section>
<q-item-label>Connect</q-item-label>

View File

@ -37,9 +37,9 @@ async function serialSigner(path) {
methods: {
openSerialPort: async function () {
if (!this.checkSerialPortSupported()) return
if (this.selectedPort) return
console.log('### openSerialPort', this.selectedPort)
if (!this.checkSerialPortSupported()) return false
if (this.selectedPort) return true
try {
navigator.serial.addEventListener('connect', event => {
console.log('### navigator.serial event: connected!', event)
@ -65,6 +65,7 @@ async function serialSigner(path) {
)
this.writer = textEncoder.writable.getWriter()
return true
} catch (error) {
this.selectedPort = null
this.$q.notify({
@ -73,6 +74,7 @@ async function serialSigner(path) {
caption: `${error}`,
timeout: 10000
})
return false
}
},
closeSerialPort: async function () {
@ -302,11 +304,6 @@ async function serialSigner(path) {
this.hww.psbtSent = false
this.hww.signingPsbt = true
await this.writer.write(COMMAND_SIGN_PSBT + '\n')
this.$q.notify({
type: 'positive',
message: 'PSBT signed!',
timeout: 5000
})
} catch (error) {
this.$q.notify({
type: 'warning',