diff --git a/scripts/dashboard/Dashboard.vue b/scripts/dashboard/Dashboard.vue index 2b55ac793..4b4211871 100644 --- a/scripts/dashboard/Dashboard.vue +++ b/scripts/dashboard/Dashboard.vue @@ -896,6 +896,7 @@ defineExpose({ diff --git a/scripts/governance/Governance.vue b/scripts/governance/Governance.vue index f120ebca5..2129ed608 100644 --- a/scripts/governance/Governance.vue +++ b/scripts/governance/Governance.vue @@ -4,12 +4,22 @@ import { watch, ref, computed } from 'vue'; import { cOracle } from '../prices'; import { ProposalValidator } from './status'; import { blockCount } from '../global'; +import { useWallet } from '../composables/use_wallet'; import Masternode from '../masternode.js'; import ProposalsTable from './ProposalsTable.vue'; import Flipdown from './Flipdown.vue'; +import ProposalCreateModal from './ProposalCreateModal.vue'; +import { hasEncryptedWallet } from '../wallet'; +import { createAlert } from '../misc'; +import { ALERTS, tr, translation } from '../i18n'; +import { Database } from '../database'; +import { storeToRefs } from 'pinia'; +import { useSettings } from '../composables/use_settings'; +import { getNetwork } from '../network'; const strCurrency = 'usd'; const price = ref(0); +const showCreateProposalModal = ref(false); watch( strCurrency, async () => { @@ -18,6 +28,9 @@ watch( { immediate: true } ); +const wallet = useWallet(); +const settings = useSettings(); +const { advancedMode } = storeToRefs(settings); const proposals = ref([]); const contestedProposals = ref([]); const nextSuperBlock = ref(0); @@ -160,9 +173,9 @@ function addProposalToFinalisationCache(cProposal) { return cPropCache; } -async function createProposal() { +async function openCreateProposal() { // Must have a wallet - if (!wallet.isLoaded()) { + if (!wallet.isImported) { return createAlert('warning', ALERTS.PROPOSAL_IMPORT_FIRST, 4500); } // Wallet must be encrypted @@ -175,109 +188,47 @@ async function createProposal() { 4500 ); } - // Wallet must be unlocked - if ( - wallet.isViewOnly() && - !(await restoreWallet(translation.walletUnlockProposal)) - ) { - return; - } // Must have enough funds if (wallet.balance * COIN < cChainParams.current.proposalFee) { 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: `
-

Proposal name

-
- -

URL

-
- -

Duration in cycles

-
- -

${ - cChainParams.current.TICKER - } per cycle

- ${ - !fAdvancedMode ? '
' : '' - } - -

Proposal Address

- -
`, - wideModal: true, - }); - - // If the user cancelled, then we return - if (!fConfirmed) return; - - 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.trim() - ); + showCreateProposalModal.value = true; +} - // 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() || - wallet.getNewAddress(1)[0]; - const nextSuperblock = await Masternode.getNextSuperblock(); +async function createProposal(name, url, payments, monthlyPayment, address) { + debugger; + address = address || wallet.getNewAddress(1)[0]; + const start = await Masternode.getNextSuperblock(); const proposal = { - name: strTitle, - url: strUrl, - nPayments: numCycles, - start: nextSuperblock, - address: strAddress, - monthlyPayment: numPayment * COIN, + name, + url, + nPayments: payments, + start, + address, + monthlyPayment: monthlyPayment * COIN, }; - - const isValid = Masternode.isValidProposal(proposal); - if (!isValid.ok) { + const validation = Masternode.isValidProposal(proposal); + if (!validation.ok) { createAlert( 'warning', - `${ALERTS.PROPOSAL_INVALID_ERROR} ${isValid.err}`, + `${ALERTS.PROPOSAL_INVALID_ERROR} ${validation.err}`, 7500 ); return; } - const hash = Masternode.createProposalHash(proposal); - const { ok, txid } = await createAndSendTransaction({ - address: hash, - amount: cChainParams.current.proposalFee, - isProposal: true, - }); + const { ok, txid } = await wallet.createAndSendTransaction( + getNetwork(), + hash, + cChainParams.current.proposalFee, + { + isProposal: true, + } + ); if (ok) { proposal.txid = txid; + // TODO: Update database using vue reactivity const database = await Database.getInstance(); // Fetch our Account, add the proposal to it @@ -287,12 +238,18 @@ async function createProposal() { // Update the DB await database.updateAccount(account); createAlert('success', translation.PROPOSAL_CREATED, 10000); - updateGovernanceTab(); + showCreateProposalModal.value = false; } }