Skip to content

Commit f32a60e

Browse files
authored
Merge pull request #44 from Beldex-Coin/dev
Dev to master
2 parents e703f63 + 5beeb18 commit f32a60e

8 files changed

Lines changed: 663 additions & 193 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "beldex-electron-wallet",
3-
"version": "6.0.0",
3+
"version": "6.0.1",
44
"description": "Modern GUI interface for Beldex Currency",
55
"productName": "Beldex Electron Wallet",
66
"repository": {

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

Lines changed: 109 additions & 5 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
};
@@ -709,9 +725,12 @@ export class WalletRPC {
709725
return;
710726
}
711727

712-
let refresh_start_height = refresh_start_timestamp_or_height;
728+
let refresh_start_height = Number.parseInt(
729+
refresh_start_timestamp_or_height
730+
);
713731

714-
if (!Number.isInteger(refresh_start_height)) {
732+
// if the height can't be parsed just start from block 0
733+
if (!refresh_start_height) {
715734
refresh_start_height = 0;
716735
}
717736

@@ -738,6 +757,74 @@ export class WalletRPC {
738757
});
739758
}
740759

760+
restoreWalletWithKeys(
761+
filename,
762+
password,
763+
address,
764+
viewkey,
765+
spendkey,
766+
refresh_type,
767+
refresh_start_timestamp_or_height
768+
) {
769+
if (refresh_type == "date") {
770+
// Convert timestamp to 00:00 and move back a day
771+
// Core code also moved back some amount of blocks
772+
let timestamp = refresh_start_timestamp_or_height;
773+
timestamp = timestamp - (timestamp % 86400000) - 86400000;
774+
775+
this.backend.daemon.timestampToHeight(timestamp).then(height => {
776+
if (height === false) {
777+
this.sendGateway("set_wallet_error", {
778+
status: {
779+
code: -1,
780+
i18n: "notification.errors.invalidRestoreDate"
781+
}
782+
});
783+
} else {
784+
this.restoreWalletWithKeys(
785+
filename,
786+
password,
787+
address,
788+
viewkey,
789+
spendkey,
790+
"height",
791+
height
792+
);
793+
}
794+
});
795+
return;
796+
}
797+
798+
let restore_height = Number.parseInt(refresh_start_timestamp_or_height);
799+
800+
// if the height can't be parsed just start from block 0
801+
if (!restore_height) {
802+
restore_height = 0;
803+
}
804+
this.sendRPC("generate_from_keys", {
805+
filename,
806+
password,
807+
address,
808+
viewkey,
809+
spendkey,
810+
restore_height
811+
}).then(data => {
812+
if (data.hasOwnProperty("error")) {
813+
this.sendGateway("set_wallet_error", { status: data.error });
814+
return;
815+
}
816+
817+
// store hash of the password so we can check against it later when requesting private keys, or for sending txs
818+
this.wallet_state.password_hash = crypto
819+
.pbkdf2Sync(password, this.auth[2], 1000, 64, "sha512")
820+
.toString("hex");
821+
this.wallet_state.name = filename;
822+
this.wallet_state.open = true;
823+
824+
this.finalizeNewWallet(filename);
825+
});
826+
}
827+
741828
importWallet(wallet_name, password, import_path) {
742829
// Reset the status error
743830
this.sendGateway("reset_wallet_error");
@@ -851,6 +938,12 @@ export class WalletRPC {
851938
};
852939
for (let n of data) {
853940
if (n.hasOwnProperty("error") || !n.hasOwnProperty("result")) {
941+
if (n.params.key_type == "spend_key") {
942+
if (n.error?.code == -29) {
943+
wallet.info.view_only = true;
944+
this.wallet_state.view_only = true;
945+
}
946+
}
854947
continue;
855948
}
856949
if (n.method == "get_address") {
@@ -865,6 +958,7 @@ export class WalletRPC {
865958
if (n.params.key_type == "spend_key") {
866959
if (/^0*$/.test(n.result.key)) {
867960
wallet.info.view_only = true;
961+
this.wallet_state.view_only = true;
868962
}
869963
}
870964
}
@@ -930,6 +1024,17 @@ export class WalletRPC {
9301024
// Check if we have a view only wallet by querying the spend key
9311025
this.sendRPC("query_key", { key_type: "spend_key" }).then(data => {
9321026
if (data.hasOwnProperty("error") || !data.hasOwnProperty("result")) {
1027+
if (data.params.key_type == "spend_key") {
1028+
if (data.error?.code == -29) {
1029+
// wallet.info.view_only = true;
1030+
this.wallet_state.view_only = true;
1031+
this.sendGateway("set_wallet_data", {
1032+
info: {
1033+
view_only: true
1034+
}
1035+
});
1036+
}
1037+
}
9331038
return;
9341039
}
9351040
if (/^0*$/.test(data.result.key)) {
@@ -2475,7 +2580,6 @@ export class WalletRPC {
24752580
}
24762581

24772582
deregisterImages(password) {
2478-
console.log("deregister_images.....wallet-rpc");
24792583
crypto.pbkdf2(
24802584
password,
24812585
this.auth[2],

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)