Skip to content

Commit 3c318f7

Browse files
authored
Create new Type to show DEX tag in summary header (#2543)
* Create new Type to show DEX tag in summary header * Add new response variable for interpreter
1 parent 0f9b5e7 commit 3c318f7

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

types/api/txInterpretation.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,23 @@ export type TxInterpretationVariable =
1616
TxInterpretationVariableString |
1717
TxInterpretationVariableCurrency |
1818
TxInterpretationVariableTimestamp |
19+
TxInterpretationVariableExternalLink |
1920
TxInterpretationVariableToken |
2021
TxInterpretationVariableAddress |
2122
TxInterpretationVariableDomain |
22-
TxInterpretationVariableMethod;
23+
TxInterpretationVariableMethod |
24+
TxInterpretationVariableDex;
2325

24-
export type TxInterpretationVariableType = 'string' | 'currency' | 'timestamp' | 'token' | 'address' | 'domain' | 'method';
26+
export type TxInterpretationVariableType =
27+
'string' |
28+
'currency' |
29+
'timestamp' |
30+
'external_link' |
31+
'token' |
32+
'address' |
33+
'domain' |
34+
'method' |
35+
'dexTag';
2536

2637
export type TxInterpretationVariableString = {
2738
type: 'string';
@@ -38,6 +49,14 @@ export type TxInterpretationVariableTimestamp = {
3849
value: string;
3950
};
4051

52+
export type TxInterpretationVariableExternalLink = {
53+
type: 'external_link';
54+
value: {
55+
name: string;
56+
link: string;
57+
};
58+
};
59+
4160
export type TxInterpretationVariableToken = {
4261
type: 'token';
4362
value: TokenInfo;
@@ -57,3 +76,14 @@ export type TxInterpretationVariableMethod = {
5776
type: 'method';
5877
value: string;
5978
};
79+
80+
export type TxInterpretationVariableDex = {
81+
type: 'dexTag';
82+
value: {
83+
name: string;
84+
icon: string;
85+
url: string;
86+
app_id?: string;
87+
app_icon?: string;
88+
};
89+
};

ui/shared/tx/interpretation/TxInterpretation.tsx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Tooltip, chakra } from '@chakra-ui/react';
1+
import { Tooltip, Image, chakra } from '@chakra-ui/react';
22
import BigNumber from 'bignumber.js';
33
import React from 'react';
44

@@ -9,6 +9,8 @@ import type {
99
TxInterpretationVariableString,
1010
} from 'types/api/txInterpretation';
1111

12+
import { route } from 'nextjs-routes';
13+
1214
import config from 'configs/app';
1315
import dayjs from 'lib/date/dayjs';
1416
import * as mixpanel from 'lib/mixpanel/index';
@@ -19,6 +21,8 @@ import AddressEntity from 'ui/shared/entities/address/AddressEntity';
1921
import EnsEntity from 'ui/shared/entities/ens/EnsEntity';
2022
import TokenEntity from 'ui/shared/entities/token/TokenEntity';
2123
import IconSvg from 'ui/shared/IconSvg';
24+
import LinkExternal from 'ui/shared/links/LinkExternal';
25+
import LinkInternal from 'ui/shared/links/LinkInternal';
2226

2327
import {
2428
extractVariables,
@@ -121,6 +125,9 @@ const TxInterpretationElementByType = (
121125
case 'timestamp': {
122126
return <chakra.span color="text_secondary" whiteSpace="pre">{ dayjs(Number(value) * 1000).format('MMM DD YYYY') }</chakra.span>;
123127
}
128+
case 'external_link': {
129+
return <LinkExternal href={ value.link }>{ value.name }</LinkExternal>;
130+
}
124131
case 'method': {
125132
return (
126133
<Tag
@@ -134,6 +141,35 @@ const TxInterpretationElementByType = (
134141
</Tag>
135142
);
136143
}
144+
case 'dexTag': {
145+
const icon = value.app_icon || value.icon;
146+
const name = (() => {
147+
if (value.app_id && config.features.marketplace.isEnabled) {
148+
return (
149+
<LinkInternal
150+
href={ route({ pathname: '/apps/[id]', query: { id: value.app_id } }) }
151+
>
152+
{ value.name }
153+
</LinkInternal>
154+
);
155+
}
156+
if (value.url) {
157+
return (
158+
<LinkExternal href={ value.url }>
159+
{ value.name }
160+
</LinkExternal>
161+
);
162+
}
163+
return value.name;
164+
})();
165+
166+
return (
167+
<chakra.span display="inline-flex" alignItems="center" verticalAlign="top" _notFirst={{ marginLeft: 1 }} gap={ 1 }>
168+
{ icon && <Image src={ icon } alt={ value.name } width={ 5 } height={ 5 }/> }
169+
{ name }
170+
</chakra.span>
171+
);
172+
}
137173
}
138174
};
139175

0 commit comments

Comments
 (0)