Skip to content

Commit

Permalink
chore: 👷 clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
gamalielhere committed Sep 24, 2021
1 parent dde786c commit 46d31dc
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 53 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 57 additions & 5 deletions src/modules/access-wallet/ModuleAccessWalletHardware.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@
:set-path="setPath"
:hw-wallet-instance="hwWalletInstance"
:unlock="bitbox02Unlock"
:device-not-paired="bitBox2NotPaired"
:device-connected="bitBox2Connected"
:device-unpaired="bitBox2Unpaired"
:device-pairing-code="bitBox2PairingCode"
:device-confirmed="bitBox2Confirmed"
:device-initialized="bitBox2Initialized"
/>
<!--
=====================================================================================
Expand Down Expand Up @@ -471,6 +477,44 @@ export default {
} else if (this.step === 1) {
return 'Select a hardware wallet';
}
if (this.onBitbox2) return this.bitbox2Titles;
return this.wallets[this.walletType].title;
},
bitBox2NotPaired() {
return (
_.isEmpty(this.hwWalletInstance) ||
(!_.isEmpty(this.hwWalletInstance) && !this.hwWalletInstance?.status)
);
},
bitBox2Connected() {
return (
!this.bitBox2NotPaired && this.hwWalletInstance?.status === 'connected'
);
},
bitBox2Unpaired() {
return (
!this.bitBox2NotPaired && this.hwWalletInstance?.status === 'unpaired'
);
},
bitBox2Initialized() {
return (
!this.bitBox2NotPaired &&
this.hwWalletInstance?.status === 'initialized'
);
},
bitBox2PairingCode() {
return !this.bitBox2NotPaired ? this.hwWalletInstance?.pairingCode : '';
},
bitBox2Confirmed() {
return !this.bitBox2NotPaired
? this.hwWalletInstance?.pairingConfirmed
: false;
},
bitbox2Titles() {
if (this.bitBox2Connected) return 'Enter Bitbox 02 password';
if (this.bitBox2Unpaired) return 'Confirm pairing code';
if (this.bitBox2Initialized)
return 'Bitbox 02 succesfully initialized. Loading wallet';
return this.wallets[this.walletType].title;
}
},
Expand Down Expand Up @@ -561,12 +605,20 @@ export default {
this.loaded = true;
this.hwWalletInstance = _hwWallet;
if (this.onLedger) this.ledgerConnected = true;
if (this.onKeepkey || this.onKeepkey) this.step++;
if (this.onKeepkey || this.onTrezor) this.step++;
if (this.onBitbox2) {
_hwWallet.init(this.hasPath).then(() => {
this.hwWalletInstance = _hwWallet;
this.nextStep();
});
_hwWallet
.init(this.hasPath)
.then(() => {
this.nextStep();
this.hwWalletInstance = _hwWallet;
})
.catch(e => {
this.wallets[this.walletType].create.errorHandler(e);
if (e.message === 'Error: Pairing rejected') {
this.reset();
}
});
}
return _hwWallet;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
Terms
=====================================================================================
-->
<div class="d-flex align-center flex-column pt-3">
<div class="d-flex align-center flex-column py-6">
<mew-checkbox
v-model="acceptTerms"
label="To access my wallet, I accept "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@
<div>
<v-row v-if="deviceNotPaired" no-gutters class="pt-4">
<v-col cols="12" justify="center" align="center" class="py-5">
<img :src="imgPath" width="60%" />
</v-col>
<v-col cols="12" justify="center" align="center">
<v-card-title class="border justify-center font-wrapping py-5 mb-8">
<div class="mew-heading-4 font-weight-medium pl-1">
Connect your Bitbox2 device
</div>
</v-card-title>
<img :src="lockedImg" width="100%" class="bitbox-img" />
</v-col>
<v-col cols="12" justify="center" align="center">
<mew-button
Expand All @@ -28,10 +21,18 @@
</v-col>
</v-row>

<v-row v-if="deviceInitialized" no-gutters class="pt-4">
<v-col cols="12" justify="center" align="center" class="py-5">
<img :src="openImg" width="100%" class="bitbox-img" />
</v-col>
<v-col cols="12" justify="center" align="center">
<v-card-title class="border justify-center font-wrapping py-5 mb-8">
<div class="mew-heading-4 font-weight-medium pl-1">Loading....</div>
</v-card-title>
</v-col>
</v-row>

<div v-if="deviceUnpaired">
<div class="mew-heading-2 pa-3 text-center">
Please verify pairing code
</div>
<div class="mew-body">
<pre class="text-center mew-heading-1">{{ devicePairingCode }}</pre>
</div>
Expand All @@ -50,8 +51,8 @@
</template>

<script>
import { _ } from 'web3-utils';
import gifPath from '@/assets/images/hardware-wallets/bb02-pw-entry.gif';
import bitbox2Locked from '@/assets/images/hardware-wallets/bitbox02-locked.png';
import bitbox2Welcome from '@/assets/images/hardware-wallets/bitbox02-welcome.png';
export default {
props: {
Expand All @@ -62,40 +63,39 @@ export default {
unlock: {
type: Function,
default: () => {}
},
deviceNotPaired: {
type: Boolean,
default: false
},
deviceConnected: {
type: Boolean,
default: false
},
deviceUnpaired: {
type: Boolean,
default: false
},
devicePairingCode: {
type: String,
default: ''
},
deviceConfirmed: {
type: Boolean,
default: false
},
deviceInitialized: {
type: Boolean,
default: false
}
},
data() {
return {
gifPath: gifPath,
imgPath: bitbox2Welcome
lockedImg: bitbox2Locked,
openImg: bitbox2Welcome
};
},
computed: {
deviceNotPaired() {
return (
_.isEmpty(this.hwWalletInstance) ||
(!_.isEmpty(this.hwWalletInstance) && !this.hwWalletInstance?.status)
);
},
deviceConnected() {
return (
!this.deviceNotPaired && this.hwWalletInstance?.status === 'connected'
);
},
deviceUnpaired() {
return (
!this.deviceNotPaired && this.hwWalletInstance?.status === 'unpaired'
);
},
devicePairingCode() {
return !this.deviceNotPaired ? this.hwWalletInstance?.pairingCode : '';
},
deviceConfirmed() {
return !this.deviceNotPaired
? this.hwWalletInstance?.pairingConfirmed
: false;
}
},
methods: {
resolvePairing() {
this.hwWalletInstance.pairingConfirmationResolve();
Expand All @@ -119,4 +119,8 @@ export default {
white-space: pre-wrap;
word-break: break-word;
}
.bitbox-img {
max-width: 340px;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,13 @@ class BitBox02Wallet {
};
}
async connect() {
try {
const devicePath = await getDevicePath();
this.BitBox02 = new BitBox02API(devicePath);
} catch (e) {
errorHandler(e);
}
const devicePath = await getDevicePath();
this.BitBox02 = new BitBox02API(devicePath);
}

async init(basePath) {
this.basePath = basePath ? basePath : this.supportedPaths[0].path;
try {
this.basePath = basePath ? basePath : this.supportedPaths[0].path;
await this.BitBox02.connect(
pairingCode => {
this.pairingCode = pairingCode;
Expand Down Expand Up @@ -77,7 +73,7 @@ class BitBox02Wallet {
errorHandler({ message: 'Attestation failed' });
}
} catch (e) {
errorHandler(e);
throw new Error(e);
}
}

Expand Down

0 comments on commit 46d31dc

Please sign in to comment.