Skip to content

Commit

Permalink
Add restore wallet when creating a proposal (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
Duddino authored Jan 3, 2025
1 parent 8bebc13 commit 81a6de9
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion scripts/governance/Governance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ProposalValidator } from './status';
import { useWallet } from '../composables/use_wallet';
import Masternode from '../masternode.js';
import ProposalsTable from './ProposalsTable.vue';
import RestoreWallet from '../dashboard/RestoreWallet.vue';
import Flipdown from './Flipdown.vue';
import ProposalCreateModal from './ProposalCreateModal.vue';
import MonthlyBudget from './MonthlyBudget.vue';
Expand All @@ -25,7 +26,12 @@ const wallet = useWallet();
const settings = useSettings();
const { localProposals, masternode } = storeToRefs(useMasternode());
const { advancedMode } = storeToRefs(settings);
const { blockCount, currency: strCurrency, price } = storeToRefs(wallet);
const {
blockCount,
currency: strCurrency,
price,
isViewOnly,
} = storeToRefs(wallet);
const proposals = ref([]);
const contestedProposals = ref([]);
const nextSuperBlock = ref(0);
Expand All @@ -44,6 +50,8 @@ const allocatedBudget = computed(() => {
const flipdownTimeStamp = computed(
() => Date.now() / 1000 + (nextSuperBlock.value - blockCount.value) * 60
);
const showRestoreWallet = ref(false);
const restoreWalletReason = ref('');
// Each block update check if we have local proposals to update or finalize
watch(
Expand Down Expand Up @@ -74,6 +82,22 @@ watch(
{ immediate: true }
);
async function restoreWallet(strReason) {
if (!wallet.isEncrypted) return false;
if (wallet.isHardwareWallet) return true;
showRestoreWallet.value = true;
return await new Promise((res) => {
watch(
[showRestoreWallet, isViewOnly],
() => {
showRestoreWallet.value = false;
res(!isViewOnly.value);
},
{ once: true }
);
});
}
async function fetchProposals() {
const arrProposals = await getNetwork().getProposals({
fAllowFinished: false,
Expand Down Expand Up @@ -113,6 +137,10 @@ async function openCreateProposal() {
4500
);
}
// Ensure the wallet is unlocked
if (wallet.isViewOnly && !(await restoreWallet())) {
return;
}
// Must have enough funds
if (wallet.balance * COIN < cChainParams.current.proposalFee) {
return createAlert('warning', ALERTS.PROPOSAL_NOT_ENOUGH_FUNDS, 4500);
Expand Down Expand Up @@ -295,4 +323,10 @@ async function vote(proposal, voteCode) {
@vote="vote"
/>
</div>
<RestoreWallet
:show="showRestoreWallet"
:reason="restoreWalletReason"
:wallet="wallet"
@close="showRestoreWallet = false"
/>
</template>

0 comments on commit 81a6de9

Please sign in to comment.