Skip to content

Commit

Permalink
feat: add staked and unstaked action to activity details
Browse files Browse the repository at this point in the history
  • Loading branch information
evavirseda committed Dec 24, 2024
1 parent 434807e commit 0a7587f
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions apps/core/src/utils/transaction/getTransactionAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@

import { IotaTransactionBlockResponse } from '@iota/iota-sdk/client';
import { TransactionAction } from '../../interfaces';
import { STAKING_REQUEST_EVENT, UNSTAKING_REQUEST_EVENT } from '../../constants';

export const getTransactionAction = (
transaction: IotaTransactionBlockResponse,
currentAddress?: string,
) => {
const isSender = transaction.transaction?.data.sender === currentAddress;
return isSender ? TransactionAction.Send : TransactionAction.Receive;
const stakeTypeTransaction = transaction?.events?.find(
({ type }) => type === STAKING_REQUEST_EVENT,
);
const unstakeTypeTransaction = transaction?.events?.find(
({ type }) => type === UNSTAKING_REQUEST_EVENT,
);
if (stakeTypeTransaction) {
return TransactionAction.Staked;
} else if (unstakeTypeTransaction) {
return TransactionAction.Unstaked;
} else {
const isSender = transaction.transaction?.data.sender === currentAddress;
return isSender ? TransactionAction.Send : TransactionAction.Receive;
}
};

0 comments on commit 0a7587f

Please sign in to comment.