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 this.showChecking = true
try { try {
if (!this.serialSignerRef.isConnected()) { if (!this.serialSignerRef.isConnected()) {
await this.serialSignerRef.openSerialPort() const portOpen = await this.serialSignerRef.openSerialPort()
if (!portOpen) return
} }
if (!this.serialSignerRef.isAuthenticated()) { if (!this.serialSignerRef.isAuthenticated()) {
await this.serialSignerRef.hwwShowPasswordDialog() await this.serialSignerRef.hwwShowPasswordDialog()

View file

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

View file

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