-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1457 from blockscout/fe-1435
Transaction interpretations
- Loading branch information
Showing
27 changed files
with
513 additions
and
28 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,24 @@ | ||
import type { Feature } from './types'; | ||
|
||
import { getEnvValue } from '../utils'; | ||
|
||
const title = 'Transaction interpretation'; | ||
|
||
const provider = getEnvValue('NEXT_PUBLIC_TRANSACTION_INTERPRETATION_PROVIDER') || 'none'; | ||
|
||
const config: Feature<{ provider: string }> = (() => { | ||
if (provider !== 'none') { | ||
return Object.freeze({ | ||
title, | ||
provider, | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ | |
| "graphQL" | ||
| "info" | ||
| "key" | ||
| "lightning" | ||
| "link" | ||
| "lock" | ||
| "minus" | ||
|
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,34 @@ | ||
import type { TxInterpretationResponse } from 'types/api/txInterpretation'; | ||
|
||
import { TOKEN_INFO_ERC_20 } from './token'; | ||
|
||
export const TX_INTERPRETATION: TxInterpretationResponse = { | ||
data: { | ||
summaries: [ | ||
{ | ||
summary_template: '{action_type} {source_amount} Ether into {destination_amount} {destination_token}', | ||
summary_template_variables: { | ||
action_type: { type: 'string', value: 'Wrap' }, | ||
source_amount: { type: 'currency', value: '0.7' }, | ||
destination_amount: { type: 'currency', value: '0.7' }, | ||
destination_token: { | ||
type: 'token', | ||
value: TOKEN_INFO_ERC_20, | ||
}, | ||
}, | ||
}, | ||
{ | ||
summary_template: '{action_type} {source_amount} Ether into {destination_amount} {destination_token}', | ||
summary_template_variables: { | ||
action_type: { type: 'string', value: 'Wrap' }, | ||
source_amount: { type: 'currency', value: '0.7' }, | ||
destination_amount: { type: 'currency', value: '0.7' }, | ||
destination_token: { | ||
type: 'token', | ||
value: TOKEN_INFO_ERC_20, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}; |
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
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,54 @@ | ||
import { Box, Flex, Link } from '@chakra-ui/react'; | ||
import React from 'react'; | ||
|
||
import config from 'configs/app'; | ||
import useApiQuery from 'lib/api/useApiQuery'; | ||
import { TX_INTERPRETATION } from 'stubs/txInterpretation'; | ||
import AccountActionsMenu from 'ui/shared/AccountActionsMenu/AccountActionsMenu'; | ||
import TxEntity from 'ui/shared/entities/tx/TxEntity'; | ||
import NetworkExplorers from 'ui/shared/NetworkExplorers'; | ||
import { TX_ACTIONS_BLOCK_ID } from 'ui/tx/details/txDetailsActions/TxDetailsActionsWrapper'; | ||
import TxInterpretation from 'ui/tx/interpretation/TxInterpretation'; | ||
|
||
type Props = { | ||
hash?: string; | ||
hasTag: boolean; | ||
} | ||
|
||
const TxSubHeading = ({ hash, hasTag }: Props) => { | ||
const hasInterpretationFeature = config.features.txInterpretation.isEnabled; | ||
|
||
const txInterpretationQuery = useApiQuery('tx_interpretation', { | ||
pathParams: { hash }, | ||
queryOptions: { | ||
enabled: Boolean(hash) && hasInterpretationFeature, | ||
placeholderData: TX_INTERPRETATION, | ||
}, | ||
}); | ||
|
||
const hasInterpretation = hasInterpretationFeature && | ||
(txInterpretationQuery.isPlaceholderData || txInterpretationQuery.data?.data.summaries.length); | ||
|
||
return ( | ||
<Box display={{ base: 'block', lg: 'flex' }} alignItems="center" w="100%"> | ||
{ hasInterpretationFeature && ( | ||
<Flex mr={{ base: 0, lg: 6 }} flexWrap="wrap" alignItems="center"> | ||
<TxInterpretation | ||
summary={ txInterpretationQuery.data?.data.summaries[0] } | ||
isLoading={ txInterpretationQuery.isPlaceholderData } | ||
fontSize="lg" | ||
/> | ||
{ !txInterpretationQuery.isPlaceholderData && txInterpretationQuery.data?.data.summaries && txInterpretationQuery.data?.data.summaries.length > 1 && | ||
<Link ml={ 3 } href={ `#${ TX_ACTIONS_BLOCK_ID }` }>all actions</Link> } | ||
</Flex> | ||
) } | ||
{ !hasInterpretation && <TxEntity hash={ hash } noLink noCopy={ false } fontWeight={ 500 } mr={{ base: 0, lg: 2 }} fontFamily="heading"/> } | ||
<Flex alignItems="center" justifyContent={{ base: 'start', lg: 'space-between' }} flexGrow={ 1 }> | ||
{ !hasTag && <AccountActionsMenu mr={ 3 } mt={{ base: 3, lg: 0 }}/> } | ||
<NetworkExplorers type="tx" pathParam={ hash } ml={{ base: 0, lg: 'auto' }} mt={{ base: 3, lg: 0 }}/> | ||
</Flex> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default TxSubHeading; |
File renamed without changes.
Oops, something went wrong.