Skip to content

Commit 807f858

Browse files
authored
Merge pull request #42 from Beldex-Coin/feature-keys-to-import-wallet
Feature keys to import wallet
2 parents f803718 + c6a7e9d commit 807f858

7 files changed

Lines changed: 665 additions & 189 deletions

File tree

src-electron/main-process/modules/wallet-rpc.js

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export class WalletRPC {
2727
password_hash: null,
2828
balance: null,
2929
unlocked_balance: null,
30-
bnsRecords: []
30+
bnsRecords: [],
31+
view_only: false
3132
};
3233
this.isRPCSyncing = false;
3334
this.dirs = null;
@@ -303,6 +304,21 @@ export class WalletRPC {
303304
);
304305
break;
305306

307+
case "restore_wallet_with_keys":
308+
// TODO: Decide if we want this for Beldex
309+
this.restoreWalletWithKeys(
310+
params.name,
311+
params.password,
312+
params.address,
313+
params.viewkey,
314+
params.spendkey,
315+
params.refresh_type,
316+
params.refresh_type == "date"
317+
? params.refresh_start_date
318+
: params.refresh_start_height
319+
);
320+
break;
321+
306322
case "import_wallet":
307323
this.importWallet(params.name, params.password, params.path);
308324
break;
@@ -505,7 +521,7 @@ export class WalletRPC {
505521
address: response.result.per_subaddress[0].address,
506522
balance: response.result.balance,
507523
unlocked_balance: response.result.unlocked_balance,
508-
view_only: false,
524+
view_only: this.wallet_state.view_only,
509525
load_balance: false
510526
}
511527
};
@@ -738,6 +754,73 @@ export class WalletRPC {
738754
});
739755
}
740756

