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: create a delegation popup logic #8082

Merged
merged 33 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5e7d764
feat: add Delegation view UI
cpl121 Feb 20, 2024
c5b2a2a
Merge branches 'feat/add-delegation-view' and 'develop-iota2.0' of gi…
cpl121 Feb 20, 2024
4a3b0bc
Merge branches 'feat/add-delegation-view' and 'develop-iota2.0' of gi…
cpl121 Feb 20, 2024
8b0a3c1
feat: add header translations
cpl121 Feb 20, 2024
cd57815
fix: styles
cpl121 Feb 20, 2024
eb3fd0d
style: make tbody scrollable
cpl121 Feb 20, 2024
913a084
feat: create a delegation popup UI
cpl121 Feb 21, 2024
f0ddb45
feat: create a delegation popup logic WIP
cpl121 Feb 21, 2024
b6e2243
fix: styles
cpl121 Feb 21, 2024
793f3e5
fix: add fixed height in the table tag
cpl121 Feb 21, 2024
8823cdc
Merge branch 'develop-iota2.0' into feat/add-delegation-view
cpl121 Feb 22, 2024
3df30e4
Merge branch 'develop-iota2.0' into feat/add-delegation-view
cpl121 Feb 22, 2024
70f5820
Merge branches 'feat/add-delegation-view' and 'develop-iota2.0' of gi…
cpl121 Feb 22, 2024
6a9853c
Merge branches 'feat/add-create-delegation-popup' and 'feat/add-deleg…
cpl121 Feb 22, 2024
ab3415a
Merge branches 'feat/create-delegation-popup-logic' and 'feat/add-cre…
cpl121 Feb 22, 2024
06f49a2
fix: verify inputs
cpl121 Feb 22, 2024
bf43c17
Merge branch 'develop-iota2.0' into feat/add-delegation-view
cpl121 Feb 23, 2024
8907b45
Merge branch 'feat/add-delegation-view' into feat/add-create-delegati…
cpl121 Feb 23, 2024
e96e1f5
Merge branch 'feat/add-create-delegation-popup' into feat/create-dele…
cpl121 Feb 23, 2024
8cddef6
Merge branch 'develop-iota2.0' into feat/add-delegation-view
cpl121 Feb 23, 2024
f6853fe
Merge branch 'feat/add-delegation-view' into feat/add-create-delegati…
cpl121 Feb 23, 2024
3b4f30e
Merge branches 'feat/add-create-delegation-popup' and 'develop-iota2.…
cpl121 Feb 26, 2024
c13f4d9
Merge branches 'feat/create-delegation-popup-logic' and 'feat/add-cre…
cpl121 Feb 26, 2024
20c4383
Merge branches 'feat/create-delegation-popup-logic' and 'develop-iota…
cpl121 Feb 27, 2024
e87feab
feat: update literals
cpl121 Feb 27, 2024
b7e2328
Merge branches 'feat/create-delegation-popup-logic' and 'develop-iota…
cpl121 Feb 27, 2024
faccc5d
Merge branches 'feat/create-delegation-popup-logic' and 'develop-iota…
cpl121 Feb 27, 2024
0b928ad
Merge branches 'feat/create-delegation-popup-logic' and 'develop-iota…
cpl121 Feb 27, 2024
f4c322e
fix: minor improvements
cpl121 Feb 27, 2024
cbbd15e
feat: create a delegation popup logic
cpl121 Feb 28, 2024
6c412c1
fix: add TODO comment
cpl121 Feb 28, 2024
f6c1dc5
Merge remote-tracking branch 'origin/develop-iota2.0' into feat/creat…
begonaalvarezd Feb 29, 2024
fee007a
fix: error type and form reactivity
cpl121 Mar 1, 2024
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
66 changes: 52 additions & 14 deletions packages/desktop/components/popups/CreateDelegationPopup.svelte
Original file line number Diff line number Diff line change
@@ -1,37 +1,67 @@
<script lang="ts">
import { closePopup } from '@auxiliary/popup'
import { closePopup, updatePopupProps } from '@auxiliary/popup'
import { api } from '@core/api'
import { handleError } from '@core/error/handlers'
import { localize } from '@core/i18n'
import { activeProfile } from '@core/profile'
import { convertToRawAmount, selectedWallet, visibleSelectedWalletAssets } from '@core/wallet'
import { activeProfile, checkActiveProfileAuth, getNetworkHrp, updateActiveWallet } from '@core/profile'
import {
convertToRawAmount,
getDefaultTransactionOptions,
selectedWallet,
selectedWalletId,
visibleSelectedWalletAssets,
} from '@core/wallet'
import { AccountAddress, CreateDelegationParams } from '@iota/sdk/out/types'
import { Text, TextType, AssetAmountInput, TextInput, Button, HTMLButtonType } from '@ui'
import { onMount } from 'svelte'

export let _onMount: (..._: any[]) => Promise<void> = async () => {}
export let rawAmount: string = $selectedWallet?.balances?.baseCoin?.available?.toString()
export let accountAddress: string

let assetAmountInput: AssetAmountInput
let amount: string
let accountId: string
let rawAmount = $selectedWallet.balances.baseCoin.available.toString()
let confirmDisabled = false

