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

feat: add loading spinner #2412

Merged
merged 4 commits into from
Feb 23, 2022
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
35 changes: 27 additions & 8 deletions packages/shared/components/popups/GovernanceCastVote.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<script lang="typescript">
import { onMount } from 'svelte'
import { Button, Icon, Text } from 'shared/components'
import { Button, Icon, Spinner, Text } from 'shared/components'
import { localize } from 'shared/lib/i18n'
import { closePopup } from 'shared/lib/popup'
import { isSoftwareProfile } from 'shared/lib/profile'
import { selectedAccount, api } from 'shared/lib/wallet'
import { selectedAccount, api, isSyncing } from 'shared/lib/wallet'
import { participate, participateWithRemainingFunds, stopParticipating } from 'shared/lib/participation/api'
import { showAppNotification } from 'shared/lib/notifications'
import { openPopup } from 'shared/lib/popup'
import { isParticipationPending } from 'shared/lib/participation/stores'
import { isParticipationPending, pendingParticipations } from 'shared/lib/participation/stores'
import { ParticipationAction, VotingEventAnswer } from 'shared/lib/participation/types'
import { sleep } from 'shared/lib/utils'

Expand All @@ -24,10 +24,13 @@
}

let votingAction = VotingAction.Cast
let disabled = false
let isVoting = false
let successText = localize('popups.votingConfirmation.votesSubmitted')
let spinnerText = localize('general.syncing')

$: showAdditionalInfo = votingAction === VotingAction.Change || votingAction === VotingAction.Stop
$: disabled = isVoting || $isSyncing || $pendingParticipations?.length !== 0
$: disabled, setSpinnerMessage()

onMount(() => {
setVotingAction()
Expand All @@ -44,7 +47,7 @@
}

const castVote = async (): Promise<void> => {
disabled = true
isVoting = true
try {
await vote()
openPopup({
Expand All @@ -59,7 +62,7 @@
message: localize(err.error),
})
}
disabled = false
isVoting = false
}

const vote = async (): Promise<void> => {
Expand Down Expand Up @@ -129,6 +132,14 @@
void castVote()
}
}

const setSpinnerMessage = (): void => {
if ($isSyncing || $pendingParticipations.length !== 0) {
spinnerText = localize('general.syncing')
} else {
spinnerText = localize('general.broadcasting')
}
}
</script>

<div>
Expand All @@ -143,11 +154,19 @@
<div class="flex justify-between space-x-2">
<Button onClick={closePopup} secondary classes="mb-0 w-full block text-15">{localize('actions.cancel')}</Button>
<Button onClick={handleCastClick} {disabled} classes="mb-0 w-full block text-15">
{localize(`actions.${votingAction}`)}
{#if disabled}
<Spinner busy message={spinnerText} classes="mx-2 justify-center" />
{:else}
{localize(`actions.${votingAction}`)}
{/if}
</Button>
{#if votingAction === `${VotingAction.Merge}`}
<Button onClick={handleStopClick} {disabled} classes="mb-0 w-full block text-15">
{localize(`actions.${VotingAction.Stop}`)}
{#if disabled}
<Spinner busy message={spinnerText} classes="mx-2 justify-center" />
{:else}
{localize(`actions.${VotingAction.Stop}`)}
{/if}
</Button>
{/if}
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/lib/participation/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ export const STAKING_AIRDROP_TOKENS: { [key in StakingAirdrop]: string } = {
*/
export const PARTICIPATION_POLL_DURATION = 10 * MILLISECONDS_PER_SECOND

export const TREASURY_VOTE_EVENT_ID = 'b0cd7ac16c22c12fecad5a9f5c92fb11c84a07a708dd77581d8eb33675723926'
export const TREASURY_VOTE_EVENT_ID = '16d2eb8aada8bff94d98bd0cb59b33e8e8fde97b09b4712876c4a80523e24d43'