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

Auto deshield transaction #369

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions locale/cnr/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
autoShieldTransaction = "" # Auto shield transaction

[ALERTS]
INTERNAL_ERROR = "Interna greška, molimo pokušajte ponovo kasnije" # Internal error, please try again later
Expand Down Expand Up @@ -333,3 +334,4 @@ CONFIRM_LEDGER_TX = "" # Confirm this transaction matches the one on your {hardw
CONFIRM_LEDGER_TX_OUT = "" # You will send {value} {ticker} to <div class="inline-address">{address}</div>
MISSING_FUNDS = "" # Balance is too small! Missing {sats} sats!
MISSING_SHIELD = "" # Shield is not enabled in this wallet!
AUTO_SHIELDING_TO_SHIELD_ADDRESS = "" # Cannot auto shield to a shield address!
2 changes: 2 additions & 0 deletions locale/de/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
autoShieldTransaction = "" # Auto shield transaction

[ALERTS]
INTERNAL_ERROR = "Interner Fehler, bitte versuche es später erneut" # Internal error, please try again later
Expand Down Expand Up @@ -333,3 +334,4 @@ CONFIRM_LEDGER_TX = "" # Confirm this transaction matches the one on your {hardw
CONFIRM_LEDGER_TX_OUT = "" # You will send {value} {ticker} to <div class="inline-address">{address}</div>
MISSING_FUNDS = "" # Balance is too small! Missing {sats} sats!
MISSING_SHIELD = "" # Shield is not enabled in this wallet!
AUTO_SHIELDING_TO_SHIELD_ADDRESS = "" # Cannot auto shield to a shield address!
2 changes: 2 additions & 0 deletions locale/en/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ saveWalletFile = "Save Wallet File" # Save Wallet File
proposalOverBudget = "Over Budget" # Over Budget
badSaplingRoot = "There was an error while syncing. Resyncing from scratch (Bad sapling root)" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "Creating SHIELD transaction..." # Creating SHIELD transaction...
autoShieldTransaction = "Auto shield transaction" # Auto shield transaction

[ALERTS]
INTERNAL_ERROR = "Internal error, please try again later" # Internal error, please try again later
Expand Down Expand Up @@ -333,3 +334,4 @@ CONFIRM_LEDGER_TX = "Confirm this transaction matches the one on your {hardwareW
CONFIRM_LEDGER_TX_OUT = "You will send {value} {ticker} to <div class=\"inline-address\">{address}</div>" # You will send {value} {ticker} to <div class="inline-address">{address}</div>
MISSING_FUNDS = "Balance is too small! Missing {sats} sats!" # Balance is too small! Missing {sats} sats!
MISSING_SHIELD = "Shield is not enabled in this wallet!" # Shield is not enabled in this wallet!
AUTO_SHIELDING_TO_SHIELD_ADDRESS = "Cannot auto shield to a shield address!" # Cannot auto shield to a shield address!
2 changes: 2 additions & 0 deletions locale/es-mx/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
autoShieldTransaction = "" # Auto shield transaction

[ALERTS]
INTERNAL_ERROR = "Error interno, vuelve a intentarlo más tarde" # Internal error, please try again later
Expand Down Expand Up @@ -333,3 +334,4 @@ CONFIRM_LEDGER_TX = "" # Confirm this transaction matches the one on your {hardw
CONFIRM_LEDGER_TX_OUT = "" # You will send {value} {ticker} to <div class="inline-address">{address}</div>
MISSING_FUNDS = "" # Balance is too small! Missing {sats} sats!
MISSING_SHIELD = "" # Shield is not enabled in this wallet!
AUTO_SHIELDING_TO_SHIELD_ADDRESS = "" # Cannot auto shield to a shield address!
2 changes: 2 additions & 0 deletions locale/fr/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
autoShieldTransaction = "" # Auto shield transaction

[ALERTS]
INTERNAL_ERROR = "Erreur interne, veuillez réessayer plus tard" # Internal error, please try again later
Expand Down Expand Up @@ -333,3 +334,4 @@ CONFIRM_LEDGER_TX = "" # Confirm this transaction matches the one on your {hardw
CONFIRM_LEDGER_TX_OUT = "" # You will send {value} {ticker} to <div class="inline-address">{address}</div>
MISSING_FUNDS = "" # Balance is too small! Missing {sats} sats!
MISSING_SHIELD = "" # Shield is not enabled in this wallet!
AUTO_SHIELDING_TO_SHIELD_ADDRESS = "" # Cannot auto shield to a shield address!
2 changes: 2 additions & 0 deletions locale/it/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
autoShieldTransaction = "" # Auto shield transaction

