Skip to content

Commit

Permalink
TW-1479: [EVM] Transactions history. Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-tsx committed Nov 4, 2024
1 parent 5aa2c4d commit 2838d85
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 52 deletions.
23 changes: 1 addition & 22 deletions src/app/atoms/SettingsCell.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React, { FC, HTMLAttributes, ReactElement, ReactNode } from 'react';
import React, { FC, HTMLAttributes, ReactNode } from 'react';

import clsx from 'clsx';

import { Button } from 'app/atoms';

interface ComponentBase {
className?: string;
children?: ReactNode;
Expand Down Expand Up @@ -52,22 +50,3 @@ export const SettingsCellSingle = <P extends ComponentBase>({
</Component>
);
};

interface Props {
title: ReactNode;
first?: boolean;
icon: ReactElement;
onClick: EmptyFn;
}

// @ts-prune-ignore-next
export const SettingsCell: FC<Props> = ({ title, first, onClick, icon }) => (
<Button
className={clsx('flex items-center justify-between p-3 gap-x-2 border-lines', !first && 'border-t-0.5')}
onClick={onClick}
>
<span className="text-font-medium-bold">{title}</span>

{icon}
</Button>
);
54 changes: 24 additions & 30 deletions src/lib/activity/evm/parse/gr-v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,7 @@ function parseLogEvent(
const fromAddress = logEvent.decoded.params.at(0)!.value;
const toAddress = logEvent.decoded.params.at(1)!.value;

const type = (() => {
if (toAddress === accountAddress) {
return item.to_address === logEvent.sender_address
? ActivityOperTransferType.receiveFromAccount
: ActivityOperTransferType.receive;
}

if (fromAddress === accountAddress) {
return item.to_address === logEvent.sender_address
? ActivityOperTransferType.sendToAccount
: ActivityOperTransferType.send;
}

return null;
})();
const type = deriveTransferType(accountAddress, fromAddress, toAddress, item, logEvent);

if (type == null) return { kind: ActivityOperKindEnum.interaction, withAddress: contractAddress };

Expand Down Expand Up @@ -104,21 +90,7 @@ function parseLogEvent(
const fromAddress = logEvent.decoded.params.at(1)!.value;
const toAddress = logEvent.decoded.params.at(2)!.value;

const type = (() => {
if (toAddress === accountAddress) {
return item.to_address === logEvent.sender_address
? ActivityOperTransferType.receiveFromAccount
: ActivityOperTransferType.receive;
}

if (fromAddress === accountAddress) {
return item.to_address === logEvent.sender_address
? ActivityOperTransferType.sendToAccount
: ActivityOperTransferType.send;
}

return null;
})();
const type = deriveTransferType(accountAddress, fromAddress, toAddress, item, logEvent);

if (type == null) return { kind: ActivityOperKindEnum.interaction, withAddress: contractAddress };

Expand Down Expand Up @@ -203,3 +175,25 @@ function parseLogEvent(

return { kind: ActivityOperKindEnum.interaction, withAddress: contractAddress };
}

function deriveTransferType(
accountAddress: string,
fromAddress: string,
toAddress: string,
item: Transaction,
logEvent: LogEvent
) {
if (toAddress === accountAddress) {
return item.to_address === logEvent.sender_address
? ActivityOperTransferType.receiveFromAccount
: ActivityOperTransferType.receive;
}

if (fromAddress === accountAddress) {
return item.to_address === logEvent.sender_address
? ActivityOperTransferType.sendToAccount
: ActivityOperTransferType.send;
}

return null;
}

0 comments on commit 2838d85

Please sign in to comment.