Skip to content

Commit

Permalink
chore: update profile auth for governance (#2109)
Browse files Browse the repository at this point in the history
* update profile auth for governance

* update profile auth for consolidation + token burning

* fix

---------

Co-authored-by: Tuditi <[email protected]>
  • Loading branch information
MarkNerdi and Tuditi authored Mar 12, 2024
1 parent bf570ed commit 501a26a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { selectedAccount } from '@core/account/stores'
import { getStorageDepositFromOutput } from '@core/activity/utils/helper'
import { localize } from '@core/i18n'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { checkActiveProfileAuthAsync } from '@core/profile/actions'
import { consolidateOutputs } from '@core/wallet/actions/consolidateOutputs'
import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup'
import { CommonOutput, OutputType, UnlockCondition, UnlockConditionType } from '@iota/sdk/out/types'
Expand Down Expand Up @@ -50,30 +50,34 @@
let unavailableTotalAmount = $selectedAccount?.votingPower
for (const [outputId, unlocked] of Object.entries(accountBalance?.potentiallyLockedOutputs ?? {})) {
if (!unlocked) {
const output = (await $selectedAccount.getOutput(outputId)).output
let type: string
let amount: bigint
if (output.type !== OutputType.Treasury) {
const commonOutput = output as CommonOutput
if (containsUnlockCondition(commonOutput.unlockConditions, UnlockConditionType.Expiration)) {
type = UnavailableAmountType.Unclaimed
amount = BigInt(output.amount)
} else if (
containsUnlockCondition(commonOutput.unlockConditions, UnlockConditionType.StorageDepositReturn)
) {
type = UnavailableAmountType.StorageDepositReturn
amount = getStorageDepositFromOutput(commonOutput)
} else if (containsUnlockCondition(commonOutput.unlockConditions, UnlockConditionType.Timelock)) {
type = UnavailableAmountType.Timelock
amount = BigInt(output.amount)
}
}
if (unlocked) {
continue
}
const output = (await $selectedAccount.getOutput(outputId)).output
if (output.type === OutputType.Treasury) {
continue
}
subBreakdown[type] += amount
unavailableTotalAmount += amount
let type: string
let amount: bigint
const commonOutput = output as CommonOutput
if (containsUnlockCondition(commonOutput.unlockConditions, UnlockConditionType.Expiration)) {
type = UnavailableAmountType.Unclaimed
amount = BigInt(output.amount)
} else if (
containsUnlockCondition(commonOutput.unlockConditions, UnlockConditionType.StorageDepositReturn)
) {
type = UnavailableAmountType.StorageDepositReturn
amount = getStorageDepositFromOutput(commonOutput)
} else if (containsUnlockCondition(commonOutput.unlockConditions, UnlockConditionType.Timelock)) {
type = UnavailableAmountType.Timelock
amount = BigInt(output.amount)
}
subBreakdown[type] += amount
unavailableTotalAmount += amount
}
return { amount: unavailableTotalAmount, subBreakdown }
Expand Down Expand Up @@ -110,13 +114,14 @@
description: localize('popups.minimizeStorageDeposit.description'),
confirmText: localize('popups.minimizeStorageDeposit.confirmButton'),
onConfirm: async () => {
await checkActiveProfileAuth(
async () => {
await consolidateOutputs()
closePopup()
},
{ stronghold: true }
)
try {
await checkActiveProfileAuthAsync()
} catch (err) {
return
}
await consolidateOutputs()
closePopup()
},
},
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<script lang="ts">
import { Alert, Table } from '@bloomwalletio/ui'
import { selectedAccount } from '@core/account/stores'
import { handleError } from '@core/error/handlers'
import { localize } from '@core/i18n'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { checkActiveProfileAuthAsync } from '@core/profile/actions'
import { ITokenWithBalance, formatTokenAmountBestMatch } from '@core/token'
import { burnToken } from '@core/wallet'
import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup'
import { onMount } from 'svelte'
import PopupTemplate from '../PopupTemplate.svelte'
export let token: ITokenWithBalance
export let rawAmount: bigint
export let _onMount: (..._: any[]) => Promise<void> = async () => {}
$: formattedAmount = formatTokenAmountBestMatch(rawAmount, token?.metadata)
Expand All @@ -25,25 +22,14 @@
async function onBurnTokenClick(): Promise<void> {
try {
await checkActiveProfileAuth(
async () => {
await burnToken(token.id, rawAmount)
closePopup()
},
{ stronghold: true }
)
await checkActiveProfileAuthAsync()
} catch (err) {
console.error(err)
return
}
}
onMount(async () => {
try {
await _onMount()
} catch (err) {
handleError(err)
}
})
await burnToken(token.id, rawAmount)
closePopup()
}
</script>

<PopupTemplate
Expand Down
14 changes: 9 additions & 5 deletions packages/desktop/components/popup/popups/RevotePopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
import { vote } from '@contexts/governance/actions'
import { selectedAccount } from '@core/account/stores'
import { localize } from '@core/i18n'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { checkActiveProfileAuthAsync } from '@core/profile/actions'
import { closePopup } from '@desktop/auxiliary/popup'
import { PopupTemplate } from '@components/popup'
$: hasGovernanceTransactionInProgress =
$selectedAccount?.hasVotingPowerTransactionInProgress || $selectedAccount?.hasVotingTransactionInProgress
async function onSubmit(): Promise<void> {
await checkActiveProfileAuth(async () => {
await vote()
closePopup({ forceClose: true })
})
try {
await checkActiveProfileAuthAsync()
} catch (error) {
return
}
await vote()
closePopup({ forceClose: true })
}
function onCancelClick(): void {
Expand Down
14 changes: 9 additions & 5 deletions packages/desktop/components/popup/popups/StopVotingPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { selectedProposal } from '@contexts/governance/stores'
import { selectedAccount } from '@core/account/stores'
import { localize } from '@core/i18n'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { checkActiveProfileAuthAsync } from '@core/profile/actions'
import { closePopup } from '@desktop/auxiliary/popup'
import PopupTemplate from '../PopupTemplate.svelte'
Expand All @@ -16,10 +16,14 @@
}
async function onStopVotingClick(): Promise<void> {
await checkActiveProfileAuth(async () => {
await stopVotingForProposal($selectedProposal?.id)
closePopup()
})
try {
await checkActiveProfileAuthAsync()
} catch (error) {
return
}
await stopVotingForProposal($selectedProposal?.id)
closePopup()
}
</script>

Expand Down

0 comments on commit 501a26a

Please sign in to comment.