[ALERTS]
INTERNAL_ERROR = "Errore interno, rirova più tardi" # Internal error, please try again later
Expand Down Expand Up @@ -333,3 +334,4 @@ CONFIRM_LEDGER_TX = "Conferma che questa transazione combacia quella nel tuo {ha
CONFIRM_LEDGER_TX_OUT = "Manderai {value} {ticker} a <div class=\"inline-address\">{address}</div>" # You will send {value} {ticker} to <div class="inline-address">{address}</div>
MISSING_FUNDS = "Il bilancio non è sufficiente! Mancano {sats} sats!" # Balance is too small! Missing {sats} sats!
MISSING_SHIELD = "Lo Shield non è abilitato nel wallet!" # Shield is not enabled in this wallet!
AUTO_SHIELDING_TO_SHIELD_ADDRESS = "" # Cannot auto shield to a shield address!
2 changes: 2 additions & 0 deletions locale/nl/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
autoShieldTransaction = "" # Auto shield transaction

[ALERTS]
INTERNAL_ERROR = "Interne fout, probeer het later opnieuw" # Internal error, please try again later
Expand Down Expand Up @@ -333,3 +334,4 @@ CONFIRM_LEDGER_TX = "" # Confirm this transaction matches the one on your {hardw
CONFIRM_LEDGER_TX_OUT = "" # You will send {value} {ticker} to <div class="inline-address">{address}</div>
MISSING_FUNDS = "" # Balance is too small! Missing {sats} sats!
MISSING_SHIELD = "" # Shield is not enabled in this wallet!
AUTO_SHIELDING_TO_SHIELD_ADDRESS = "" # Cannot auto shield to a shield address!
2 changes: 2 additions & 0 deletions locale/ph/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
autoShieldTransaction = "" # Auto shield transaction

[ALERTS]
INTERNAL_ERROR = "Internal error, Pakiusap uliting muli" # Internal error, please try again later
Expand Down Expand Up @@ -333,3 +334,4 @@ CONFIRM_LEDGER_TX = "" # Confirm this transaction matches the one on your {hardw
CONFIRM_LEDGER_TX_OUT = "" # You will send {value} {ticker} to <div class="inline-address">{address}</div>
MISSING_FUNDS = "" # Balance is too small! Missing {sats} sats!
MISSING_SHIELD = "" # Shield is not enabled in this wallet!
AUTO_SHIELDING_TO_SHIELD_ADDRESS = "" # Cannot auto shield to a shield address!
2 changes: 2 additions & 0 deletions locale/pl/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
autoShieldTransaction = "" # Auto shield transaction

[ALERTS]
INTERNAL_ERROR = "Błąd wewnętrzny, spróbuj ponownie później" # Internal error, please try again later
Expand Down Expand Up @@ -333,3 +334,4 @@ CONFIRM_LEDGER_TX = "" # Confirm this transaction matches the one on your {hardw
CONFIRM_LEDGER_TX_OUT = "" # You will send {value} {ticker} to <div class="inline-address">{address}</div>
MISSING_FUNDS = "" # Balance is too small! Missing {sats} sats!
MISSING_SHIELD = "" # Shield is not enabled in this wallet!
AUTO_SHIELDING_TO_SHIELD_ADDRESS = "" # Cannot auto shield to a shield address!
2 changes: 2 additions & 0 deletions locale/pt-br/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
autoShieldTransaction = "" # Auto shield transaction

[ALERTS]
STAKE_ADDR_SET = "<b>Endereço de Cold Staking definido!</b><br>Ao fazer Stake no futuro este endereço irá ser usado." # <b>Cold Address set!</b><br>Future stakes will use this address.
Expand Down Expand Up @@ -132,3 +133,4 @@ CONFIRM_LEDGER_TX = "" # Confirm this transaction matches the one on your {hardw
CONFIRM_LEDGER_TX_OUT = "" # You will send {value} {ticker} to <div class="inline-address">{address}</div>
MISSING_FUNDS = "" # Balance is too small! Missing {sats} sats!
MISSING_SHIELD = "" # Shield is not enabled in this wallet!
AUTO_SHIELDING_TO_SHIELD_ADDRESS = "" # Cannot auto shield to a shield address!
2 changes: 2 additions & 0 deletions locale/pt-pt/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
autoShieldTransaction = "" # Auto shield transaction

