Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix confirm tx popup inconsistency when sweeping all from service node tab #191

Merged
merged 6 commits into from Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion src-electron/main-process/modules/backend.js
Expand Up @@ -493,7 +493,6 @@ export class Backend {
fs.mkdirpSync(log_dir);
}

console.log("About to init the logger with log_dir: " + log_dir);
this.initLogger(log_dir);

this.daemon = new Daemon(this);
Expand Down
50 changes: 36 additions & 14 deletions src-electron/main-process/modules/wallet-rpc.js
Expand Up @@ -336,15 +336,17 @@ export class WalletRPC {
params.amount,
params.address,
params.payment_id,
params.priority
params.priority,
!!params.isSweepAll
);
break;
case "relay_tx":
this.relayTransaction(
params.metadataList,
params.isBlink,
params.addressSave,
params.note
params.note,
!!params.isSweepAll
);
break;
case "purchase_lns":
Expand Down Expand Up @@ -1348,8 +1350,17 @@ export class WalletRPC {
}

// submits the transaction to the blockchain, irreversible from here
async relayTransaction(metadataList, isBlink, addressSave, note) {
const { address, payment_id, address_book } = addressSave;
async relayTransaction(metadataList, isBlink, addressSave, note, isSweepAll) {
// for a sweep these don't exist
let address = "";
let payment_id = "";
let address_book = "";
if (addressSave) {
address = addressSave.address;
payment_id = addressSave.payment_id;
address_book = addressSave.address_book;
}

let failed = false;
let errorMessage = "Failed to relay transaction";

Expand Down Expand Up @@ -1383,8 +1394,13 @@ export class WalletRPC {
}
}

// for updating state on the correct page
const gatewayEndpoint = isSweepAll
? "set_sweep_all_status"
: "set_tx_status";

if (!failed) {
this.sendGateway("set_tx_status", {
this.sendGateway(gatewayEndpoint, {
code: 0,
i18n: "notification.positive.sendSuccess",
sending: false
Expand All @@ -1401,7 +1417,7 @@ export class WalletRPC {
return;
}

this.sendGateway("set_tx_status", {
this.sendGateway(gatewayEndpoint, {
code: -1,
message: errorMessage,
sending: false
Expand All @@ -1410,7 +1426,8 @@ export class WalletRPC {

// prepares params and provides a "confirm" popup to allow the user to check
// send address and tx fees before sending
transfer(password, amount, address, payment_id, priority) {
// isSweepAll refers to if it's the sweep from service nodes page
transfer(password, amount, address, payment_id, priority, isSweepAll) {
const cryptoCallback = (err, password_hash) => {
if (err) {
this.sendGateway("set_tx_status", {
Expand All @@ -1434,10 +1451,10 @@ export class WalletRPC {
// if sending "All" the funds, then we need to send all - fee (sweep_all)
// To be amended after the hardfork, v8.
// https://github.com/loki-project/loki-electron-gui-wallet/issues/181
const isSweepAll = amount == this.wallet_state.unlocked_balance;
const rpc_endpoint = isSweepAll ? "sweep_all" : "transfer_split";
const isSweepAllRPC = amount == this.wallet_state.unlocked_balance;
const rpc_endpoint = isSweepAllRPC ? "sweep_all" : "transfer_split";

const rpcSpecificParams = isSweepAll
const rpcSpecificParams = isSweepAllRPC
? {
address,
account_index: 0
Expand All @@ -1456,6 +1473,11 @@ export class WalletRPC {
params.payment_id = payment_id;
}

// for updating state on the correct page
const gatewayEndpoint = isSweepAll
? "set_sweep_all_status"
: "set_tx_status";

this.sendRPC(rpc_endpoint, params)
.then(data => {
if (data.hasOwnProperty("error") || !data.hasOwnProperty("result")) {
Expand All @@ -1467,7 +1489,7 @@ export class WalletRPC {
} else {
error = `Incorrect result from ${rpc_endpoint} RPC call`;
}
this.sendGateway("set_tx_status", {
this.sendGateway(gatewayEndpoint, {
code: -1,
message: error,
sending: false
Expand All @@ -1476,14 +1498,14 @@ export class WalletRPC {
}

// update state to show a confirm popup
this.sendGateway("set_tx_status", {
this.sendGateway(gatewayEndpoint, {
code: 1,
i18n: "strings.awaitingConfirmation",
sending: false,
txData: {
// target address for a sweep all
address: data.params.address,
isSweepAll: isSweepAll,
isSweepAll: isSweepAllRPC,
amountList: data.result.amount_list,
metadataList: data.result.tx_metadata_list,
feeList: data.result.fee_list,
Expand All @@ -1494,7 +1516,7 @@ export class WalletRPC {
});
})
.catch(err => {
this.sendGateway("set_tx_status", {
this.sendGateway(gatewayEndpoint, {
code: -1,
message: err.message,
sending: false
Expand Down
107 changes: 101 additions & 6 deletions src/components/service_node/service_node_staking.vue
Expand Up @@ -73,8 +73,17 @@
class="contribute"
@contribute="fillStakingFields"
/>
<ConfirmTransactionDialog
:show="confirmSweepAll"
:amount="confirmFields.totalAmount"
:is-blink="confirmFields.isBlink"
:send-to="confirmFields.destination"
:fee="confirmFields.totalFees"
:on-confirm-transaction="onConfirmTransaction"
:on-cancel-transaction="onCancelTransaction"
/>
<q-inner-loading
:showing="stake_status.sending || tx_status.sending"
:showing="stake_status.sending || sweep_all_status.sending"
:dark="theme == 'dark'"
>
<q-spinner color="primary" size="30" />
Expand All @@ -92,15 +101,16 @@ import WalletPassword from "src/mixins/wallet_password";
import ConfirmDialogMixin from "src/mixins/confirm_dialog_mixin";
import ServiceNodeContribute from "./service_node_contribute";
import ServiceNodeMixin from "src/mixins/service_node_mixin";
import ConfirmTransactionDialog from "components/confirm_tx_dialog";

// the case for doing nothing on a tx_status update
const DO_NOTHING = 10;

export default {
name: "ServiceNodeStaking",
components: {
LokiField,
ServiceNodeContribute
ServiceNodeContribute,
ConfirmTransactionDialog
},
mixins: [WalletPassword, ConfirmDialogMixin, ServiceNodeMixin],
data() {
Expand All @@ -112,6 +122,13 @@ export default {
// start at min/max for the wallet
minStakeAmount: 0,
maxStakeAmount: this.unlocked_balance / 1e9
},
confirmFields: {
metadataList: [],
isBlink: false,
totalAmount: -1,
destination: "",
totalFees: 0
}
};
},
Expand All @@ -120,8 +137,9 @@ export default {
unlocked_balance: state => state.gateway.wallet.info.unlocked_balance,
info: state => state.gateway.wallet.info,
stake_status: state => state.gateway.service_node_status.stake,
tx_status: state => state.gateway.tx_status,
sweep_all_status: state => state.gateway.sweep_all_status,
award_address: state => state.gateway.wallet.info.address,
confirmSweepAll: state => state.gateway.sweep_all_status.code === 1,
is_ready() {
return this.$store.getters["gateway/isReady"];
},
Expand Down Expand Up @@ -215,6 +233,50 @@ export default {
}
},
deep: true
},
sweep_all_status: {
handler(val, old) {
if (val.code == old.code) return;
const { code, message } = val;
switch (code) {
// the "nothing", so we can update state without doing anything
// in particular
case DO_NOTHING:
break;
case 1:
this.buildDialogFieldsSweepAll(val);
break;
case 0:
this.$q.notify({
type: "positive",
timeout: 1000,
message
});
this.$v.$reset();
this.newTx = {
amount: 0,
address: "",
payment_id: "",
// blink
priority: 5,
address_book: {
save: false,
name: "",
description: ""
},
note: ""
};
break;
case -1:
this.$q.notify({
type: "negative",
timeout: 3000,
message
});
break;
}
},
deep: true
}
},
methods: {
Expand Down Expand Up @@ -256,6 +318,33 @@ export default {
return nodeOfKey;
}
},
onConfirmTransaction() {
// put the loading spinner up
this.$store.commit("gateway/set_sweep_all_status", {
code: DO_NOTHING,
message: "Getting sweep all tx information",
sending: true
});

const metadataList = this.confirmFields.metadataList;
const isBlink = this.confirmFields.isBlink;

const relayTxData = {
metadataList,
isBlink,
isSweepAll: true
};

// Commit the transaction
this.$gateway.send("wallet", "relay_tx", relayTxData);
},
onCancelTransaction() {
this.$store.commit("gateway/set_sweep_all_status", {
code: DO_NOTHING,
message: "Cancel the transaction from confirm dialog",
sending: false
});
},
sweepAllWarning() {
this.$q
.dialog({
Expand All @@ -278,6 +367,9 @@ export default {
.onDismiss(() => {})
.onCancel(() => {});
},
buildDialogFieldsSweepAll(txData) {
this.confirmFields = this.buildDialogFields(txData);
},
areButtonsEnabled() {
// if we can find the service node key in the list of service nodes
const key = this.service_node.key;
Expand Down Expand Up @@ -307,12 +399,15 @@ export default {
passwordDialog
.onOk(password => {
password = password || "";
this.$store.commit("gateway/set_tx_status", {
this.$store.commit("gateway/set_sweep_all_status", {
code: DO_NOTHING,
message: "Sweeping all",
sending: true
});
const newTx = objectAssignDeep.noMutate(tx, { password });
const newTx = objectAssignDeep.noMutate(tx, {
password,
isSweepAll: true
});
this.$gateway.send("wallet", "transfer", newTx);
})
.onDismiss(() => {})
Expand Down
29 changes: 29 additions & 0 deletions src/css/app.styl
Expand Up @@ -373,6 +373,35 @@ footer,
color: white;
}
}
.confirm-tx-card {
color: "primary";
width: 450px;
max-width: 450x;

.confirm-list {
.q-item {
max-height: 100%;
margin-top: 0;
margin-bottom: 4px;
padding-top: 0;
padding-bottom: 0;
}
}

.label {
color: #cecece;
padding-right: 6px;
}
.address-value {
word-break: break-word;
}

.confirm-send-btn {
color: white;
background: $positive;
}
}


.header-popover {
background: $primary;
Expand Down