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

Improve Proposal Creation #199

Merged
merged 2 commits into from
Sep 19, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions locale/de/translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,10 @@ export const de_translation = {
popupCreateProposal: 'Erstelle Antrag', //Create Proposal
popupCreateProposalCost: 'Kosten', //Cost
popupProposalName: 'Name des Antrags', //Proposal Name
popupProposalAddress: '', //Proposal Address (Optional)
popupProposalDuration: 'Dauer in Zyklen', //Duration in cycles
popupProposalPerCycle: 'pro Zyklus', //per cycle
popupProposalEncryptFirst: '', //You need to hit "{button}" before you can create proposals!
popupProposalVoteHash: 'Hash zum Wählen', //Vote Hash:
popupProposalFinalisedNote:
'<b>Glückwünsche zum einreichen des Antrags!</b><br>Besitzer einer Masternote können nun den Wahl-Hash benutzen, um aus ihren Geldbörsen heraus (auch andere als MPW) zu wählen. Es ist darum sinnvoll einen Beitrag dazu im Form zun hinterlassen - wenn Anwendbar', //<b>Congratulations on launching your proposal!</b><br>Masternode owners can use your Vote Hash to vote from wallets other than MPW, so make sure to add this to your forum post, if applicable!
Expand Down
3 changes: 3 additions & 0 deletions locale/en/translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,11 @@ export const en_translation = {
popupCreateProposal: 'Create Proposal',
popupCreateProposalCost: 'Cost',
popupProposalName: 'Proposal Name',
popupProposalAddress: 'Proposal Address (Optional)',
popupProposalDuration: 'Duration in cycles',
popupProposalPerCycle: 'per cycle',
popupProposalEncryptFirst:
'You need to hit "{button}" before you can create proposals!',
popupProposalVoteHash: 'Vote Hash:',
popupProposalFinalisedNote:
'<b>Congratulations on launching your proposal!</b><br>Masternode owners can use your Vote Hash to vote from wallets other than MPW, so make sure to add this to your forum post, if applicable!',
Expand Down
2 changes: 2 additions & 0 deletions locale/es-mx/translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@ export const es_mx_translation = {
popupCreateProposal: 'Crear una Propuesta', //Create Proposal
popupCreateProposalCost: 'Costo', //Cost
popupProposalName: 'Nombre de la Propuesta', //Proposal Name
popupProposalAddress: '', //Proposal Address (Optional)
popupProposalDuration: 'Duración en Ciclos', //Duration in cycles
popupProposalPerCycle: 'por ciclo', //per cycle
popupProposalEncryptFirst: '', //You need to hit "{button}" before you can create proposals!
popupProposalVoteHash: 'Hash de Votación:', //Vote Hash:
popupProposalFinalisedNote:
'<b>¡Felicitaciones por el lanzamiento de tu propuesta!</b><br>¡Los propietarios de Masternode pueden utilizar tu Hash de Votación para votar desde wallets que no sean MPW, así que asegúrate de añadirlo a tu mensaje en el foro, si aplica!', //<b>Congratulations on launching your proposal!</b><br>Masternode owners can use your Vote Hash to vote from wallets other than MPW, so make sure to add this to your forum post, if applicable!
Expand Down
2 changes: 2 additions & 0 deletions locale/fr/translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,10 @@ export const fr_translation = {
popupCreateProposal: 'Créer une proposition', //Create Proposal
popupCreateProposalCost: 'Coût', //Cost
popupProposalName: 'Nom de la proposition', //Proposal Name
popupProposalAddress: '', //Proposal Address (Optional)
popupProposalDuration: 'Durée en cycles', //Duration in cycles
popupProposalPerCycle: 'par cycle', //per cycle
popupProposalEncryptFirst: '', //You need to hit "{button}" before you can create proposals!
popupProposalVoteHash: 'Vote Hash :', //Vote Hash:
popupProposalFinalisedNote:
"<b>Félicitations pour le lancement de votre proposition!</b><br>Les propriétaires de Masternodes peuvent utiliser votre Hash de vote pour voter à partir de portefeuilles autres que MPW, alors assurez-vous d'ajouter ceci à votre message sur le forum, le cas échéant!", //<b>Congratulations on launching your proposal!</b><br>Masternode owners can use your Vote Hash to vote from wallets other than MPW, so make sure to add this to your forum post, if applicable!
Expand Down
2 changes: 2 additions & 0 deletions locale/it/translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,10 @@ export const it_translation = {
popupCreateProposal: 'Crea proposta', //Create Proposal
popupCreateProposalCost: 'Costo', //Cost
popupProposalName: 'Nome della proposta', //Proposal Name
popupProposalAddress: '', //Proposal Address (Optional)
popupProposalDuration: 'Durata in cicli', //Duration in cycles
popupProposalPerCycle: 'per ciclo', //per cycle
popupProposalEncryptFirst: '', //You need to hit "{button}" before you can create proposals!
popupProposalVoteHash: 'Hash del voto:', //Vote Hash:
popupProposalFinalisedNote:
'<b>Congratulazioni per aver pubblicato la tua proposta!</b><br>I proprietari di Masternode possono utilizzare il tuo Hash di voto per votare da portafogli diversi da MPW, quindi assicurati di aggiungerlo al tuo post sul forum, se applicabile!', //<b>Congratulations on launching your proposal!</b><br>Masternode owners can use your Vote Hash to vote from wallets other than MPW, so make sure to add this to your forum post, if applicable!
Expand Down
2 changes: 2 additions & 0 deletions locale/ph/translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,10 @@ export const ph_translation = {
popupCreateProposal: 'Gumawa ng Proposal', //Create Proposal
popupCreateProposalCost: 'Gastos', //Cost
popupProposalTitle: 'Proposal Title', //Proposal Title
popupProposalAddress: '', //Proposal Address (Optional)
popupProposalDuration: 'Duration in cycles', //Duration in cycles
popupProposalPerCycle: 'per cycles', //per cycle
popupProposalEncryptFirst: '', //You need to hit "{button}" before you can create proposals!
popupProposalVoteHash: 'Vote Hash:', //Vote Hash:
popupProposalFinalisedNote:
'<b>Binabati kita sa paglulunsad ng iyong proposal!</b><br>Ang mga may-ari ng Masternode ay pwedeng gumamit ng Vote Hash upang bumoto mula sa mga wallet maliban sa MPW, kaya siguraduhin idagdag ito sa iyong forum post, kung naaangkop!', //<b>Congratulations on launching your proposal!</b><br>Masternode owners can use your Vote Hash to vote from wallets other than MPW, so make sure to add this to your forum post, if applicable!
Expand Down
2 changes: 2 additions & 0 deletions locale/pt-br/translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@ export const pt_br_translation = {
popupCreateProposal: 'Criar Proposta', //Create Proposal
popupCreateProposalCost: 'Custo', //Cost
popupProposalName: 'Título da Proposta', //Proposal Title
popupProposalAddress: '', //Proposal Address (Optional)
popupProposalDuration: 'Duração em ciclos', //Duration in cycles
popupProposalPerCycle: 'por ciclo', //per cycle
popupProposalEncryptFirst: '', //You need to hit "{button}" before you can create proposals!
popupProposalVoteHash: 'Votação de Hash:', //Vote Hash:
popupProposalFinalisedNote:
'<b>Parabéns pelo lançamento da sua proposta!</b><br>Os proprietários do Masternode podem usar a sua votação de hash em outras carteiras que não sejam MPW, então certifique-se de adicionar isso à sua publicação no fórum, se aplicável!', //<b>Congratulations on launching your proposal!</b><br>Masternode owners can use your Vote Hash to vote from wallets other than MPW, so make sure to add this to your forum post, if applicable!
Expand Down
2 changes: 2 additions & 0 deletions locale/pt-pt/translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@ export const pt_pt_translation = {
popupCreateProposal: 'Criar Proposta', //Create Proposal
popupCreateProposalCost: 'Custo', //Cost
popupProposalName: 'Título da Proposta', //Proposal Title
popupProposalAddress: '', //Proposal Address (Optional)
popupProposalDuration: 'Duração em ciclos', //Duration in cycles
popupProposalPerCycle: 'por ciclo', //per cycle
popupProposalEncryptFirst: '', //You need to hit "{button}" before you can create proposals!
popupProposalVoteHash: 'Votação de Hash:', //Vote Hash:
popupProposalFinalisedNote:
'<b>Parabéns pelo lançamento da sua proposta!</b><br>Os proprietários do Masternode podem usar a sua votação de hash em outras carteiras que não sejam MPW, então certifique-se de adicionar isso à sua publicação no fórum, se aplicável!', //<b>Congratulations on launching your proposal!</b><br>Masternode owners can use your Vote Hash to vote from wallets other than MPW, so make sure to add this to your forum post, if applicable!
Expand Down
2 changes: 2 additions & 0 deletions locale/template/translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,10 @@ export const translation_template = {
popupCreateProposal: '', //Create Proposal
popupCreateProposalCost: '', //Cost
popupProposalName: '', //Proposal Name
popupProposalAddress: '', //Proposal Address (Optional)
popupProposalDuration: '', //Duration in cycles
popupProposalPerCycle: '', //per cycle
popupProposalEncryptFirst: '', //You need to hit "{button}" before you can create proposals!
popupProposalVoteHash: '', //Vote Hash:
popupProposalFinalisedNote: '', //<b>Congratulations on launching your proposal!</b><br>Masternode owners can use your Vote Hash to vote from wallets other than MPW, so make sure to add this to your forum post, if applicable!
popupProposalFinalisedSignoff: '', //Good luck on your journey through the DAO, PIVian!
Expand Down
3 changes: 3 additions & 0 deletions locale/uwu/translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,11 @@ export const uwu_translation = {
popupCreateProposal: 'Cweate Pwoposal', //Create Proposal
popupCreateProposalCost: 'Cost', //Cost
popupProposalName: 'Pwoposal Name', //Proposal Name
popupProposalAddress: 'Pwoposal Addwess (Optional)', //Proposal Address (Optional)
popupProposalDuration: 'Duwration in cycles', //Duration in cycles
popupProposalPerCycle: 'per cycle', //per cycle
popupProposalEncryptFirst:
'Yew need tew hit "{button}" before yew can cweate pwoposals!', //You need to hit "{button}" before you can create proposals!
popupProposalVoteHash: 'Vowote Hash:', //Vote Hash:
popupProposalFinalisedNote:
'<b>Congratsu on launching ur pwoposal DAO senpai!</b><br>Masternowode owners can use ur Vowote Hash to vowote from wawwets other than MPW, so make sure to add dis to ur forum post, if applicable!', //<b>Congratulations on launching your proposal!</b><br>Masternode owners can use your Vote Hash to vote from wallets other than MPW, so make sure to add this to your forum post, if applicable!
Expand Down
64 changes: 51 additions & 13 deletions scripts/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
importWallet,
decryptWallet,
} from './wallet.js';
import { LegacyMasterKey } from './masterkey.js';

Check warning on line 11 in scripts/global.js

View workflow job for this annotation

GitHub Actions / ESLint

scripts/global.js#L11

'LegacyMasterKey' is defined but never used (@typescript-eslint/no-unused-vars)
import { getNetwork, HistoricalTxType } from './network.js';
import {
start as settingsStart,
Expand Down Expand Up @@ -2766,47 +2766,85 @@
}

export async function createProposal() {
// Must have a wallet
if (!wallet.isLoaded()) {
return createAlert('warning', ALERTS.PROPOSAL_IMPORT_FIRST);
return createAlert('warning', ALERTS.PROPOSAL_IMPORT_FIRST, 4500);
}
// Wallet must be encrypted
if (!(await hasEncryptedWallet())) {
return createAlert(
'warning',
tr(translation.popupProposalEncryptFirst, [
{ button: translation.secureYourWallet },
]),
4500
);
}
// Wallet must be unlocked
if (
wallet.isViewOnly() &&
!(await restoreWallet(translation.walletUnlockProposal))
) {
return;
}
// Must have enough funds
if (getBalance() * COIN < cChainParams.current.proposalFee) {
return createAlert('warning', ALERTS.PROPOSAL_NOT_ENOUGH_FUNDS);
return createAlert('warning', ALERTS.PROPOSAL_NOT_ENOUGH_FUNDS, 4500);
}

// Create the popup, wait for the user to confirm or cancel
const fConfirmed = await confirmPopup({
title: `${translation.popupCreateProposal} (${
translation.popupCreateProposalCost
} ${cChainParams.current.proposalFee / COIN} ${
cChainParams.current.TICKER
})`,
html: `<input id="proposalTitle" maxlength="20" placeholder="${translation.popupProposalName}" style="text-align: center;"><br>
<input id="proposalUrl" maxlength="64" placeholder="${translation.popupExample} https://forum.pivx.org/..." style="text-align: center;"><br>
<input type="number" id="proposalCycles" placeholder="${translation.popupProposalDuration}" style="text-align: center;"><br>
<input type="number" id="proposalPayment" placeholder="${cChainParams.current.TICKER} ${translation.popupProposalPerCycle}" style="text-align: center;"><br>`,
html: `<input id="proposalTitle" maxlength="20" placeholder="${
translation.popupProposalName
}" style="text-align: center;"><br>
<input id="proposalUrl" maxlength="64" placeholder="${
translation.popupExample
} https://forum.pivx.org/..." style="text-align: center;"><br>
<input type="number" id="proposalCycles" min="1" max="${
cChainParams.current.maxPaymentCycles
}" placeholder="${
translation.popupProposalDuration
}" style="text-align: center;"><br>
<input type="number" id="proposalPayment" min="10" max="${
cChainParams.current.maxPayment / COIN
}" placeholder="${cChainParams.current.TICKER} ${
translation.popupProposalPerCycle
}" style="text-align: center;"><br>
<input id="proposalAddress" maxlength="34" placeholder="${
translation.popupProposalAddress
}" style="text-align: center; ${
!fAdvancedMode ? 'display: none' : ''
}"><br>`,
});

// If the user cancelled, then we return
if (!fConfirmed) return;

const strTitle = document.getElementById('proposalTitle').value;
const strUrl = document.getElementById('proposalUrl').value;
const numCycles = parseInt(document.getElementById('proposalCycles').value);
const strTitle = document.getElementById('proposalTitle').value.trim();
const strUrl = document.getElementById('proposalUrl').value.trim();
const numCycles = parseInt(
document.getElementById('proposalCycles').value.trim()
);
const numPayment = parseInt(
document.getElementById('proposalPayment').value
document.getElementById('proposalPayment').value.trim()
);

// If Advanced Mode is enabled and an address is given, use the provided address, otherwise, generate a new one
const strAddress =
document.getElementById('proposalAddress').value.trim() ||
(await wallet.getNewAddress())[0];
const nextSuperblock = await Masternode.getNextSuperblock();
const proposal = {
name: strTitle,
url: strUrl,
nPayments: numCycles,
start: nextSuperblock,
address: (await wallet.getNewAddress())[0],
address: strAddress,
monthlyPayment: numPayment * COIN,
};

Expand All @@ -2815,7 +2853,7 @@
createAlert(
'warning',
`${ALERTS.PROPOSAL_INVALID_ERROR} ${isValid.err}`,
5000
7500
);
return;
}
Expand All @@ -2836,7 +2874,7 @@

// Update the DB
await database.updateAccount(account);
createAlert('success', translation.PROPOSAL_CREATED, 7500);
createAlert('success', translation.PROPOSAL_CREATED, 10000);
updateGovernanceTab();
}
}
Expand Down
7 changes: 5 additions & 2 deletions scripts/masternode.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as nobleSecp256k1 from '@noble/secp256k1';
import { OP } from './script.js';
import bs58 from 'bs58';
import base32 from 'base32';
import { isStandardAddress } from './misc.js';

/**
* Construct a Masternode
Expand Down Expand Up @@ -579,7 +580,7 @@ export default class Masternode {
url,
nPayments,
_start,
_address,
address,
monthlyPayment,
}) {
const isSafeStr = /^[a-z0-9 .,;\-_/:?@()]+$/i;
Expand Down Expand Up @@ -620,7 +621,9 @@ export default class Masternode {
) {
return { ok: false, err: 'invalid_monthly_payment' };
}
// No need to validate start or address as they're generated by MPW
if (!isStandardAddress(address)) {
return { ok: false, err: 'invalid_address' };
}

return { ok: true };
}
Expand Down
Loading