[ALERTS]
STAKE_ADDR_SET = "<b>Endereço de Cold Staking definido!</b><br>Ao fazer Stake no futuro irá ser usado este endereço." # <b>Cold Address set!</b><br>Future stakes will use this address.
Expand Down Expand Up @@ -132,3 +133,4 @@ CONFIRM_LEDGER_TX = "" # Confirm this transaction matches the one on your {hardw
CONFIRM_LEDGER_TX_OUT = "" # You will send {value} {ticker} to <div class="inline-address">{address}</div>
MISSING_FUNDS = "" # Balance is too small! Missing {sats} sats!
MISSING_SHIELD = "" # Shield is not enabled in this wallet!
AUTO_SHIELDING_TO_SHIELD_ADDRESS = "" # Cannot auto shield to a shield address!
4 changes: 3 additions & 1 deletion locale/template/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ shieldAddress = "Shield address"
cantShieldToExc = "This address does not support shield transfers"
badSaplingRoot = "There was an error while syncing. Resyncing from scratch (Bad sapling root)"
creatingShieldTransaction = "Creating SHIELD transaction..."
autoShieldTransaction = "Auto shield transaction"

[ALERTS]
INTERNAL_ERROR = "Internal error, please try again later"
Expand Down Expand Up @@ -356,4 +357,5 @@ CONFIRM_POPUP_DELETE_ACCOUNT_TITLE = 'Are you sure?'
CONFIRM_LEDGER_TX = 'Confirm this transaction matches the one on your {hardwareWallet}'
CONFIRM_LEDGER_TX_OUT = 'You will send {value} {ticker} to <div class="inline-address">{address}</div>'
MISSING_FUNDS = 'Balance is too small! Missing {sats} sats!'
MISSING_SHIELD = "Shield is not enabled in this wallet!"
MISSING_SHIELD = "Shield is not enabled in this wallet!"
AUTO_SHIELDING_TO_SHIELD_ADDRESS = "Cannot auto shield to a shield address!"
2 changes: 2 additions & 0 deletions locale/uwu/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ saveWalletFile = "Save Wawwet File" # Save Wallet File
proposalOverBudget = "Over Budgey" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
autoShieldTransaction = "" # Auto shield transaction

