-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create delegation activity (#8366)
* feat: add delegation activity * fix: minor improvements * feat: create delegation tile and details component * feat: improvements * feat: add delegatioon tab details * feat: add account address * minor fix * fix storage deposti and giftedStorageDeposit --------- Co-authored-by: cpl121 <[email protected]> Co-authored-by: cpl121 <[email protected]>
- Loading branch information
1 parent
602a13c
commit cff7a2e
Showing
20 changed files
with
209 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/shared/components/DelegationActivityDetails.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<script lang="ts"> | ||
import { AddressBox, ActivityInclusionStatusPill, AmountBox } from '@ui' | ||
import { DelegationActivity, getAssetFromPersistedAssets } from '@core/wallet' | ||
import { getBaseToken, getCoinType } from '@core/profile' | ||
export let activity: DelegationActivity | ||
const asset = getAssetFromPersistedAssets(getCoinType()) | ||
const unit = getBaseToken().unit | ||
$: amount = activity.delegatedAmount | ||
</script> | ||
|
||
<main-content class="flex flex-auto w-full flex-col items-center justify-center space-y-3"> | ||
<AmountBox {amount} {asset} {unit} /> | ||
<account-status class="flex flex-row w-full space-x-2 justify-center"> | ||
<ActivityInclusionStatusPill localizationKey={'delegation.creation'} inclusionState={activity.inclusionState} /> | ||
</account-status> | ||
<AddressBox clearBackground clearPadding isCopyable address={activity.transactionId} /> | ||
</main-content> |
32 changes: 32 additions & 0 deletions
32
packages/shared/components/activity-info/DelegationActivityInformation.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<script lang="ts"> | ||
import { KeyValueBox } from '@ui' | ||
import { localize } from '@core/i18n' | ||
import { DelegationActivity, EMPTY_HEX_ID, formatTokenAmountBestMatch } from '@core/wallet' | ||
import { getBaseToken } from 'shared/lib/core/profile' | ||
import { api } from '@core/api' | ||
import { onMount } from 'svelte' | ||
export let activity: DelegationActivity | ||
const formattedAmount = formatTokenAmountBestMatch(activity.delegatedAmount, getBaseToken()).toString() | ||
let delegationId = activity.delegationId | ||
let detailsList: { [key in string]: string } | ||
onMount(() => { | ||
if (delegationId === EMPTY_HEX_ID) { | ||
delegationId = api.computeDelegationId(activity.outputId) | ||
} | ||
}) | ||
$: detailsList = { | ||
validatorAddress: activity.validatorAddress, | ||
delegatedAmount: formattedAmount, | ||
delegationId: delegationId, | ||
startEpoch: activity.startEpoch.toString(), | ||
} | ||
</script> | ||
|
||
{#each Object.entries(detailsList) as [key, value]} | ||
<KeyValueBox keyText={localize(`general.${key}`)} valueText={value} isCopyable /> | ||
{/each} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/shared/components/tiles/tileContents/DelegationActivityTileContent.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script lang="ts"> | ||
import { localize } from '@core/i18n' | ||
import { DelegationActivity, getActivityTileTitle } from '@core/wallet' | ||
import { truncateString } from '@core/utils' | ||
import { ActivityTileContent } from '@ui' | ||
import { Icon } from '@lib/auxiliary/icon' | ||
export let activity: DelegationActivity | ||
$: action = localize(getActivityTileTitle(activity)) | ||
$: formattedAsset = { | ||
text: truncateString(activity.accountAddress, 6, 6), | ||
color: 'blue-700', | ||
} | ||
</script> | ||
|
||
<ActivityTileContent icon={Icon.Account} {action} subject={localize('general.internalTransaction')} {formattedAsset} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ export enum ActivityAction { | |
Burn = 'burn', | ||
Mint = 'mint', | ||
Unknown = 'unknown', | ||
Create = 'create', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ export enum ActivityType { | |
Nft = 'nft', | ||
Vesting = 'vesting', | ||
Anchor = 'anchor', | ||
Delegation = 'delegation', | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/shared/lib/core/wallet/types/activities/delegation-activity.type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ActivityType } from '@core/wallet/enums' | ||
import { BaseActivity } from './base-activity.type' | ||
|
||
export type DelegationActivity = BaseActivity & { | ||
type: ActivityType.Delegation | ||
validatorAddress: string | ||
delegatedAmount: number | ||
delegationId: string | ||
startEpoch: number | ||
accountAddress: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
.../shared/lib/core/wallet/utils/generateActivity/generateActivitiesFromDelegationOutputs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { IWalletState } from '@core/wallet/interfaces' | ||
import { ActivityAction, DelegationActivity, IProcessedTransaction } from '@core/wallet' | ||
import { Activity } from '@core/wallet/types' | ||
import { generateSingleDelegationActivity } from './generateSingleDelegationActivity' | ||
import { OutputType } from '@iota/sdk/out/types' | ||
|
||
export async function generateActivitiesFromDelegationOutputs( | ||
processedTransaction: IProcessedTransaction, | ||
wallet: IWalletState | ||
): Promise<Activity[]> { | ||
const outputs = processedTransaction.outputs | ||
const activities: DelegationActivity[] = [] | ||
|
||
const delegationOutputs = outputs.filter((output) => output.output.type === OutputType.Delegation) | ||
for (const delegationOutput of delegationOutputs) { | ||
const activity = await generateSingleDelegationActivity(wallet, { | ||
action: ActivityAction.Create, | ||
processedTransaction, | ||
wrappedOutput: delegationOutput, | ||
}) | ||
activities.push(activity) | ||
} | ||
return activities | ||
} |
50 changes: 50 additions & 0 deletions
50
packages/shared/lib/core/wallet/utils/generateActivity/generateSingleDelegationActivity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { ActivityType } from '@core/wallet/enums' | ||
import { IActivityGenerationParameters, IWalletState } from '@core/wallet/interfaces' | ||
import { DelegationActivity } from '@core/wallet/types' | ||
import { getAsyncDataFromOutput, getSendingInformation, getStorageDepositFromOutput } from './helper' | ||
import { DelegationOutput } from '@iota/sdk/out/types' | ||
import { AddressConverter } from '../AddressConverter' | ||
|
||
export async function generateSingleDelegationActivity( | ||
wallet: IWalletState, | ||
{ action, processedTransaction, wrappedOutput }: IActivityGenerationParameters | ||
): Promise<DelegationActivity> { | ||
const { transactionId, direction, time, claimingData, inclusionState, mana } = processedTransaction | ||
const output = wrappedOutput.output as DelegationOutput | ||
const { storageDeposit, giftedStorageDeposit } = await getStorageDepositFromOutput(output) | ||
const outputId = wrappedOutput.outputId | ||
const id = outputId || transactionId | ||
const isHidden = false | ||
const isAssetHidden = false | ||
const containsValue = true | ||
const delegatedAmount = Number(output.delegatedAmount) | ||
const delegationId = output.delegationId | ||
const validatorAddress = AddressConverter.addressToBech32(output?.validatorAddress) | ||
const asyncData = await getAsyncDataFromOutput(output, outputId, claimingData, wallet) | ||
const sendingInfo = getSendingInformation(processedTransaction, output, wallet) | ||
const startEpoch = output.startEpoch | ||
const accountAddress = AddressConverter.addressToBech32(output.unlockConditions[0]?.address) | ||
return { | ||
type: ActivityType.Delegation, | ||
id, | ||
outputId, | ||
transactionId, | ||
direction, | ||
action, | ||
isHidden, | ||
isAssetHidden, | ||
time, | ||
inclusionState, | ||
containsValue, | ||
mana, | ||
delegatedAmount, | ||
storageDeposit, | ||
giftedStorageDeposit, | ||
delegationId, | ||
validatorAddress, | ||
asyncData, | ||
accountAddress, | ||
startEpoch, | ||
...sendingInfo, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters