Skip to content

Commit

Permalink
Merge branch 'develop' into tooling/move-validator-logo
Browse files Browse the repository at this point in the history
  • Loading branch information
panteleymonchuk authored Jan 17, 2025
2 parents 089c9d7 + f2570f8 commit e2f96c1
Show file tree
Hide file tree
Showing 16 changed files with 508 additions and 379 deletions.
36 changes: 22 additions & 14 deletions apps/core/src/components/transaction/TransactionIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

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

const ICON_COLORS = {
primary: 'text-primary-30',
error: 'text-error-30',
};

const icons = {
Send: <ArrowTopRight className={ICON_COLORS.primary} />,
Receive: <ArrowBottomLeft className={ICON_COLORS.primary} />,
Transaction: <ArrowTopRight className={ICON_COLORS.primary} />,
Staked: <Stake className={ICON_COLORS.primary} />,
Unstaked: <Stake className={ICON_COLORS.primary} />,
Rewards: <IotaLogoMark className={ICON_COLORS.primary} />,
Failed: <Info className={ICON_COLORS.error} />,
Loading: <LoadingIndicator />,
PersonalMessage: <Person className={ICON_COLORS.primary} />,
['Timelocked Staked']: <Stake className={ICON_COLORS.primary} />,
['Timelocked Unstaked']: <Stake className={ICON_COLORS.primary} />,
[TransactionAction.Send]: <ArrowTopRight className={ICON_COLORS.primary} />,
[TransactionAction.Receive]: <ArrowBottomLeft className={ICON_COLORS.primary} />,
[TransactionAction.Transaction]: <ArrowTopRight className={ICON_COLORS.primary} />,
[TransactionAction.Staked]: <Stake className={ICON_COLORS.primary} />,
[TransactionAction.Unstaked]: <Unstake className={ICON_COLORS.primary} />,
[TransactionAction.Rewards]: <IotaLogoMark className={ICON_COLORS.primary} />,
[TransactionAction.Failed]: <Info className={ICON_COLORS.error} />,
[TransactionAction.PersonalMessage]: <Person className={ICON_COLORS.primary} />,
[TransactionAction.TimelockedStaked]: <Stake className={ICON_COLORS.primary} />,
[TransactionAction.TimelockedUnstaked]: <Unstake className={ICON_COLORS.primary} />,
[TransactionAction.Migration]: <Migration className={ICON_COLORS.primary} />,
[TransactionAction.TimelockedCollect]: <Vesting className={ICON_COLORS.primary} />,
};

interface TransactionIconProps {
txnFailed?: boolean;
variant: keyof typeof icons;
variant: TransactionAction;
}

export function TransactionIcon({ txnFailed, variant }: TransactionIconProps) {
return <div className="[&_svg]:h-5 [&_svg]:w-5">{icons[txnFailed ? 'Failed' : variant]}</div>;
return (
<div className="[&_svg]:h-5 [&_svg]:w-5">
{icons[txnFailed ? TransactionAction.Failed : variant]}
</div>
);
}
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`;
3 changes: 3 additions & 0 deletions apps/core/src/interfaces/transactions.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ export enum TransactionAction {
Send = 'Send',
Receive = 'Receive',
Transaction = 'Transaction',
Failed = 'Failed',
Staked = 'Staked',
Unstaked = 'Unstaked',
TimelockedStaked = 'Timelocked Staked',
TimelockedUnstaked = 'Timelocked Unstaked',
TimelockedCollect = 'Timelocked Collect',
Migration = 'Migration',
Rewards = 'Rewards',
PersonalMessage = 'PersonalMessage',
}
Expand Down
20 changes: 16 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,39 @@

import { IotaTransactionBlockResponse } from '@iota/iota-sdk/client';
import { TransactionAction } from '../../interfaces';
import { checkIfIsTimelockedStaking } from '../stake/checkIfIsTimelockedStaking';
import { checkIfIsTimelockedStaking } from '../stake';
import { isMigrationTransaction, isUnlockTimelockedObjectTransaction } 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 = isMigrationTransaction(transaction.transaction);
const isSupplyIncreaseVestingCollect = isUnlockTimelockedObjectTransaction(
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 './isMigrationTransaction';
export * from './isUnlockTimelockedObjectTransaction';
29 changes: 29 additions & 0 deletions apps/core/src/utils/transaction/isMigrationTransaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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 isMigrationTransaction(
transaction: IotaTransactionBlockResponse['transaction'],
): boolean {
if (!transaction || transaction.data.transaction.kind !== 'ProgrammableTransaction')
return 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,28 @@
// 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 isUnlockTimelockedObjectTransaction(
transaction: IotaTransactionBlockResponse['transaction'],
): boolean {
if (!transaction || transaction.data.transaction.kind !== 'ProgrammableTransaction')
return false;
const moveCallTxs = transaction.data.transaction.transactions
.filter(isMoveCall)
.filter((tx) => tx.MoveCall.module === TIMELOCK_MODULE);
const isUnlockTimelockedObject =
moveCallTxs.length > 0 && moveCallTxs.every((tx) => tx.MoveCall.function === 'unlock');
return isUnlockTimelockedObject;
}

function isMoveCall(
transaction: IotaTransaction,
): transaction is { MoveCall: MoveCallIotaTransaction } {
return 'MoveCall' in transaction;
}
2 changes: 1 addition & 1 deletion apps/ui-icons/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `@iota/ui-icons`
# `@iota/apps-ui-icons`

## Exporting Icons

Expand Down
5 changes: 4 additions & 1 deletion apps/wallet-dashboard/app/(protected)/migrations/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ function MigrationDashboardPage(): JSX.Element {
{ StructType: STARDUST_NFT_OUTPUT_TYPE },
],
});
queryClient.invalidateQueries({
queryKey: ['migration-transaction', address],
});
});
},
[iotaClient, queryClient, address],
Expand Down Expand Up @@ -178,7 +181,7 @@ function MigrationDashboardPage(): JSX.Element {

function handleMigrationDialogClose() {
setIsMigrationDialogOpen(false);
router.push('/');
router.replace('/home');
}

return (
Expand Down
2 changes: 1 addition & 1 deletion apps/wallet-dashboard/app/(protected)/vesting/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export default function VestingDashboardPage(): JSX.Element {

useEffect(() => {
if (!supplyIncreaseVestingEnabled) {
router.push('/');
router.push('/home');
}
}, [router, supplyIncreaseVestingEnabled]);

Expand Down
4 changes: 2 additions & 2 deletions apps/wallet-dashboard/lib/constants/routes.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import type { ProtectedRoute } from '../interfaces';
import { ProtectedRouteTitle } from '../enums';
import { Activity, Assets, Calendar, Home, Stake, Vesting } from '@iota/apps-ui-icons';
import { Activity, Assets, Home, Migration, Stake, Vesting } from '@iota/apps-ui-icons';

export const HOMEPAGE_ROUTE: ProtectedRoute = {
title: ProtectedRouteTitle.Home,
Expand Down Expand Up @@ -31,7 +31,7 @@ export const ACTIVITY_ROUTE: ProtectedRoute = {
export const MIGRATIONS_ROUTE: ProtectedRoute = {
title: ProtectedRouteTitle.Migrations,
path: '/migrations',
icon: Calendar,
icon: Migration,
};
export const VESTING_ROUTE: ProtectedRoute = {
title: ProtectedRouteTitle.Vesting,
Expand Down
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.

1 change: 1 addition & 0 deletions apps/wallet-dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"zustand": "^4.4.1"
},
"devDependencies": {
"@tanstack/react-query-devtools": "^5.58.0",
"@types/jest": "^29.5.2",
"@types/node": "^20.14.10",
"@types/react": "^18.3.3",
Expand Down
2 changes: 2 additions & 0 deletions apps/wallet-dashboard/providers/AppProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { GrowthBookProvider } from '@growthbook/growthbook-react';
import { IotaClientProvider, lightTheme, darkTheme, WalletProvider } from '@iota/dapp-kit';
import { getAllNetworks, getDefaultNetwork } from '@iota/iota-sdk/client';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import { useState } from 'react';
import { KioskClientProvider, useLocalStorage } from '@iota/core';
import { growthbook } from '@/lib/utils';
Expand Down Expand Up @@ -53,6 +54,7 @@ export function AppProviders({ children }: React.PropsWithChildren) {
</WalletProvider>
</KioskClientProvider>
</IotaClientProvider>
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
</GrowthBookProvider>
);
Expand Down
Loading

0 comments on commit e2f96c1

Please sign in to comment.