[ALERTS]
INTERNAL_ERROR = "Internal error, pwease try again later" # Internal error, please try again later
Expand Down Expand Up @@ -333,3 +334,4 @@ CONFIRM_LEDGER_TX = "" # Confirm this transaction matches the one on your {hardw
CONFIRM_LEDGER_TX_OUT = "" # You will send {value} {ticker} to <div class="inline-address">{address}</div>
MISSING_FUNDS = "" # Balance is too small! Missing {sats} sats!
MISSING_SHIELD = "" # Shield is not enabled in this wallet!
AUTO_SHIELDING_TO_SHIELD_ADDRESS = "" # Cannot auto shield to a shield address!
26 changes: 19 additions & 7 deletions scripts/composables/use_wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ export const useWallet = defineStore('wallet', () => {
getEventEmitter().on('shield-loaded-from-disk', () => {
hasShield.value = wallet.hasShield();
});
const sendTransaction = async (network, tx) => {
const res = await network.sendTransaction(tx.serialize());
if (res) {
await wallet.addTransaction(tx);
} else {
wallet.discardTransaction(tx);
}
return res;
};
const createAndSendTransaction = lockableFunction(
async (network, address, value, opts) => {
const tx = wallet.createTransaction(address, value, opts);
Expand All @@ -81,15 +90,17 @@ export const useWallet = defineStore('wallet', () => {
} else {
await wallet.sign(tx);
}
const res = await network.sendTransaction(tx.serialize());
if (res) {
await wallet.addTransaction(tx);
} else {
wallet.discardTransaction(tx);
}
return res;
return await sendTransaction(network, tx);
}
);
const createAuthoshieldTransactions = async (network, address, value) => {
Duddino marked this conversation as resolved.
Show resolved Hide resolved
const txs = await wallet.createAutoshieldTransactions(address, value);
let res = true;
for (const tx of txs) {
res = res && (await sendTransaction(network, tx));
Duddino marked this conversation as resolved.
Show resolved Hide resolved
}
return res;
};
const isCreatingTransaction = () => createAndSendTransaction.isLocked();

getEventEmitter().on('toggle-network', async () => {
Expand Down Expand Up @@ -136,5 +147,6 @@ export const useWallet = defineStore('wallet', () => {
createAndSendTransaction,
loadFromDisk,
coldBalance,
createAuthoshieldTransactions,
};
});
10 changes: 9 additions & 1 deletion scripts/contacts-book.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
createAlert,
createQR,
getImageFile,
isShieldAddress,
isValidPIVXAddress,
isXPub,
sanitizeHTML,
Expand Down Expand Up @@ -935,8 +936,12 @@ export async function guiSetAccountName(strDOM) {
/**
* Get the address color based on the validity of an address/contact
* @param {string} address
* @param {boolean} [invalidateShieldAddresses] - if set to true, shield addresses will return as invalid color
*/
export async function getAddressColor(address) {
export async function getAddressColor(
address,
invalidateShieldAddresses = false
) {
// If the value is empty, we don't do any checks and simply reset the colourcoding
if (!address) {
return '';
Expand All @@ -955,6 +960,9 @@ export async function getAddressColor(address) {
// Yep, nice!
return 'green';
}
if (invalidateShieldAddresses && isShieldAddress(address)) {
return '#b20000';
}
if (isValidPIVXAddress(address)) {
// Yep!
return 'green';
Expand Down
26 changes: 22 additions & 4 deletions scripts/dashboard/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ function lockWallet() {
* Sends a transaction
* @param {string} address - Address or contact to send to
* @param {number} amount - Amount of PIVs to send
* @param {boolean} isAutoShield - Whether or not this is an autoshield transaction
*/
async function send(address, amount, useShieldInputs) {
async function send(address, amount, useShieldInputs, isAutoShield) {
// Ensure a wallet is unlocked
if (wallet.isViewOnly && !wallet.isHardwareWallet) {
if (
Expand Down Expand Up @@ -251,6 +252,10 @@ async function send(address, amount, useShieldInputs) {
}
}

if (isAutoShield && isShieldAddress(address)) {
return createAlert('warning', ALERTS.AUTO_SHIELDING_TO_SHIELD_ADDRESS);
}

// If this is an XPub, we'll fetch their last used 'index', and derive a new public key for enhanced privacy
if (isXPub(address)) {
const cNet = getNetwork();
Expand Down Expand Up @@ -325,9 +330,22 @@ async function send(address, amount, useShieldInputs) {

// Create and send the TX
try {
await wallet.createAndSendTransaction(getNetwork(), address, nValue, {
useShieldInputs,
});
if (isAutoShield) {
await wallet.createAuthoshieldTransactions(
getNetwork(),
address,
nValue
);
} else {
await wallet.createAndSendTransaction(
getNetwork(),
address,
nValue,
{
useShieldInputs,
}
);
}
} catch (e) {
console.error(e);
createAlert('warning', e);
Expand Down
34 changes: 32 additions & 2 deletions scripts/dashboard/TransferMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ const emit = defineEmits([
// Amount of PIVs to send in the selected currency (e.g. USD)
const amountCurrency = ref('');
const useShieldInputs = ref(false);
const autoShieldTransaction = ref(false);
const color = ref('');

watch(useShieldInputs, (useShieldInputs) => {
if (!useShieldInputs) autoShieldTransaction.value = false;
});

const props = defineProps({
show: Boolean,
price: Number,
Expand All @@ -35,9 +40,16 @@ const address = computed({
},
set(value) {
emit('update:address', value);
getAddressColor(value).then((c) => (color.value = c));
getAddressColor(
value,
autoShieldTransaction.value || !props.shieldEnabled
).then((c) => (color.value = c));
},
});
watch(autoShieldTransaction, () => {
// Trigger address setter so we can recolor shield addresses
address.value = address.value;
});
const amount = computed({
get() {
return props.amount;
Expand All @@ -55,7 +67,8 @@ function send() {
'send',
sanitizeHTML(address.value),
amount.value,
useShieldInputs.value
useShieldInputs.value,
autoShieldTransaction.value
);
}

Expand Down Expand Up @@ -254,6 +267,23 @@ async function selectContact() {
}}</label>
</div>
<br />
<div v-show="useShieldInputs">
<div class="custom-control custom-switch">
<input
type="checkbox"
class="custom-control-input"
data-testid="useShieldInputs"
id="autoShieldTransaction"
v-model="autoShieldTransaction"
/>
<label
class="custom-control-label"
for="autoShieldTransaction"
>{{ translation.autoShieldTransaction }}</label
>
</div>
<br />
</div>
</div>

<div class="text-right pb-2">
Expand Down
Loading
Loading