Skip to content

Commit

Permalink
feat(wallet-dashboard): improve tx history & details
Browse files Browse the repository at this point in the history
  • Loading branch information
cpl121 committed Jan 15, 2025
1 parent d90c78f commit 64e731f
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 37 deletions.
13 changes: 12 additions & 1 deletion apps/core/src/components/transaction/TransactionIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
// SPDX-License-Identifier: Apache-2.0

import { LoadingIndicator } from '@iota/apps-ui-kit';
import { ArrowBottomLeft, ArrowTopRight, Info, IotaLogoMark, Person, Stake } from '@iota/ui-icons';
import {
ArrowBottomLeft,
ArrowTopRight,
Info,
IotaLogoMark,
Migration,
Person,
Stake,
Vesting,
} from '@iota/ui-icons';

const ICON_COLORS = {
primary: 'text-primary-30',
Expand All @@ -21,6 +30,8 @@ const icons = {
PersonalMessage: <Person className={ICON_COLORS.primary} />,
['Timelocked Staked']: <Stake className={ICON_COLORS.primary} />,
['Timelocked Unstaked']: <Stake className={ICON_COLORS.primary} />,
Migration: <Migration className={ICON_COLORS.primary} />,
['Timelocked Collect']: <Vesting className={ICON_COLORS.primary} />,
};

interface TransactionIconProps {
Expand Down
5 changes: 3 additions & 2 deletions apps/core/src/constants/timelock.constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

export const TIMELOCK_IOTA_TYPE = '0x2::timelock::TimeLock<0x2::balance::Balance<0x2::iota::IOTA>>';
export const TIMELOCK_STAKED_TYPE = '0x3::timelocked_staking::TimelockedStakedIota';
export const TIMELOCK_MODULE = 'timelock';
export const TIMELOCK_IOTA_TYPE = `0x2::${TIMELOCK_MODULE}::TimeLock<0x2::balance::Balance<0x2::iota::IOTA>>`;
export const TIMELOCK_STAKED_TYPE = `0x3::timelocked_staking::TimelockedStakedIota`;
2 changes: 2 additions & 0 deletions apps/core/src/interfaces/transactions.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export enum TransactionAction {
Unstaked = 'Unstaked',
TimelockedStaked = 'Timelocked Staked',
TimelockedUnstaked = 'Timelocked Unstaked',
TimelockedCollect = 'Timelocked Collect',
Migration = 'Migration',
Rewards = 'Rewards',
PersonalMessage = 'PersonalMessage',
}
Expand Down
32 changes: 32 additions & 0 deletions apps/core/src/utils/transaction/checkIfIsMigrationTransaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import type {
IotaTransaction,
IotaTransactionBlockResponse,
MoveCallIotaTransaction,
} from '@iota/iota-sdk/client';
import { STARDUST_PACKAGE_ID } from '../../constants';

export function checkIfIsMigrationTransaction(
transaction: IotaTransactionBlockResponse['transaction'],
) {
if (!transaction || transaction.data.transaction.kind !== 'ProgrammableTransaction')
return { isMigration: false };
const moveCallTxs = transaction.data.transaction.transactions.filter(isMoveCall);
const isMigration = moveCallTxs.some(
(tx) =>
tx.MoveCall.package === STARDUST_PACKAGE_ID &&
tx.MoveCall.function === 'extract_assets',
);

return {
isMigration,
};
}

function isMoveCall(
transaction: IotaTransaction,
): transaction is { MoveCall: MoveCallIotaTransaction } {
return 'MoveCall' in transaction;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import type {
IotaTransaction,
IotaTransactionBlockResponse,
MoveCallIotaTransaction,
} from '@iota/iota-sdk/client';
import { TIMELOCK_MODULE } from '../../';

export function checkIfIsSupplyIncreaseVestingCollectTransaction(
transaction: IotaTransactionBlockResponse['transaction'],
) {
if (!transaction || transaction.data.transaction.kind !== 'ProgrammableTransaction')
return { isSupplyIncreaseVestingCollect: false };
const moveCallTxs = transaction.data.transaction.transactions
.filter(isMoveCall)
.filter((tx) => tx.MoveCall.module === TIMELOCK_MODULE);
const isSupplyIncreaseVestingCollect =
moveCallTxs.length > 0 && moveCallTxs.every((tx) => tx.MoveCall.function === 'unlock');

return {
isSupplyIncreaseVestingCollect,
};
}

function isMoveCall(
transaction: IotaTransaction,
): transaction is { MoveCall: MoveCallIotaTransaction } {
return 'MoveCall' in transaction;
}
23 changes: 19 additions & 4 deletions apps/core/src/utils/transaction/getTransactionAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,42 @@

import { IotaTransactionBlockResponse } from '@iota/iota-sdk/client';
import { TransactionAction } from '../../interfaces';
import { checkIfIsTimelockedStaking } from '../stake/checkIfIsTimelockedStaking';
import { checkIfIsTimelockedStaking } from '../stake';
import {
checkIfIsMigrationTransaction,
checkIfIsSupplyIncreaseVestingCollectTransaction,
} from '..';

export const getTransactionAction = (
transaction: IotaTransactionBlockResponse,
currentAddress?: string,
) => {
const sender = transaction.transaction?.data.sender;
const {
isTimelockedStaking,
isTimelockedUnstaking,
stakeTypeTransaction,
unstakeTypeTransaction,
} = checkIfIsTimelockedStaking(transaction?.events);

if (stakeTypeTransaction) {
const { isMigration } = checkIfIsMigrationTransaction(transaction.transaction);
const { isSupplyIncreaseVestingCollect } = checkIfIsSupplyIncreaseVestingCollectTransaction(
transaction.transaction,
);

if (isMigration) {
return TransactionAction.Migration;
} else if (isSupplyIncreaseVestingCollect) {
return TransactionAction.TimelockedCollect;
} else if (stakeTypeTransaction) {
return isTimelockedStaking ? TransactionAction.TimelockedStaked : TransactionAction.Staked;
} else if (unstakeTypeTransaction) {
return isTimelockedUnstaking
? TransactionAction.TimelockedUnstaked
: TransactionAction.Unstaked;
} else if (!!sender) {
return sender === currentAddress ? TransactionAction.Send : TransactionAction.Receive;
} else {
const isSender = transaction.transaction?.data.sender === currentAddress;
return isSender ? TransactionAction.Transaction : TransactionAction.Receive;
return TransactionAction.Transaction;
}
};
2 changes: 2 additions & 0 deletions apps/core/src/utils/transaction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export * from './createTokenTransferTransaction';
export * from './getObjectDisplayLookup';
export * from './createNftSendValidationSchema';
export * from './createUnlockTimelockedObjectsTransaction';
export * from './checkIfIsMigrationTransaction';
export * from './checkIfIsSupplyIncreaseVestingCollectTransaction';
1 change: 0 additions & 1 deletion apps/wallet-dashboard/lib/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

export * from './transactions.interfaces';
export * from './timelock.interfaces';
export * from './vesting.interfaces';
export * from './appRoute.interfaces';
Expand Down
29 changes: 0 additions & 29 deletions apps/wallet-dashboard/lib/interfaces/transactions.interfaces.ts

This file was deleted.

0 comments on commit 64e731f

Please sign in to comment.