240 lines
6.9 KiB
Vue
240 lines
6.9 KiB
Vue
<template>
|
|
<div class="lns-input">
|
|
<LNSInputForm
|
|
ref="form"
|
|
:submit-label="submit_label"
|
|
:disable-name="updating || renewing"
|
|
:updating="updating"
|
|
:renewing="renewing"
|
|
:show-clear-button="updating || renewing"
|
|
:disable-submit-button="disable_submit_button"
|
|
@onSubmit="onSubmit"
|
|
@onClear="onClear"
|
|
/>
|
|
<q-inner-loading :showing="lns_status.sending" :dark="theme == 'dark'">
|
|
<q-spinner color="primary" size="30" />
|
|
</q-inner-loading>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { mapState } from "vuex";
|
|
import LNSInputForm from "./lns_input_form";
|
|
import WalletPassword from "src/mixins/wallet_password";
|
|
const objectAssignDeep = require("object-assign-deep");
|
|
|
|
export default {
|
|
name: "LNSInput",
|
|
components: {
|
|
LNSInputForm
|
|
},
|
|
mixins: [WalletPassword],
|
|
data() {
|
|
return {
|
|
updating: false,
|
|
renewing: false
|
|
};
|
|
},
|
|
computed: mapState({
|
|
theme: state => state.gateway.app.config.appearance.theme,
|
|
lns_status: state => state.gateway.lns_status,
|
|
unlocked_balance: state => state.gateway.wallet.info.unlocked_balance,
|
|
disable_submit_button() {
|
|
const minBalance = this.updating ? 0.05 : 21;
|
|
return this.unlocked_balance < minBalance * 1e9;
|
|
},
|
|
submit_label() {
|
|
let label = "buttons.purchase";
|
|
if (this.updating) {
|
|
label = "buttons.update";
|
|
} else if (this.renewing) {
|
|
label = "buttons.renew";
|
|
}
|
|
return this.$t(label);
|
|
}
|
|
}),
|
|
|
|
watch: {
|
|
lns_status: {
|
|
handler(val, old) {
|
|
if (val.code == old.code) return;
|
|
const { code, message } = val;
|
|
switch (code) {
|
|
case 0:
|
|
this.$q.notify({
|
|
type: "positive",
|
|
timeout: 1000,
|
|
message
|
|
});
|
|
this.$refs.form.reset();
|
|
this.renewing = false;
|
|
this.updating = false;
|
|
break;
|
|
case -1:
|
|
this.$q.notify({
|
|
type: "negative",
|
|
timeout: 3000,
|
|
message
|
|
});
|
|
break;
|
|
}
|
|
},
|
|
deep: true
|
|
}
|
|
},
|
|
methods: {
|
|
startUpdating(record) {
|
|
this.$refs.form.setRecord(record);
|
|
this.updating = true;
|
|
},
|
|
startRenewing(record) {
|
|
this.renewing = true;
|
|
// set the type such that we default to one year
|
|
let renewRecord = {
|
|
...record,
|
|
type: "lokinet_1y"
|
|
};
|
|
this.$refs.form.setRecord(renewRecord);
|
|
},
|
|
onSubmit(record, oldRecord) {
|
|
if (this.updating) {
|
|
this.update(record, oldRecord);
|
|
} else if (this.renewing) {
|
|
this.renew(record);
|
|
} else {
|
|
this.purchase(record);
|
|
}
|
|
},
|
|
onClear() {
|
|
this.$refs.form.reset();
|
|
this.updating = false;
|
|
this.renewing = false;
|
|
},
|
|
async update(record, oldRecord) {
|
|
console.log("update called");
|
|
console.log(record);
|
|
console.log(oldRecord);
|
|
// Make sure we have a diff between the 2 records
|
|
const isOwnerDifferent =
|
|
record.owner !== "" && record.owner !== oldRecord.owner;
|
|
const isBackupOwnerDifferent =
|
|
record.backup_owner !== "" &&
|
|
record.backup_owner !== oldRecord.backup_owner;
|
|
console.log("old value: " + oldRecord.value);
|
|
console.log("new value: " + record.value);
|
|
const isValueDifferent = record.value !== oldRecord.value;
|
|
const different =
|
|
isOwnerDifferent || isBackupOwnerDifferent || isValueDifferent;
|
|
|
|
// TODO: This is a little confusing, if nothing was actually updated
|
|
if (!different) {
|
|
this.$q.notify({
|
|
type: "positive",
|
|
timeout: 1000,
|
|
message: this.$t("notification.positive.lnsRecordUpdated")
|
|
});
|
|
return;
|
|
}
|
|
|
|
const updatedRecord = {
|
|
...record,
|
|
value: isValueDifferent ? record.value : oldRecord.value,
|
|
owner: isOwnerDifferent ? record.owner : "",
|
|
backup_owner: isBackupOwnerDifferent ? record.backup_owner : ""
|
|
};
|
|
console.log("updated record");
|
|
console.log(updatedRecord);
|
|
|
|
let passwordDialog = await this.showPasswordConfirmation({
|
|
title: this.$t("dialog.lnsUpdate.title"),
|
|
noPasswordMessage: this.$t("dialog.lnsUpdate.message"),
|
|
ok: {
|
|
label: this.$t("dialog.lnsUpdate.ok"),
|
|
color: "primary"
|
|
},
|
|
dark: this.theme == "dark",
|
|
color: this.theme == "dark" ? "white" : "dark"
|
|
});
|
|
passwordDialog
|
|
.onOk(password => {
|
|
// if no password set
|
|
password = password || "";
|
|
this.$store.commit("gateway/set_lns_status", {
|
|
code: 1,
|
|
message: "Sending transaction",
|
|
sending: true
|
|
});
|
|
const lns = objectAssignDeep.noMutate(updatedRecord, {
|
|
password
|
|
});
|
|
this.$gateway.send("wallet", "update_lns_mapping", lns);
|
|
})
|
|
.onDismiss(() => {})
|
|
.onCancel(() => {});
|
|
},
|
|
async purchase(record) {
|
|
let passwordDialog = await this.showPasswordConfirmation({
|
|
title: this.$t("dialog.purchase.title"),
|
|
noPasswordMessage: this.$t("dialog.purchase.message"),
|
|
ok: {
|
|
label: this.$t("dialog.purchase.ok"),
|
|
color: "primary"
|
|
},
|
|
dark: this.theme == "dark",
|
|
color: this.theme == "dark" ? "white" : "dark"
|
|
});
|
|
passwordDialog
|
|
.onOk(password => {
|
|
// if no password set
|
|
password = password || "";
|
|
this.$store.commit("gateway/set_lns_status", {
|
|
code: 1,
|
|
message: "Sending transaction",
|
|
sending: true
|
|
});
|
|
const lns = objectAssignDeep.noMutate(record, {
|
|
password
|
|
});
|
|
this.$gateway.send("wallet", "purchase_lns", lns);
|
|
})
|
|
.onDismiss(() => {})
|
|
.onCancel(() => {});
|
|
},
|
|
async renew(record) {
|
|
console.log("renew the record");
|
|
console.log(record);
|
|
let passwordDialog = await this.showPasswordConfirmation({
|
|
title: this.$t("dialog.renew.title"),
|
|
noPasswordMessage: this.$t("dialog.renew.message"),
|
|
ok: {
|
|
label: this.$t("dialog.renew.ok"),
|
|
color: "primary"
|
|
},
|
|
dark: this.theme == "dark",
|
|
color: this.theme == "dark" ? "white" : "dark"
|
|
});
|
|
passwordDialog
|
|
.onOk(password => {
|
|
// if no password set
|
|
password = password || "";
|
|
this.$store.commit("gateway/set_lns_status", {
|
|
code: 1,
|
|
message: "Sending renew mapping transaction",
|
|
sending: true
|
|
});
|
|
const params = {
|
|
type: record.type,
|
|
name: record.name,
|
|
password
|
|
};
|
|
this.$gateway.send("wallet", "lns_renew_mapping", params);
|
|
})
|
|
.onDismiss(() => {})
|
|
.onCancel(() => {});
|
|
}
|
|
}
|
|
};
|
|
</script>
|
|
|
|
<style lang="scss"></style>
|