Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new Type to show DEX tag in summary header #2543

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions types/api/txInterpretation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@ export type TxInterpretationVariable =
TxInterpretationVariableString |
TxInterpretationVariableCurrency |
TxInterpretationVariableTimestamp |
TxInterpretationVariableExternalLink |
TxInterpretationVariableToken |
TxInterpretationVariableAddress |
TxInterpretationVariableDomain |
TxInterpretationVariableMethod;
TxInterpretationVariableMethod |
TxInterpretationVariableDex;

export type TxInterpretationVariableType = 'string' | 'currency' | 'timestamp' | 'token' | 'address' | 'domain' | 'method';
export type TxInterpretationVariableType =
'string' |
'currency' |
'timestamp' |
'external_link' |
'token' |
'address' |
'domain' |
'method' |
'dexTag';

export type TxInterpretationVariableString = {
type: 'string';
Expand All @@ -38,6 +49,14 @@ export type TxInterpretationVariableTimestamp = {
value: string;
};

export type TxInterpretationVariableExternalLink = {
type: 'external_link';
value: {
name: string;
link: string;
};
};

export type TxInterpretationVariableToken = {
type: 'token';
value: TokenInfo;
Expand All @@ -57,3 +76,14 @@ export type TxInterpretationVariableMethod = {
type: 'method';
value: string;
};

export type TxInterpretationVariableDex = {
type: 'dexTag';
value: {
name: string;
icon: string;
url: string;
app_id?: string;
app_icon?: string;
};
};
38 changes: 37 additions & 1 deletion ui/shared/tx/interpretation/TxInterpretation.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tooltip, chakra } from '@chakra-ui/react';
import { Tooltip, Image, chakra } from '@chakra-ui/react';
import BigNumber from 'bignumber.js';
import React from 'react';

Expand All @@ -9,6 +9,8 @@ import type {
TxInterpretationVariableString,
} from 'types/api/txInterpretation';

import { route } from 'nextjs-routes';

import config from 'configs/app';
import dayjs from 'lib/date/dayjs';
import * as mixpanel from 'lib/mixpanel/index';
Expand All @@ -19,6 +21,8 @@ import AddressEntity from 'ui/shared/entities/address/AddressEntity';
import EnsEntity from 'ui/shared/entities/ens/EnsEntity';
import TokenEntity from 'ui/shared/entities/token/TokenEntity';
import IconSvg from 'ui/shared/IconSvg';
import LinkExternal from 'ui/shared/links/LinkExternal';
import LinkInternal from 'ui/shared/links/LinkInternal';

import {
extractVariables,
Expand Down Expand Up @@ -121,6 +125,9 @@ const TxInterpretationElementByType = (
case 'timestamp': {
return <chakra.span color="text_secondary" whiteSpace="pre">{ dayjs(Number(value) * 1000).format('MMM DD YYYY') }</chakra.span>;
}
case 'external_link': {
return <LinkExternal href={ value.link }>{ value.name }</LinkExternal>;
}
case 'method': {
return (
<Tag
Expand All @@ -134,6 +141,35 @@ const TxInterpretationElementByType = (
</Tag>
);
}
case 'dexTag': {
const icon = value.app_icon || value.icon;
const name = (() => {
if (value.app_id && config.features.marketplace.isEnabled) {
return (
<LinkInternal
href={ route({ pathname: '/apps/[id]', query: { id: value.app_id } }) }
>
{ value.name }
</LinkInternal>
);
}
if (value.url) {
return (
<LinkExternal href={ value.url }>
{ value.name }
</LinkExternal>
);
}
return value.name;
})();

return (
<chakra.span display="inline-flex" alignItems="center" verticalAlign="top" _notFirst={{ marginLeft: 1 }} gap={ 1 }>
{ icon && <Image src={ icon } alt={ value.name } width={ 5 } height={ 5 }/> }
{ name }
</chakra.span>
);
}
}
};

Expand Down
Loading