$: asset = $visibleSelectedWalletAssets[$activeProfile?.network.id].baseCoin
$: asset = $visibleSelectedWalletAssets[$activeProfile?.network?.id].baseCoin
$: hasTransactionInProgress =
$selectedWallet?.hasConsolidatingOutputsTransactionInProgress || $selectedWallet?.isTransferring
$: amount, hasTransactionInProgress, setConfirmDisabled()
$selectedWallet?.hasConsolidatingOutputsTransactionInProgress ||
$selectedWallet?.hasDelegationTransactionInProgress ||
$selectedWallet?.isTransferring
$: amount, accountAddress, hasTransactionInProgress, setConfirmDisabled()

function setConfirmDisabled(): void {
if (!amount) {
if (!amount || !accountAddress) {
confirmDisabled = true
return
}
const convertedSliderAmount = convertToRawAmount(amount, asset?.metadata)?.toString()
confirmDisabled =
convertedSliderAmount === $selectedWallet.balances.baseCoin.available.toString() || hasTransactionInProgress
confirmDisabled = convertedSliderAmount === rawAmount || hasTransactionInProgress
}

async function onSubmit(): Promise<void> {
try {
await assetAmountInput?.validate(true)
if (!amount || !accountId) return
// TODO: Add logic in other PR
if (!rawAmount || !accountAddress) return
updatePopupProps({ rawAmount, accountAddress })
await checkActiveProfileAuth(delegate, { stronghold: true, ledger: false })
} catch (err) {
handleError(err)
}
}

async function delegate(): Promise<void> {
try {
const params: CreateDelegationParams = {
address: api.accountIdToBech32($selectedWallet.mainAccountId, getNetworkHrp()),
delegatedAmount: rawAmount,
validatorAddress: new AccountAddress(api.bech32ToHex(accountAddress)),
}
await $selectedWallet.createDelegation(params, getDefaultTransactionOptions())
updateActiveWallet($selectedWalletId, {
hasDelegationTransactionInProgress: true,
isTransferring: true,
})
} catch (err) {
handleError(err)
}
Expand All @@ -40,6 +70,14 @@
function onCancelClick(): void {
closePopup()
}

onMount(async () => {
try {
await _onMount()
} catch (err) {
handleError(err.error)
}
})
</script>

<create-delegation-popup class="flex flex-col space-y-6">
Expand All @@ -57,7 +95,7 @@
disabled={hasTransactionInProgress}
/>
<TextInput
bind:value={accountId}
bind:value={accountAddress}
placeholder={localize('popups.createDelegation.account.title')}
label={localize('popups.createDelegation.account.description')}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
}

$: delegationOutputs =
$selectedWallet.walletOutputs.filter((output) => output?.output?.type === OutputType.Delegation) || []
$selectedWallet?.walletOutputs?.filter((output) => output?.output?.type === OutputType.Delegation) || []
$: delegationOutputs?.length > 0 && mappedDelegationData(delegationOutputs)
$: ({ baseCoin } = $selectedWalletAssets[$activeProfile?.network.id])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export async function buildWalletState(
hasVotingTransactionInProgress: false,
hasConsolidatingOutputsTransactionInProgress: false,
hasImplicitAccountCreationTransactionInProgress: false,
hasDelegationTransactionInProgress: false,
isTransferring: false,
votingPower,
walletOutputs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getOrRequestAssetFromPersistedAssets,
hasBlockIssuerFeature,
isAccountOutput,
isDelegationOutput,
isImplicitAccountOutput,
preprocessGroupedOutputs,
syncBalance,
Expand Down Expand Up @@ -54,6 +55,7 @@ export async function handleNewOutputEventInternal(walletId: string, payload: Ne
if (
(address && wallet?.depositAddress === address && !outputData?.remainder) ||
isAccountOutput(outputData) ||
isDelegationOutput(outputData) ||
isBasicOutput
) {
await syncBalance(wallet.id, true)
Expand Down Expand Up @@ -105,6 +107,17 @@ export async function handleNewOutputEventInternal(walletId: string, payload: Ne
closePopup() // close ActivateAccountPopup when the account output is created
}
}

// TODO: update this logic when available balance is fixed
if (isDelegationOutput(outputData)) {
if (wallet?.hasDelegationTransactionInProgress) {
updateActiveWallet(walletId, {
hasDelegationTransactionInProgress: false,
isTransferring: false,
})
closePopup() // close CreateDelegationPopup when the account output is created
}
}
if (isNftOutput) {
const wrappedOutput = outputData as unknown as IWrappedOutput
const nft = buildNftFromNftOutput(wrappedOutput, wallet.depositAddress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface IWalletState extends IWallet, IPersistedWalletData {
hasVotingTransactionInProgress: boolean
hasConsolidatingOutputsTransactionInProgress: boolean
hasImplicitAccountCreationTransactionInProgress: boolean
hasDelegationTransactionInProgress: boolean
votingPower: string
walletOutputs: OutputData[]
accountOutputs: OutputData[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export function getDefaultTransactionOptions(
value: new AccountAddress(accountId),
},
allowMicroAmount: true,
allowAllottingFromAccountMana: true,
}
}
1 change: 1 addition & 0 deletions packages/shared/lib/core/wallet/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export * from './getSubjectFromAddress'
export * from './getTokenFromSelectedWallet'
export * from './getUnitFromTokenMetadata'
export * from './isAccountOutput'
export * from './isDelegationOutput'
export * from './isImplicitAccountOutput'
export * from './isReservedTagKeyword'
export * from './isSubjectInternal'
Expand Down
5 changes: 5 additions & 0 deletions packages/shared/lib/core/wallet/utils/isDelegationOutput.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { OutputData, OutputType } from '@iota/sdk/out/types'

export function isDelegationOutput(output: OutputData): boolean {
return output?.output?.type === OutputType.Delegation
}
Loading