-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f257b4
commit 4d0720b
Showing
18 changed files
with
352 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { Feature } from './types'; | ||
|
||
import { getEnvValue } from '../utils'; | ||
|
||
const title = 'Transaction interpretation'; | ||
|
||
const config: Feature<{ isEnabled: true }> = (() => { | ||
if (getEnvValue('NEXT_PUBLIC_TRANSACTION_INTERPRETATION_ENABLED') === 'true') { | ||
return Object.freeze({ | ||
title, | ||
isEnabled: true, | ||
}); | ||
} | ||
|
||
return Object.freeze({ | ||
title, | ||
isEnabled: false, | ||
}); | ||
})(); | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type { TxInterpretationResponse } from 'types/api/txInterpretation'; | ||
|
||
export const txInterpretation: TxInterpretationResponse = { | ||
data: { | ||
summaries: [ { | ||
summary_template: `{action_type} {amount} {token} to {to_address} on {timestamp}`, | ||
summary_template_variables: { | ||
action_type: { type: 'string', value: 'Transfer' }, | ||
amount: { type: 'currency', value: '100' }, | ||
token: { | ||
type: 'token', | ||
value: { | ||
name: 'Duck', | ||
type: 'ERC-20', | ||
symbol: 'DUCK', | ||
address: '0x486a3c5f34cDc4EF133f248f1C81168D78da52e8', | ||
holders: '1152', | ||
decimals: '18', | ||
icon_url: null, | ||
total_supply: '210000000000000000000000000', | ||
exchange_rate: null, | ||
circulating_market_cap: null, | ||
}, | ||
}, | ||
to_address: { | ||
type: 'address', | ||
value: { | ||
hash: '0x48c04ed5691981C42154C6167398f95e8f38a7fF', | ||
implementation_name: null, | ||
is_contract: false, | ||
is_verified: false, | ||
name: null, | ||
private_tags: [], | ||
public_tags: [], | ||
watchlist_names: [], | ||
}, | ||
}, | ||
timestamp: { | ||
type: 'timestamp', | ||
value: '1687005431', | ||
}, | ||
}, | ||
} ], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type { AddressParam } from 'types/api/addressParams'; | ||
import type { TokenInfo } from 'types/api/token'; | ||
|
||
export interface TxInterpretationResponse { | ||
data: { | ||
summaries: Array<TxInterpretationSummary>; | ||
}; | ||
} | ||
|
||
export type TxInterpretationSummary = { | ||
summary_template: string; | ||
summary_template_variables: Record<string, TxInterpretationVariable>; | ||
} | ||
|
||
export type TxInterpretationVariable = | ||
TxInterpretationVariableString | | ||
TxInterpretationVariableCurrency | | ||
TxInterpretationVariableTimestamp | | ||
TxInterpretationVariableToken | | ||
TxInterpretationVariableAddress; | ||
|
||
export type TxInterpretationVariableType = 'string' | 'currency' | 'timestamp' | 'token' | 'address'; | ||
|
||
export type TxInterpretationVariableString = { | ||
type: 'string'; | ||
value: string; | ||
} | ||
|
||
export type TxInterpretationVariableCurrency = { | ||
type: 'currency'; | ||
value: string; | ||
} | ||
|
||
export type TxInterpretationVariableTimestamp = { | ||
type: 'timestamp'; | ||
value: string; | ||
} | ||
|
||
export type TxInterpretationVariableToken = { | ||
type: 'token'; | ||
value: TokenInfo; | ||
} | ||
|
||
export type TxInterpretationVariableAddress = { | ||
type: 'address'; | ||
value: AddressParam; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { test, expect } from '@playwright/experimental-ct-react'; | ||
import type { UseQueryResult } from '@tanstack/react-query'; | ||
import React from 'react'; | ||
|
||
import type { TxInterpretationResponse } from 'types/api/txInterpretation'; | ||
|
||
import type { ResourceError } from 'lib/api/resources'; | ||
import { txInterpretation as txInterpretationMock } from 'mocks/txs/txInterpretation'; | ||
import TestApp from 'playwright/TestApp'; | ||
|
||
import TxInterpretation from './TxInterpretation'; | ||
|
||
test('base view +@mobile +@dark-mode', async({ mount }) => { | ||
const component = await mount( | ||
<TestApp> | ||
<TxInterpretation query={{ data: txInterpretationMock } as UseQueryResult<TxInterpretationResponse, ResourceError>}/> | ||
</TestApp>, | ||
); | ||
|
||
await expect(component).toHaveScreenshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Skeleton, Text, Icon, chakra } from '@chakra-ui/react'; | ||
import type { UseQueryResult } from '@tanstack/react-query'; | ||
import BigNumber from 'bignumber.js'; | ||
import React from 'react'; | ||
|
||
import type { TxInterpretationResponse, TxInterpretationVariable } from 'types/api/txInterpretation'; | ||
|
||
import actionIcon from 'icons/action.svg'; | ||
import type { ResourceError } from 'lib/api/resources'; | ||
import dayjs from 'lib/date/dayjs'; | ||
import AddressEntity from 'ui/shared/entities/address/AddressEntity'; | ||
import TokenEntity from 'ui/shared/entities/token/TokenEntity'; | ||
|
||
import { extractVariables, getStringChunks } from './utils'; | ||
|
||
type Props = { | ||
query: UseQueryResult<TxInterpretationResponse, ResourceError>; | ||
className?: string; | ||
} | ||
|
||
const TxInterpretationElementByType = ({ type, value }: TxInterpretationVariable) => { | ||
switch (type) { | ||
case 'address': | ||
return <AddressEntity address={ value } truncation="constant" sx={{ ':not(:first-child)': { marginLeft: 1 } }}/>; | ||
case 'token': | ||
return <TokenEntity token={ value } onlySymbol width="fit-content" sx={{ ':not(:first-child)': { marginLeft: 1 } }}/>; | ||
case 'currency': | ||
return <Text>{ BigNumber(value).toFormat() }</Text>; | ||
case 'timestamp': | ||
// timestamp is in unix format | ||
return <Text>{ dayjs(Number(value) * 1000).format('llll') }</Text>; | ||
case 'string': | ||
default: { | ||
return <Text>{ value.toString() }</Text>; | ||
} | ||
} | ||
}; | ||
|
||
const TxInterpretation = ({ query, className }: Props) => { | ||
if (!query.data?.data.summaries[0]) { | ||
return null; | ||
} | ||
|
||
const template = query.data.data.summaries[0].summary_template; | ||
const variables = query.data.data.summaries[0].summary_template_variables; | ||
|
||
const variablesNames = extractVariables(template); | ||
|
||
const chunks = getStringChunks(template); | ||
|
||
return ( | ||
<Skeleton display="flex" flexWrap="wrap" alignItems="center" isLoaded={ !query.isPlaceholderData } className={ className }> | ||
<Icon as={ actionIcon } boxSize={ 5 } color="text_secondary" mr={ 2 }/> | ||
{ chunks.map((chunk, index) => { | ||
return ( | ||
<> | ||
<Text whiteSpace="pre">{ chunk }</Text> | ||
{ index < chunks.length - 1 && <TxInterpretationElementByType { ...variables[variablesNames[index]] }/> } | ||
</> | ||
); | ||
}) } | ||
</Skeleton> | ||
); | ||
}; | ||
|
||
export default chakra(TxInterpretation); |
Binary file added
BIN
+9.31 KB
...hots__/TxInterpretation.pw.tsx_dark-color-mode_base-view-mobile-dark-mode-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.06 KB
..._screenshots__/TxInterpretation.pw.tsx_default_base-view-mobile-dark-mode-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.77 KB
...__screenshots__/TxInterpretation.pw.tsx_mobile_base-view-mobile-dark-mode-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.