757+
restoreWalletWithKeys(
758+
filename,
759+
password,
760+
address,
761+
viewkey,
762+
spendkey,
763+
refresh_type,
764+
refresh_start_timestamp_or_height
765+
) {
766+
if (refresh_type == "date") {
767+
// Convert timestamp to 00:00 and move back a day
768+
// Core code also moved back some amount of blocks
769+
let timestamp = refresh_start_timestamp_or_height;
770+
timestamp = timestamp - (timestamp % 86400000) - 86400000;
771+
772+
this.backend.daemon.timestampToHeight(timestamp).then(height => {
773+
if (height === false) {
774+
this.sendGateway("set_wallet_error", {
775+
status: {
776+
code: -1,
777+
i18n: "notification.errors.invalidRestoreDate"
778+
}
779+
});
780+
} else {
781+
this.restoreWalletWithKeys(
782+
filename,
783+
password,
784+
address,
785+
viewkey,
786+
spendkey,
787+
"height",
788+
height
789+
);
790+
}
791+
});
792+
return;
793+
}
794+
795+
let restore_height = refresh_start_timestamp_or_height;
796+
797+
if (!Number.isInteger(restore_height)) {
798+
restore_height = 0;
799+
}
800+
this.sendRPC("generate_from_keys", {
801+
filename,
802+
password,
803+
address,
804+
viewkey,
805+
spendkey,
806+
restore_height
807+
}).then(data => {
808+
if (data.hasOwnProperty("error")) {
809+
this.sendGateway("set_wallet_error", { status: data.error });
810+
return;
811+
}
812+
813+
// store hash of the password so we can check against it later when requesting private keys, or for sending txs
814+
this.wallet_state.password_hash = crypto
815+
.pbkdf2Sync(password, this.auth[2], 1000, 64, "sha512")
816+
.toString("hex");
817+
this.wallet_state.name = filename;
818+
this.wallet_state.open = true;
819+
820+
this.finalizeNewWallet(filename);
821+
});
822+
}
823+
741824
importWallet(wallet_name, password, import_path) {
742825
// Reset the status error
743826
this.sendGateway("reset_wallet_error");
@@ -851,6 +934,12 @@ export class WalletRPC {
851934
};
852935
for (let n of data) {
853936
if (n.hasOwnProperty("error") || !n.hasOwnProperty("result")) {
937+
if (n.params.key_type == "spend_key") {
938+
if (n.error?.code == -29) {
939+
wallet.info.view_only = true;
940+
this.wallet_state.view_only = true;
941+
}
942+
}
854943
continue;
855944
}
856945
if (n.method == "get_address") {
@@ -865,6 +954,7 @@ export class WalletRPC {
865954
if (n.params.key_type == "spend_key") {
866955
if (/^0*$/.test(n.result.key)) {
867956
wallet.info.view_only = true;
957+
this.wallet_state.view_only = true;
868958
}
869959
}
870960
}
@@ -930,6 +1020,17 @@ export class WalletRPC {
9301020
// Check if we have a view only wallet by querying the spend key
9311021
this.sendRPC("query_key", { key_type: "spend_key" }).then(data => {
9321022
if (data.hasOwnProperty("error") || !data.hasOwnProperty("result")) {
1023+
if (data.params.key_type == "spend_key") {
1024+
if (data.error?.code == -29) {
1025+
// wallet.info.view_only = true;
1026+
this.wallet_state.view_only = true;
1027+
this.sendGateway("set_wallet_data", {
1028+
info: {
1029+
view_only: true
1030+
}
1031+
});
1032+
}
1033+
}
9331034
return;
9341035
}
9351036
if (/^0*$/.test(data.result.key)) {

src/assets/images/viewOnlyMode.svg

Lines changed: 3 additions & 0 deletions
Loading

src/css/app.styl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,6 @@ h1, h2, h3, h4, h5, h6, img, .q-list-header, .q-header, .q-menu .q-item-label, .
10541054
background-color $beldex-lightgray
10551055
margin-top 50px
10561056
margin-bottom 20px
1057-
padding 20px 50px
10581057
border-radius 20px
10591058
box-shadow 0 6px 24px rgba(0, 0, 0, .2)
10601059
overflow-y auto

src/layouts/wallet/rightPane.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
<!-- <router-link to="/wallet/send"> -->
1818
<div :class="[this.routes === 'send' ? 'active' : '']">
1919
<!-- <q-btn class="large-btn send-btn" size="md" @click="router('send')"> -->
20-
<q-btn class="large-btn send-btn" @click="router('send')">
20+
<q-btn
21+
class="large-btn send-btn"
22+
:disable="view_only"
23+
@click="router('send')"
24+
>
2125
<!-- width="16"
2226
height="20" -->
2327
<svg
@@ -110,6 +114,7 @@ export default {
110114
},
111115
computed: mapState({
112116
info: state => state.gateway.wallet.info,
117+
view_only: state => state.gateway.wallet.info.view_only,
113118
routes: state => state.gateway.router_path_rightpane
114119
}),
115120
data() {

src/pages/wallet-select/created.vue

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -66,50 +66,52 @@
6666
</div>
6767
</div>
6868

69-
<div class="col wallet ">
70-
<h6 style="font-family: Poppins-Regular">
71-
<span
72-
class="ft-bold"
73-
style="color: white; font-size: 16px; margin-left: 20px"
74-
>{{ $t("strings.seedWords") }}</span
75-
>
76-
<span style="color: #00e509;font-size: 12px;">
77-
- {{ $t("strings.saveSeedWarning") }}</span
78-
>
79-
</h6>
80-
</div>
69+
<template v-if="secret.mnemonic.length > 0">
70+
<div class="col wallet ">
71+
<h6 style="font-family: Poppins-Regular">
72+
<span
73+
class="ft-bold"
74+
style="color: white; font-size: 16px; margin-left: 20px"
75+
>{{ $t("strings.seedWords") }}</span
76+
>
77+
<span style="color: #00e509;font-size: 12px;">
78+
- {{ $t("strings.saveSeedWarning") }}</span
79+
>
80+
</h6>
81+
</div>
8182

82-
<div
83-
class="row items-center"
84-
style="
83+
<div
84+
class="row items-center"
85+
style="
8586
border: 1px #484856 solid;
8687
border-radius: 12px;
8788
font-family: Poppins-Regular;
8889
padding: 10px 20px;
8990
margin-left: 20px;
9091
9192
"
92-
>
93-
<div class="col" style="color: white; padding: 0px 10px 0px 0px">
94-
{{ secret.mnemonic }}
95-
</div>
96-
<div class="q-item-side">
97-
<q-btn
98-
color="secondary"
99-
size="md"
100-
:label="this.$t('buttons.copy')"
101-
icon-right="content_copy"
102-
@click="copyPrivateKey('mnemonic', $event)"
103-
>
104-
<q-tooltip
105-
anchor="center left"
106-
self="center right"
107-
:offset="[5, 10]"
108-
>{{ $t("menuItems.copySeed") }}</q-tooltip
93+
>
94+
<div class="col" style="color: white; padding: 0px 10px 0px 0px">
95+
{{ secret.mnemonic }}
96+
</div>
97+
<div class="q-item-side">
98+
<q-btn
99+
color="secondary"
100+
size="md"
101+
:label="this.$t('buttons.copy')"
102+
icon-right="content_copy"
103+
@click="copyPrivateKey('mnemonic', $event)"
109104
>
110-
</q-btn>
105+
<q-tooltip
106+
anchor="center left"
107+
self="center right"
108+
:offset="[5, 10]"
109+
>{{ $t("menuItems.copySeed") }}</q-tooltip
110+
>
111+
</q-btn>
112+
</div>
111113
</div>
112-
</div>
114+
</template>
113115

114116
<div style="margin-top: 18px; padding: 10px 20px">
115117
<template v-if="secret.view_key != secret.spend_key">

0 commit comments

Comments
 (0)