oxen-electron-gui-wallet/src/components/service_node/service_node_unlock.vue

258 lines
7.6 KiB
Vue
Raw Normal View History

<template>
2020-09-08 04:59:49 +02:00
<div class="service-node-stake-tab">
<div class="q-pa-md">
2020-03-03 04:16:23 +01:00
<div class="q-pb-sm header">
<span v-if="service_nodes.length">
2020-09-08 04:59:49 +02:00
{{ $t("titles.currentlyStakedNodes") }}
</span>
<span v-else>{{
$t("strings.serviceNodeStartStakingDescription")
}}</span>
2020-03-03 04:16:23 +01:00
</div>
2020-09-08 04:59:49 +02:00
<div v-if="service_nodes">
<ServiceNodeList
:service-nodes="service_nodes"
button-i18n="buttons.unlock"
:details="details"
:action="unlockWarning"
/>
</div>
<q-inner-loading
:showing="unlock_status.sending || fetching"
:dark="theme == 'dark'"
>
2020-09-08 04:59:49 +02:00
<q-spinner color="primary" size="30" />
</q-inner-loading>
<ServiceNodeDetails
ref="serviceNodeDetailsUnlock"
:action="unlockWarning"
action-i18n="buttons.unlock"
/>
</div>
2020-03-03 04:16:23 +01:00
</div>
</template>
<script>
2020-03-03 04:16:23 +01:00
import { clipboard } from "electron";
import { mapState } from "vuex";
import { required } from "vuelidate/lib/validators";
import { service_node_key } from "src/validators/common";
import WalletPassword from "src/mixins/wallet_password";
2020-09-03 03:18:40 +02:00
import ServiceNodeDetails from "./service_node_details";
2020-09-07 05:43:36 +02:00
import ServiceNodeList from "./service_node_list";
export default {
2020-03-03 04:16:23 +01:00
name: "ServiceNodeUnlock",
components: {
2020-09-03 08:22:45 +02:00
ServiceNodeDetails,
2020-09-07 05:43:36 +02:00
ServiceNodeList
2020-03-03 04:16:23 +01:00
},
mixins: [WalletPassword],
2020-09-03 08:22:45 +02:00
data() {
const menuItems = [
2020-09-04 02:22:03 +02:00
{ action: "copyServiceNodeKey", i18n: "menuItems.copyServiceNodeKey" },
{ action: "viewOnExplorer", i18n: "menuItems.viewOnExplorer" }
2020-09-03 08:22:45 +02:00
];
return {
menuItems
};
},
2020-03-03 04:16:23 +01:00
computed: mapState({
theme: state => state.gateway.app.config.appearance.theme,
2020-09-07 08:06:47 +02:00
unlock_status: state => state.gateway.service_node_status.unlock,
2020-03-03 04:16:23 +01:00
our_address: state => {
const primary = state.gateway.wallet.address_list.primary[0];
return (primary && primary.address) || null;
},
2020-09-08 06:12:59 +02:00
// just SNs the user has contributed to
2020-03-03 04:16:23 +01:00
service_nodes(state) {
let nodes = state.gateway.daemon.service_nodes.nodes;
// don't count reserved nodes in my stakes (where they are a contributor of amount 0)
const getOurContribution = node =>
node.contributors.find(
c => c.address === this.our_address && c.amount > 0
);
return nodes
.filter(getOurContribution)
.sort((a, b) => {
if (a.service_node_pubkey < b.service_node_pubkey) return -1;
if (a.service_node_pubkey > b.service_node_pubkey) return 1;
return 0;
})
.map(n => {
const ourContribution = getOurContribution(n);
return {
...n,
ourContributionAmount: ourContribution.amount
};
});
},
fetching: state => state.gateway.daemon.service_nodes.fetching
2020-03-03 04:16:23 +01:00
}),
validations: {
node_key: { required, service_node_key }
},
watch: {
unlock_status: {
handler(val, old) {
if (val.code == old.code) return;
const { code, message } = val;
switch (code) {
2020-03-03 04:16:23 +01:00
case 0:
this.key = null;
this.password = null;
this.$q.notify({
type: "positive",
timeout: 1000,
message
2020-03-03 04:16:23 +01:00
});
this.$v.$reset();
break;
case 1:
// Tell the user to confirm
this.$q
.dialog({
title: this.$t("dialog.unlockServiceNode.confirmTitle"),
message,
ok: {
UI upgrade (#155) * followed upgrade instructions on quasar site * followed upgrade instructions on quasar site * debug messages now show * Fix template error mode undefined * building and working, UI broken, need to move to new quasar components * move collapsible to expansion-item * moving over components to quasar v1+ * items to labels * items and item side to quasar v1 * fix label typo * item main to item label * q-section to q-item-section * popover to menu * modals to v1 quasar * Remove debug lines, use new dialog methods * move static folder up a dir and rename to public. Change paths accordingly * Exit modal fixed with v1 quasar * UI fixes for v1 quasar * remove link styles * some field updates * Fix more fields and modals for v1 * more fields updated * more fields changed over * wallet settings modals * Fix password confirm dialog issue w/ refactor * begin generalising a copy component * Receive item looking better * Index view vixed for v1 quasar * fix export/import keys modal * tx styles and some others * bunch of small style changes * Fix date display on restore page * completed upgrade to v1 quasar (I think) * lns list fixed, stake buttons fixed * fix favourite checkbox with v1 quasar * Address book fixes * Fix the context menus * clean up * remove mixin from copyicon * Fix webpack * fix QR code view on address detail page * Fix welcome stepper and default to blink * Fix some style issues * radio buttons w/ white circles * clean up * sn style fixes, and other fixes * style fixes and unlock bug fixed * fix daemon typo * Fix some style things * fix button colour Co-authored-by: Kyle Zsembery <zsembery.kyle@gmail.com>
2020-08-31 07:26:06 +02:00
label: this.$t("dialog.unlockServiceNode.ok"),
color: "primary"
},
cancel: {
2020-03-03 04:16:23 +01:00
flat: true,
label: this.$t("dialog.buttons.cancel"),
color: this.theme == "dark" ? "white" : "dark"
UI upgrade (#155) * followed upgrade instructions on quasar site * followed upgrade instructions on quasar site * debug messages now show * Fix template error mode undefined * building and working, UI broken, need to move to new quasar components * move collapsible to expansion-item * moving over components to quasar v1+ * items to labels * items and item side to quasar v1 * fix label typo * item main to item label * q-section to q-item-section * popover to menu * modals to v1 quasar * Remove debug lines, use new dialog methods * move static folder up a dir and rename to public. Change paths accordingly * Exit modal fixed with v1 quasar * UI fixes for v1 quasar * remove link styles * some field updates * Fix more fields and modals for v1 * more fields updated * more fields changed over * wallet settings modals * Fix password confirm dialog issue w/ refactor * begin generalising a copy component * Receive item looking better * Index view vixed for v1 quasar * fix export/import keys modal * tx styles and some others * bunch of small style changes * Fix date display on restore page * completed upgrade to v1 quasar (I think) * lns list fixed, stake buttons fixed * fix favourite checkbox with v1 quasar * Address book fixes * Fix the context menus * clean up * remove mixin from copyicon * Fix webpack * fix QR code view on address detail page * Fix welcome stepper and default to blink * Fix some style issues * radio buttons w/ white circles * clean up * sn style fixes, and other fixes * style fixes and unlock bug fixed * fix daemon typo * Fix some style things * fix button colour Co-authored-by: Kyle Zsembery <zsembery.kyle@gmail.com>
2020-08-31 07:26:06 +02:00
},
style: "min-width: 500px; overflow-wrap: break-word;",
dark: this.theme == "dark",
color: this.theme == "dark" ? "white" : "dark"
2020-03-03 04:16:23 +01:00
})
UI upgrade (#155) * followed upgrade instructions on quasar site * followed upgrade instructions on quasar site * debug messages now show * Fix template error mode undefined * building and working, UI broken, need to move to new quasar components * move collapsible to expansion-item * moving over components to quasar v1+ * items to labels * items and item side to quasar v1 * fix label typo * item main to item label * q-section to q-item-section * popover to menu * modals to v1 quasar * Remove debug lines, use new dialog methods * move static folder up a dir and rename to public. Change paths accordingly * Exit modal fixed with v1 quasar * UI fixes for v1 quasar * remove link styles * some field updates * Fix more fields and modals for v1 * more fields updated * more fields changed over * wallet settings modals * Fix password confirm dialog issue w/ refactor * begin generalising a copy component * Receive item looking better * Index view vixed for v1 quasar * fix export/import keys modal * tx styles and some others * bunch of small style changes * Fix date display on restore page * completed upgrade to v1 quasar (I think) * lns list fixed, stake buttons fixed * fix favourite checkbox with v1 quasar * Address book fixes * Fix the context menus * clean up * remove mixin from copyicon * Fix webpack * fix QR code view on address detail page * Fix welcome stepper and default to blink * Fix some style issues * radio buttons w/ white circles * clean up * sn style fixes, and other fixes * style fixes and unlock bug fixed * fix daemon typo * Fix some style things * fix button colour Co-authored-by: Kyle Zsembery <zsembery.kyle@gmail.com>
2020-08-31 07:26:06 +02:00
.onOk(() => {
let password = this.password || "";
this.gatewayUnlock(password, this.key, true);
2020-03-03 04:16:23 +01:00
})
UI upgrade (#155) * followed upgrade instructions on quasar site * followed upgrade instructions on quasar site * debug messages now show * Fix template error mode undefined * building and working, UI broken, need to move to new quasar components * move collapsible to expansion-item * moving over components to quasar v1+ * items to labels * items and item side to quasar v1 * fix label typo * item main to item label * q-section to q-item-section * popover to menu * modals to v1 quasar * Remove debug lines, use new dialog methods * move static folder up a dir and rename to public. Change paths accordingly * Exit modal fixed with v1 quasar * UI fixes for v1 quasar * remove link styles * some field updates * Fix more fields and modals for v1 * more fields updated * more fields changed over * wallet settings modals * Fix password confirm dialog issue w/ refactor * begin generalising a copy component * Receive item looking better * Index view vixed for v1 quasar * fix export/import keys modal * tx styles and some others * bunch of small style changes * Fix date display on restore page * completed upgrade to v1 quasar (I think) * lns list fixed, stake buttons fixed * fix favourite checkbox with v1 quasar * Address book fixes * Fix the context menus * clean up * remove mixin from copyicon * Fix webpack * fix QR code view on address detail page * Fix welcome stepper and default to blink * Fix some style issues * radio buttons w/ white circles * clean up * sn style fixes, and other fixes * style fixes and unlock bug fixed * fix daemon typo * Fix some style things * fix button colour Co-authored-by: Kyle Zsembery <zsembery.kyle@gmail.com>
2020-08-31 07:26:06 +02:00
.onDismiss(() => null)
.onCancel(() => null);
2020-03-03 04:16:23 +01:00
break;
case -1:
this.key = null;
this.password = null;
this.$q.notify({
2020-03-03 04:16:23 +01:00
type: "negative",
timeout: 3000,
message
2020-03-03 04:16:23 +01:00
});
break;
default:
break;
}
},
deep: true
}
},
methods: {
details(node) {
2020-09-07 05:43:36 +02:00
this.$refs.serviceNodeDetailsUnlock.isVisible = true;
this.$refs.serviceNodeDetailsUnlock.node = node;
},
2020-09-07 07:47:57 +02:00
unlockWarning(node, event) {
2020-09-07 05:43:36 +02:00
const key = node.service_node_pubkey;
2020-09-07 07:47:57 +02:00
// stop detail page from popping up
2020-09-08 04:59:49 +02:00
this.$gateway.send("wallet", "update_service_node_list");
2020-09-07 07:47:57 +02:00
event.stopPropagation();
2020-09-07 08:06:47 +02:00
this.$q
.dialog({
title: this.$t("dialog.unlockServiceNodeWarning.title"),
message: this.$t("dialog.unlockServiceNodeWarning.message"),
ok: {
label: this.$t("dialog.unlockServiceNodeWarning.ok"),
color: "primary"
},
cancel: {
flat: true,
label: this.$t("dialog.buttons.cancel"),
color: this.theme === "dark" ? "white" : "dark"
},
dark: this.theme == "dark",
color: this.theme == "dark" ? "white" : "dark"
})
.onOk(() => {
this.unlock(key);
})
.onDismiss(() => {})
.onCancel(() => {});
2020-03-03 04:16:23 +01:00
},
UI upgrade (#155) * followed upgrade instructions on quasar site * followed upgrade instructions on quasar site * debug messages now show * Fix template error mode undefined * building and working, UI broken, need to move to new quasar components * move collapsible to expansion-item * moving over components to quasar v1+ * items to labels * items and item side to quasar v1 * fix label typo * item main to item label * q-section to q-item-section * popover to menu * modals to v1 quasar * Remove debug lines, use new dialog methods * move static folder up a dir and rename to public. Change paths accordingly * Exit modal fixed with v1 quasar * UI fixes for v1 quasar * remove link styles * some field updates * Fix more fields and modals for v1 * more fields updated * more fields changed over * wallet settings modals * Fix password confirm dialog issue w/ refactor * begin generalising a copy component * Receive item looking better * Index view vixed for v1 quasar * fix export/import keys modal * tx styles and some others * bunch of small style changes * Fix date display on restore page * completed upgrade to v1 quasar (I think) * lns list fixed, stake buttons fixed * fix favourite checkbox with v1 quasar * Address book fixes * Fix the context menus * clean up * remove mixin from copyicon * Fix webpack * fix QR code view on address detail page * Fix welcome stepper and default to blink * Fix some style issues * radio buttons w/ white circles * clean up * sn style fixes, and other fixes * style fixes and unlock bug fixed * fix daemon typo * Fix some style things * fix button colour Co-authored-by: Kyle Zsembery <zsembery.kyle@gmail.com>
2020-08-31 07:26:06 +02:00
async unlock(key) {
2020-03-03 04:16:23 +01:00
// We store this as it could change between the 2 step process
this.key = key;
UI upgrade (#155) * followed upgrade instructions on quasar site * followed upgrade instructions on quasar site * debug messages now show * Fix template error mode undefined * building and working, UI broken, need to move to new quasar components * move collapsible to expansion-item * moving over components to quasar v1+ * items to labels * items and item side to quasar v1 * fix label typo * item main to item label * q-section to q-item-section * popover to menu * modals to v1 quasar * Remove debug lines, use new dialog methods * move static folder up a dir and rename to public. Change paths accordingly * Exit modal fixed with v1 quasar * UI fixes for v1 quasar * remove link styles * some field updates * Fix more fields and modals for v1 * more fields updated * more fields changed over * wallet settings modals * Fix password confirm dialog issue w/ refactor * begin generalising a copy component * Receive item looking better * Index view vixed for v1 quasar * fix export/import keys modal * tx styles and some others * bunch of small style changes * Fix date display on restore page * completed upgrade to v1 quasar (I think) * lns list fixed, stake buttons fixed * fix favourite checkbox with v1 quasar * Address book fixes * Fix the context menus * clean up * remove mixin from copyicon * Fix webpack * fix QR code view on address detail page * Fix welcome stepper and default to blink * Fix some style issues * radio buttons w/ white circles * clean up * sn style fixes, and other fixes * style fixes and unlock bug fixed * fix daemon typo * Fix some style things * fix button colour Co-authored-by: Kyle Zsembery <zsembery.kyle@gmail.com>
2020-08-31 07:26:06 +02:00
let passwordDialog = await this.showPasswordConfirmation({
2020-03-03 04:16:23 +01:00
title: this.$t("dialog.unlockServiceNode.title"),
noPasswordMessage: this.$t("dialog.unlockServiceNode.message"),
ok: {
UI upgrade (#155) * followed upgrade instructions on quasar site * followed upgrade instructions on quasar site * debug messages now show * Fix template error mode undefined * building and working, UI broken, need to move to new quasar components * move collapsible to expansion-item * moving over components to quasar v1+ * items to labels * items and item side to quasar v1 * fix label typo * item main to item label * q-section to q-item-section * popover to menu * modals to v1 quasar * Remove debug lines, use new dialog methods * move static folder up a dir and rename to public. Change paths accordingly * Exit modal fixed with v1 quasar * UI fixes for v1 quasar * remove link styles * some field updates * Fix more fields and modals for v1 * more fields updated * more fields changed over * wallet settings modals * Fix password confirm dialog issue w/ refactor * begin generalising a copy component * Receive item looking better * Index view vixed for v1 quasar * fix export/import keys modal * tx styles and some others * bunch of small style changes * Fix date display on restore page * completed upgrade to v1 quasar (I think) * lns list fixed, stake buttons fixed * fix favourite checkbox with v1 quasar * Address book fixes * Fix the context menus * clean up * remove mixin from copyicon * Fix webpack * fix QR code view on address detail page * Fix welcome stepper and default to blink * Fix some style issues * radio buttons w/ white circles * clean up * sn style fixes, and other fixes * style fixes and unlock bug fixed * fix daemon typo * Fix some style things * fix button colour Co-authored-by: Kyle Zsembery <zsembery.kyle@gmail.com>
2020-08-31 07:26:06 +02:00
label: this.$t("dialog.unlockServiceNode.ok"),
color: "primary"
},
dark: this.theme == "dark",
color: this.theme == "dark" ? "white" : "dark"
});
passwordDialog
.onOk(password => {
this.password = password || "";
2020-03-03 04:16:23 +01:00
this.gatewayUnlock(this.password, this.key, false);
})
UI upgrade (#155) * followed upgrade instructions on quasar site * followed upgrade instructions on quasar site * debug messages now show * Fix template error mode undefined * building and working, UI broken, need to move to new quasar components * move collapsible to expansion-item * moving over components to quasar v1+ * items to labels * items and item side to quasar v1 * fix label typo * item main to item label * q-section to q-item-section * popover to menu * modals to v1 quasar * Remove debug lines, use new dialog methods * move static folder up a dir and rename to public. Change paths accordingly * Exit modal fixed with v1 quasar * UI fixes for v1 quasar * remove link styles * some field updates * Fix more fields and modals for v1 * more fields updated * more fields changed over * wallet settings modals * Fix password confirm dialog issue w/ refactor * begin generalising a copy component * Receive item looking better * Index view vixed for v1 quasar * fix export/import keys modal * tx styles and some others * bunch of small style changes * Fix date display on restore page * completed upgrade to v1 quasar (I think) * lns list fixed, stake buttons fixed * fix favourite checkbox with v1 quasar * Address book fixes * Fix the context menus * clean up * remove mixin from copyicon * Fix webpack * fix QR code view on address detail page * Fix welcome stepper and default to blink * Fix some style issues * radio buttons w/ white circles * clean up * sn style fixes, and other fixes * style fixes and unlock bug fixed * fix daemon typo * Fix some style things * fix button colour Co-authored-by: Kyle Zsembery <zsembery.kyle@gmail.com>
2020-08-31 07:26:06 +02:00
.onDismiss(() => {})
.onCancel(() => {});
2020-03-03 04:16:23 +01:00
},
2020-09-07 08:06:47 +02:00
gatewayUnlock(password, key, confirmed = false) {
password = password || "";
this.$store.commit("gateway/set_snode_status", {
unlock: {
code: 2, // Code 1 is reserved for can_unlock
message: "Unlocking...",
sending: true
}
});
this.$gateway.send("wallet", "unlock_stake", {
password,
service_node_key: key,
confirmed
});
},
2020-09-03 08:22:45 +02:00
copyKey(key) {
2020-03-03 04:16:23 +01:00
clipboard.writeText(key);
this.$q.notify({
type: "positive",
timeout: 1000,
message: this.$t("notification.positive.copied", {
item: "Service node key"
})
});
},
openExplorer(key) {
this.$gateway.send("core", "open_explorer", {
type: "service_node",
id: key
});
},
getRole(node) {
const key =
node.operator_address === this.our_address
? "strings.operator"
: "strings.contributor";
2020-03-03 04:16:23 +01:00
return this.$t(key);
},
getFee(node) {
const operatorPortion = node.portions_for_operator;
const percentageFee = (operatorPortion / 18446744073709551612) * 100;
return `${percentageFee}% ${this.$t("strings.transactions.fee")}`;
}
2020-03-03 04:16:23 +01:00
}
};
</script>
2020-09-07 05:43:36 +02:00
<style lang="scss"></style>