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: revote flow with ledger #6019

Merged
merged 17 commits into from Mar 6, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,6 @@
<script lang="ts">
import { Text, Icon } from 'shared/components'
import { Text, Icon, TextType } from 'shared/components'
import { Icon as IconEnum } from '@auxiliary/icon'
import { localize } from '@core/i18n'
import {
checkOrConnectLedger,
Expand All @@ -17,29 +18,31 @@
closePopup()
checkOrConnectLedger(async () => {
try {
await sendOutput($ledgerPreparedOutput)
resetLedgerPreparedOutput()
if ($ledgerPreparedOutput) {
await sendOutput($ledgerPreparedOutput)
resetLedgerPreparedOutput()
}
} catch (err) {
handleError(err)
}
})
}
</script>

<Text type="h3" classes="mb-6">{localize('popups.enableLedgerBlindSigning.title')}</Text>
<Text type={TextType.h3} classes="mb-6">{localize('popups.enableLedgerBlindSigning.title')}</Text>

<div class="w-full h-full space-y-2 flex flex-auto flex-col flex-shrink-0">
<div class="bg-yellow-50 w-full h-full space-y-6 rounded-md px-6 py-4">
<span class="flex flex-row items-center space-x-4">
<Icon boxed height={18} width={18} icon="info-filled" classes="text-yellow-700" />
<Text type="p" fontSize="14" color="gray-700" darkColor="gray-700"
<Icon boxed height={18} width={18} icon={IconEnum.InfoFilled} classes="text-yellow-700" />
<Text type={TextType.p} fontSize="14" color="gray-700" darkColor="gray-700"
>{localize('popups.enableLedgerBlindSigning.info')}</Text
>
</span>
</div>
<div>
{#each STEPS as step}
<Text type="p" fontSize="15" color="gray-600" classes="my-2">
<Text type={TextType.p} fontSize="15" color="gray-600" classes="my-2">
{step}. {localize(`popups.enableLedgerBlindSigning.step_${step}`)}
</Text>
{/each}
Expand Down
40 changes: 18 additions & 22 deletions packages/desktop/components/popups/ManageVotingPowerPopup.svelte
Expand Up @@ -9,10 +9,8 @@
import { convertToRawAmount, visibleSelectedAccountAssets } from '@core/wallet'
import { closePopup, openPopup } from '@auxiliary/popup/actions'
import { popupState } from '@auxiliary/popup/stores'
import { hasToRevote, hasPendingGovernanceTransaction } from '@contexts/governance/stores'
import { onMount } from 'svelte'
import { modifyPopupState } from '@auxiliary/popup/helpers'
import { isSelectedAccountVoting } from '@contexts/governance/utils'
import { isAccountVoting } from '@contexts/governance/utils'
import { PopupId } from '@auxiliary/popup'

export let _onMount: (..._: any[]) => Promise<void> = async () => {}
Expand All @@ -25,18 +23,19 @@

$: asset = $visibleSelectedAccountAssets?.baseCoin
$: votingPower = parseInt($selectedAccount?.votingPower, 10)
$: isTransferring = $hasPendingGovernanceTransaction?.[$selectedAccount.index] || $selectedAccount?.isTransferring
$: disabled = $hasToRevote || isTransferring

$: amount, disabled, setConfirmDisabled()
$: hasTransactionInProgress =
$selectedAccount?.hasVotingPowerTransactionInProgress ||
$selectedAccount?.hasVotingTransactionInProgress ||
$selectedAccount?.isTransferring
$: amount, hasTransactionInProgress, setConfirmDisabled()

function setConfirmDisabled(): void {
if (disabled || !amount) {
if (!amount) {
confirmDisabled = true
return
}
const convertedSliderAmount = convertToRawAmount(amount, asset?.metadata).toString()
confirmDisabled = convertedSliderAmount === $selectedAccount?.votingPower || isTransferring
confirmDisabled = convertedSliderAmount === $selectedAccount?.votingPower || hasTransactionInProgress
}

function onCancelClick(): void {
Expand All @@ -47,8 +46,7 @@
try {
await assetAmountInput?.validate(true)

const isVoting = isSelectedAccountVoting()
if (amount === '0' && isVoting) {
if (amount === '0' && isAccountVoting($selectedAccount.index)) {
openPopup({ id: PopupId.VotingPowerToZero })
return
}
Expand All @@ -58,7 +56,7 @@

await checkActiveProfileAuth(
async () => {
await setVotingPower(rawAmount, isVoting)
await setVotingPower(rawAmount)
},
{ stronghold: true, ledger: false }
)
Expand All @@ -68,16 +66,9 @@
}

onMount(async () => {
disabled = true
try {
await _onMount()
if ($hasToRevote) {
modifyPopupState({ ...$popupState, preventClose: true, hideClose: true })
} else {
disabled = $selectedAccount?.isTransferring
}
} catch (err) {
disabled = false
handleError(err)
}
})
Expand All @@ -94,16 +85,21 @@
{asset}
containsSlider
disableAssetSelection
{disabled}
disabled={hasTransactionInProgress}
{votingPower}
/>
<TextHint info text={localize('popups.manageVotingPower.hint')} />
</div>
<div class="flex flex-row flex-nowrap w-full space-x-4">
<Button outline disabled={isTransferring} classes="w-full" onClick={onCancelClick}>
<Button outline disabled={hasTransactionInProgress} classes="w-full" onClick={onCancelClick}>
{localize('actions.cancel')}
</Button>
<Button type={HTMLButtonType.Submit} disabled={confirmDisabled} isBusy={isTransferring} classes="w-full">
<Button
type={HTMLButtonType.Submit}
disabled={confirmDisabled}
isBusy={hasTransactionInProgress}
classes="w-full"
>
{localize('actions.confirm')}
</Button>
</div>
Expand Down
16 changes: 8 additions & 8 deletions packages/desktop/components/popups/RevotePopup.svelte
Expand Up @@ -4,29 +4,29 @@
import { localize } from '@core/i18n'
import { closePopup } from '@auxiliary/popup/actions'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { onDestroy } from 'svelte'
import { hasPendingGovernanceTransaction, hasToRevote } from '@contexts/governance/stores'
import { vote } from '@contexts/governance/actions'

$: disabled = $hasPendingGovernanceTransaction?.[$selectedAccount.index]
$: hasGovernanceTransactionInProgress =
$selectedAccount?.hasVotingPowerTransactionInProgress || $selectedAccount?.hasVotingTransactionInProgress

async function onSubmit(): Promise<void> {
await checkActiveProfileAuth(async () => {
await vote()
closePopup(true)
})
}

onDestroy(() => {
$hasToRevote = false
})
</script>

<form id="manage-voting-power" class="space-y-5" on:submit|preventDefault={onSubmit}>
<Text type={TextType.h4} classes="mb-3">{localize('popups.revote.title')}</Text>
<Text type={TextType.p}>{localize('popups.revote.body')}</Text>
<TextHint info text={localize('popups.revote.hint')} />
<Button type={HTMLButtonType.Submit} {disabled} isBusy={disabled} classes="w-full">
<Button
type={HTMLButtonType.Submit}
disabled={hasGovernanceTransactionInProgress}
isBusy={hasGovernanceTransactionInProgress}
classes="w-full"
>
{localize('actions.revote')}
</Button>
</form>
11 changes: 6 additions & 5 deletions packages/desktop/components/popups/StopVotingPopup.svelte
Expand Up @@ -3,12 +3,13 @@
import { ButtonVariant } from 'shared/components/enums'
import { closePopup } from '@auxiliary/popup/actions'
import { stopVotingForProposal } from '@contexts/governance/actions'
import { hasPendingGovernanceTransaction, selectedProposal } from '@contexts/governance/stores'
import { selectedProposal } from '@contexts/governance/stores'
import { localize } from '@core/i18n'
import { selectedAccount } from '@core/account/stores'
import { checkActiveProfileAuth } from '@core/profile/actions'

$: isTransferring = $hasPendingGovernanceTransaction?.[$selectedAccount.index]
$: hasGovernanceTransactionInProgress =
$selectedAccount?.hasVotingPowerTransactionInProgress || $selectedAccount?.hasVotingTransactionInProgress

function onCancelClick(): void {
closePopup()
Expand All @@ -31,15 +32,15 @@
<TextHint info text={localize('popups.stopVoting.hint')} />
</div>
<div class="flex w-full space-x-4 mt-6">
<Button outline classes="w-full" disabled={isTransferring} onClick={onCancelClick}
<Button outline classes="w-full" disabled={hasGovernanceTransactionInProgress} onClick={onCancelClick}
>{localize('actions.cancel')}</Button
>
<Button
variant={ButtonVariant.Primary}
classes="w-full"
onClick={onStopVotingClick}
disabled={isTransferring}
isBusy={isTransferring}
disabled={hasGovernanceTransactionInProgress}
isBusy={hasGovernanceTransactionInProgress}
>
{localize('actions.stopVoting')}</Button
>
Expand Down
14 changes: 10 additions & 4 deletions packages/desktop/components/popups/VoteForProposalPopup.svelte
Expand Up @@ -10,7 +10,7 @@
import { formatTokenAmountBestMatch } from '@core/wallet/utils'
import { vote } from '@contexts/governance/actions'
import { ABSTAIN_VOTE_VALUE } from '@contexts/governance/constants'
import { hasPendingGovernanceTransaction, selectedProposal } from '@contexts/governance/stores'
import { selectedProposal } from '@contexts/governance/stores'
import { PopupId } from '@auxiliary/popup'

export let selectedAnswerValues: number[]
Expand All @@ -21,7 +21,8 @@
)
$: hasVotingPower = Number($selectedAccount?.votingPower) > 0

$: isTransferring = $hasPendingGovernanceTransaction?.[$selectedAccount.index]
$: hasGovernanceTransactionInProgress =
$selectedAccount?.hasVotingPowerTransactionInProgress || $selectedAccount?.hasVotingTransactionInProgress

$: numberOfAbstainedQuestions =
selectedAnswerValues?.filter((answerValue) => answerValue === ABSTAIN_VOTE_VALUE).length ?? 0
Expand Down Expand Up @@ -67,10 +68,15 @@
{/if}
</div>
<popup-buttons class="flex flex-row flex-nowrap w-full space-x-4">
<Button classes="w-full" disabled={isTransferring} outline onClick={closePopup}
<Button classes="w-full" disabled={hasGovernanceTransactionInProgress} outline onClick={closePopup}
>{localize('actions.cancel')}</Button
>
<Button type={HTMLButtonType.Submit} classes="w-full" disabled={isTransferring} isBusy={isTransferring}>
<Button
type={HTMLButtonType.Submit}
classes="w-full"
disabled={hasGovernanceTransactionInProgress}
isBusy={hasGovernanceTransactionInProgress}
>
{hasVotingPower ? localize('actions.vote') : localize('views.governance.votingPower.manage')}
</Button>
</popup-buttons>
Expand Down
Expand Up @@ -4,7 +4,6 @@
import { selectedAccount } from '@core/account/stores'
import { handleError } from '@core/error/handlers'
import { setVotingPower } from '@contexts/governance/actions'
import { hasPendingGovernanceTransaction } from '@contexts/governance/stores'
import { localize } from '@core/i18n'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { closePopup, openPopup } from '@auxiliary/popup/actions'
Expand All @@ -13,7 +12,8 @@

const ZERO_VOTING_POWER = '0'

$: isTransferring = $hasPendingGovernanceTransaction?.[$selectedAccount.index]
$: isTransferring =
$selectedAccount?.hasVotingPowerTransactionInProgress || $selectedAccount?.hasVotingTransactionInProgress

function onCancelClick(): void {
closePopup()
Expand Down
Expand Up @@ -21,7 +21,6 @@
import { ABSTAIN_VOTE_VALUE } from '@contexts/governance/constants'
import { ProposalStatus } from '@contexts/governance/enums'
import {
hasPendingGovernanceTransaction,
selectedProposal,
updateParticipationOverview,
participationOverviewForSelectedAccount,
Expand Down Expand Up @@ -82,7 +81,8 @@
!isProposalVotable($selectedProposal?.status) ||
!hasChangedAnswers(selectedAnswerValues) ||
hasSelectedNoAnswers(selectedAnswerValues)
$: isTransferring = $hasPendingGovernanceTransaction?.[$selectedAccountIndex]
$: hasGovernanceTransactionInProgress =
$selectedAccount?.hasVotingPowerTransactionInProgress || $selectedAccount?.hasVotingTransactionInProgress
$: $selectedParticipationEventStatus, (textHintString = getTextHintString())

function hasSelectedNoAnswers(_selectedAnswerValues: number[]): boolean {
Expand Down Expand Up @@ -284,13 +284,14 @@
outline
classes="w-full"
onClick={onStopVotingClick}
disabled={!isVotingForProposal || isTransferring}
isBusy={isVotingForProposal && isTransferring}>{localize('actions.stopVoting')}</Button
disabled={!isVotingForProposal || hasGovernanceTransactionInProgress}
isBusy={isVotingForProposal && hasGovernanceTransactionInProgress}
>{localize('actions.stopVoting')}</Button
>
<Button
classes="w-full"
disabled={isVotingDisabled || isTransferring}
isBusy={isTransferring}
disabled={isVotingDisabled || hasGovernanceTransactionInProgress}
isBusy={hasGovernanceTransactionInProgress}
onClick={onVoteClick}
>
{localize('actions.vote')}
Expand Down
5 changes: 3 additions & 2 deletions packages/shared/components/ProposalsDetails.svelte
@@ -1,5 +1,5 @@
<script lang="ts">
import { Text, KeyValueBox, Button, ButtonSize } from 'shared/components'
import { Text, KeyValueBox, Button, ButtonSize, ProposalsDetailsButton } from 'shared/components'
import { FontWeight } from './enums'
import { localize } from '@core/i18n'
import { activeProfileId } from '@core/profile'
Expand Down Expand Up @@ -58,10 +58,11 @@
</script>

<proposals-details class="space-y-4">
<header-container class="flex justify-left items-center">
<header-container class="flex justify-between items-center">
<Text fontSize="14" fontWeight={FontWeight.semibold}>
{localize('views.governance.proposalsDetails.title')}
</Text>
<ProposalsDetailsButton />
</header-container>
<ul class="space-y-2">
{#each Object.keys(details) as detailKey}
Expand Down
10 changes: 6 additions & 4 deletions packages/shared/components/VotingPower.svelte
Expand Up @@ -5,15 +5,17 @@
import { localize } from '@core/i18n'
import { formatTokenAmountBestMatch, visibleSelectedAccountAssets } from '@core/wallet'
import { openPopup, PopupId } from '@auxiliary/popup'
import { hasPendingGovernanceTransaction } from '@contexts/governance/stores'

const asset = $visibleSelectedAccountAssets?.baseCoin

$: votingPower = parseInt($selectedAccount?.votingPower, 10)
$: maxVotingPower = parseInt($selectedAccount?.balances?.baseCoin?.available) + votingPower
$: formattedVotingPower = formatTokenAmountBestMatch(votingPower, asset?.metadata)
$: formattedMaxVotingPower = formatTokenAmountBestMatch(maxVotingPower, asset?.metadata)
$: isTransferring = $hasPendingGovernanceTransaction?.[$selectedAccount.index] || $selectedAccount?.isTransferring
$: hasTransactionInProgress =
$selectedAccount?.hasVotingPowerTransactionInProgress ||
$selectedAccount?.hasVotingTransactionInProgress ||
$selectedAccount?.isTransferring

function handleManageVotingPower(): void {
openPopup({
Expand All @@ -34,8 +36,8 @@
size={ButtonSize.Medium}
onClick={handleManageVotingPower}
classes="w-full"
disabled={isTransferring}
isBusy={isTransferring}
disabled={hasTransactionInProgress}
isBusy={hasTransactionInProgress}
>
{localize('views.governance.votingPower.manage')}
</Button>
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/components/atoms/LedgerAnimation.svelte
@@ -1,8 +1,8 @@
<script lang="ts">
import { Animation, Illustration } from 'shared/components'

export let animation: string
export let illustration: string
export let animation: string = undefined
export let illustration: string = undefined
export let classes: string = ''
export let bgClasses: string = ''
</script>
Expand Down
10 changes: 10 additions & 0 deletions packages/shared/components/atoms/ProposalsDetailsButton.svelte
@@ -0,0 +1,10 @@
<script lang="typescript">
import { Modal, ProposalsDetailsMenu, MeatballMenuButton } from 'shared/components'

let modal: Modal
</script>

<div class="max-h-7 max-w-9 flex-none flex-initial overflow-visible relative">
<MeatballMenuButton onClick={modal?.toggle} />
<ProposalsDetailsMenu bind:modal position={{ right: '0' }} classes="mt-1.5" />
</div>
1 change: 1 addition & 0 deletions packages/shared/components/atoms/index.js
Expand Up @@ -16,5 +16,6 @@ export { default as MediaDisplay } from './MediaDisplay.svelte'
export { default as MenuItem } from './MenuItem.svelte'
export { default as NetworkIcon } from './NetworkIcon.svelte'
export { default as Pane } from './Pane.svelte'
export { default as ProposalsDetailsButton } from './ProposalsDetailsButton.svelte'
export { default as SubjectBox } from './SubjectBox.svelte'
export { default as Tabs } from './Tabs.svelte'