-
Notifications
You must be signed in to change notification settings - Fork 170
feat (explorer): add wrapper designation to order details #7404
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
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
d3e2968
feat (explorer): add wrapper designation to order details
kaze-cow 7c5fc42
remove references to orderflow
kaze-cow 37ae0e9
fix build error
kaze-cow 014593d
Merge branch 'develop' into explorer-wrapper-designation
fairlighteth a7134c2
Merge branch 'develop' into explorer-wrapper-designation
elena-zh b9c2b73
feat: improve explorer wrapper details display and code quality
kaze-cow 5d6a348
refactor: split eulerEvc.tsx into per-wrapper files
kaze-cow 5ae0400
refactor: move Euler vault hooks to hooks/euler/
kaze-cow 43e4b07
refactor: use AddressKey type, shortenAddress, direct React imports, …
kaze-cow a9eb4df
Merge branch 'develop' into explorer-wrapper-designation
kaze-cow 46977ee
add import for detail row/tooltips
kaze-cow 743c3db
Merge branch 'develop' into explorer-wrapper-designation
elena-zh 62109a8
use jotai for state management, and remove unnecessary orderflow file…
kaze-cow cccc73d
Merge branch 'explorer-wrapper-designation' of https://github.com/cow…
kaze-cow aff025c
lint fix and resolve deprecated dependency
kaze-cow 1c730ce
fix design issues as suggested
kaze-cow 577b0dc
fix word wrap
kaze-cow aca39df
Merge branch 'develop' into explorer-wrapper-designation
kaze-cow 0e20fbf
try to fix pnpm lock
kaze-cow b53c40c
Merge branch 'explorer-wrapper-designation' of https://github.com/cow…
kaze-cow cafa54c
Merge branch 'develop' into explorer-wrapper-designation
elena-zh 9c61fc6
docs(explorer): add UI and code conventions to AGENTS.md (#7459)
kaze-cow 06e3e68
Merge branch 'develop' into explorer-wrapper-designation
Danziger 9fa04c7
fix: re-organize Euler wrapper-realted components and update layout t…
Danziger b1fdb7c
fix: rename Euler-related files
Danziger 551a014
fix: rename Euler-related files
Danziger d463bca
refactor: fix typo in function name
Danziger cf5942b
fix: remove jotai-family and revert dependency changes
Danziger 7260930
feat: introduce FiniteMap and use it for Euler's getPublicClient cache
Danziger 1d87ea3
fix: narrow down deps of useEffect in OrderWrapperDetailsItem
Danziger 745e188
fix: fix FiniteMap eviction logic when accessing missing keys
Danziger f6dc090
fix: add wrapper to TokenLink
Danziger a50bd81
Merge branch 'develop' into explorer-wrapper-designation
fairlighteth 60cfe85
Merge branch 'develop' into explorer-wrapper-designation
fairlighteth 787c8bc
Merge branch 'develop' into explorer-wrapper-designation
fairlighteth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
33 changes: 33 additions & 0 deletions
33
apps/explorer/src/components/orders/OrderWrapperDetails/OrderWrapperDetails.component.tsx
This file contains hidden or 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,33 @@ | ||
| import { ReactElement } from 'react' | ||
|
|
||
| import { OrderWrapperDetailsItem } from 'components/orders/OrderWrapperDetails/item/OrderWrapperDetailsItem.component' | ||
|
|
||
| import { OrderCtxProvider } from './OrderWrapperDetails.provider' | ||
| import * as styledEl from './OrderWrapperDetails.styled' | ||
|
|
||
| import { Order } from '../../../api/operator' | ||
| import { getOrderWrappers } from '../../../utils/getOrderWrappers' | ||
|
|
||
| interface OrderWrapperDetailsProps { | ||
| fullAppData: string | undefined | ||
| order?: Order | ||
| children: (content: ReactElement) => ReactElement | ||
| } | ||
|
|
||
| export function OrderWrapperDetails({ fullAppData, order, children }: OrderWrapperDetailsProps): ReactElement | null { | ||
| const wrappers = getOrderWrappers(fullAppData) | ||
|
|
||
| if (wrappers.length === 0) return null | ||
|
|
||
| return ( | ||
| <OrderCtxProvider order={order ?? null}> | ||
| {children( | ||
| <styledEl.WrapperList> | ||
| {wrappers.map((wrapper) => ( | ||
| <OrderWrapperDetailsItem key={`${wrapper.address}-${wrapper.data ?? ''}`} wrapper={wrapper} /> | ||
| ))} | ||
| </styledEl.WrapperList>, | ||
| )} | ||
| </OrderCtxProvider> | ||
| ) | ||
| } |
17 changes: 17 additions & 0 deletions
17
apps/explorer/src/components/orders/OrderWrapperDetails/OrderWrapperDetails.provider.tsx
This file contains hidden or 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,17 @@ | ||
| import { createContext, PropsWithChildren, useContext, ReactNode } from 'react' | ||
|
|
||
| import { Order } from '../../../api/operator' | ||
|
|
||
| export const OrderCtx = createContext<Order | null>(null) | ||
|
|
||
| export function useOrderContext(): Order | null { | ||
| return useContext(OrderCtx) | ||
| } | ||
|
|
||
| export interface OrderCtxProviderProps extends PropsWithChildren { | ||
| order: Order | null | ||
| } | ||
|
|
||
| export function OrderCtxProvider({ order, children }: OrderCtxProviderProps): ReactNode { | ||
| return <OrderCtx.Provider value={order}>{children}</OrderCtx.Provider> | ||
| } |
17 changes: 17 additions & 0 deletions
17
apps/explorer/src/components/orders/OrderWrapperDetails/OrderWrapperDetails.styled.tsx
This file contains hidden or 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,17 @@ | ||
| import { Media } from '@cowprotocol/ui' | ||
|
|
||
| import styled from 'styled-components/macro' | ||
|
|
||
| export const WrapperList = styled.ul` | ||
| margin: 0; | ||
| padding: 0; | ||
| list-style: none; | ||
| display: flex; | ||
| flex-flow: column wrap; | ||
| gap: 24px; | ||
| min-width: 420px; | ||
|
|
||
| ${Media.upToExtraSmall()} { | ||
| min-width: 100%; | ||
| } | ||
| ` |
65 changes: 65 additions & 0 deletions
65
...orer/src/components/orders/OrderWrapperDetails/item/OrderWrapperDetailsItem.component.tsx
This file contains hidden or 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,65 @@ | ||
| import { ComponentType, ReactElement, Suspense, useEffect, useState } from 'react' | ||
|
|
||
| import { getBlockExplorerUrl, shortenAddress } from '@cowprotocol/common-utils' | ||
| import { getAddressKey, SupportedChainId } from '@cowprotocol/cow-sdk' | ||
|
|
||
| import * as styledEl from './OrderWrapperDetailsItem.styled' | ||
|
|
||
| import { useContractName } from '../../../../hooks/euler' | ||
| import { usePopperDefault } from '../../../../hooks/usePopper' | ||
| import { useNetworkId } from '../../../../state/network/hooks' | ||
| import { ResolvedWrapper } from '../../../../utils/getOrderWrappers' | ||
| import { WRAPPERS_BY_ADDRESS } from '../../../../utils/wrappers/wrapperRegistry.constants' | ||
| import { Tooltip } from '../../../Tooltip' | ||
|
|
||
| const UNKNOWN_WRAPPER_TOOLTIP = | ||
| 'Explorer does not recognize this wrapper address yet, so it cannot decode wrapper-specific details. This may be a custom wrapper or a supported wrapper missing from the registry.' | ||
|
|
||
| export function OrderWrapperDetailsItem({ wrapper }: { wrapper: ResolvedWrapper }): ReactElement { | ||
| const [Component, setComponent] = useState<ComponentType<{ data: string }> | null>(null) | ||
| const { info, address, data, loadComponent, isOmittable } = wrapper | ||
| const chainId = useNetworkId() as SupportedChainId | null | ||
| const isUnknown = !WRAPPERS_BY_ADDRESS[getAddressKey(address)] | ||
| const contractName = useContractName(isUnknown ? address : '') | ||
| const { tooltipProps, targetProps } = usePopperDefault<HTMLLIElement>('top') | ||
|
|
||
| useEffect(() => { | ||
| if (!data || !loadComponent) return | ||
| loadComponent().then((Comp) => setComponent(() => Comp)) | ||
| }, [data, loadComponent]) | ||
|
|
||
| const addressUrl = chainId ? getBlockExplorerUrl(chainId, 'contract', address) : undefined | ||
| const shortAddress = shortenAddress(address) | ||
| const displayName = isUnknown ? (contractName ?? shortAddress) : info.name | ||
|
|
||
| return ( | ||
| <> | ||
| <styledEl.WrapperItem {...(isUnknown ? targetProps : {})}> | ||
| <styledEl.WrapperHeader> | ||
| {info.image && <img src={info.image} alt={info.name} />} | ||
| <strong>{displayName}</strong> | ||
| {addressUrl ? ( | ||
| <span> | ||
| ( | ||
| <a href={addressUrl} target="_blank" rel="noopener noreferrer" title={address}> | ||
| {shortAddress}↗ | ||
| </a> | ||
| ) | ||
| </span> | ||
| ) : ( | ||
| <span title={address}>({shortAddress})</span> | ||
| )} | ||
| {isOmittable && <em>(omittable)</em>} | ||
| </styledEl.WrapperHeader> | ||
| {Component && data && ( | ||
| <styledEl.RenderedData> | ||
| <Suspense fallback={<span>Loading…</span>}> | ||
| <Component data={data} /> | ||
| </Suspense> | ||
| </styledEl.RenderedData> | ||
| )} | ||
| </styledEl.WrapperItem> | ||
| {isUnknown && <Tooltip {...tooltipProps}>{UNKNOWN_WRAPPER_TOOLTIP}</Tooltip>} | ||
| </> | ||
| ) | ||
| } |
50 changes: 50 additions & 0 deletions
50
...xplorer/src/components/orders/OrderWrapperDetails/item/OrderWrapperDetailsItem.styled.tsx
This file contains hidden or 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,50 @@ | ||
| import { Color } from '@cowprotocol/ui' | ||
|
|
||
| import styled from 'styled-components/macro' | ||
|
|
||
| export const WrapperItem = styled.li` | ||
| display: flex; | ||
| flex-flow: column wrap; | ||
| gap: 12px; | ||
| ` | ||
|
|
||
| export const WrapperHeader = styled.p` | ||
| margin: 0; | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 0.5rem; | ||
| flex-wrap: wrap; | ||
|
|
||
| > img { | ||
| width: 2rem; | ||
| height: 2rem; | ||
| } | ||
| ` | ||
|
|
||
| export const RenderedData = styled.div` | ||
| border: 1px solid ${Color.explorer_tableRowBorder}; | ||
| border-radius: 0.5rem; | ||
| background: ${Color.explorer_tableRowBorder}; | ||
| overflow: auto; | ||
| word-break: break-all; | ||
| line-height: 1.5; | ||
|
|
||
| table { | ||
| border-collapse: collapse; | ||
| width: 100%; | ||
| } | ||
|
|
||
| td { | ||
| padding: 0.2rem 1rem 0.2rem 0; | ||
| vertical-align: top; | ||
|
|
||
| &:first-child { | ||
| font-weight: 500; | ||
| white-space: nowrap; | ||
| } | ||
| } | ||
|
|
||
| code { | ||
| font-size: 1.2rem; | ||
| } | ||
| ` |
This file contains hidden or 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,16 @@ | ||
| export const ERC4626_ABI = [ | ||
| { name: 'asset', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'address' }] }, | ||
| { | ||
| name: 'convertToAssets', | ||
| type: 'function', | ||
| stateMutability: 'view', | ||
| inputs: [{ name: 'shares', type: 'uint256' }], | ||
| outputs: [{ type: 'uint256' }], | ||
| }, | ||
| ] as const | ||
|
|
||
| export const ERC20_ABI = [ | ||
| { name: 'symbol', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'string' }] }, | ||
| { name: 'name', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'string' }] }, | ||
| { name: 'decimals', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'uint8' }] }, | ||
| ] as const |
This file contains hidden or 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,22 @@ | ||
| import { RPC_URLS, VIEM_CHAINS } from '@cowprotocol/common-const' | ||
| import { FiniteMap } from '@cowprotocol/common-utils' | ||
| import { SupportedChainId } from '@cowprotocol/cow-sdk' | ||
|
|
||
| import { createPublicClient, http } from 'viem' | ||
|
|
||
| type PublicClient = ReturnType<typeof createPublicClient> | ||
|
|
||
| const publicClientsCache = new FiniteMap<SupportedChainId, PublicClient>(16) | ||
|
|
||
| export function getPublicClient(chainId: SupportedChainId): PublicClient { | ||
| const cached = publicClientsCache.get(chainId) | ||
| if (cached) return cached | ||
|
|
||
| const client = createPublicClient({ | ||
| chain: VIEM_CHAINS[chainId], | ||
| transport: http(RPC_URLS[chainId]), | ||
| }) | ||
|
|
||
| publicClientsCache.set(chainId, client) | ||
| return client | ||
| } |
This file contains hidden or 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,4 @@ | ||
| export type { VaultAsset } from './useVaultAsset' | ||
| export { useVaultAsset } from './useVaultAsset' | ||
| export { useConvertToAssets } from './useConvertToAssets' | ||
| export { useContractName } from './useContractName' |
This file contains hidden or 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,27 @@ | ||
| import { AddressKey, SupportedChainId } from '@cowprotocol/cow-sdk' | ||
|
|
||
| import useSWR from 'swr' | ||
|
|
||
| import { ERC20_ABI } from './abis' | ||
| import { getPublicClient } from './client' | ||
|
|
||
| import { useNetworkId } from '../../state/network/hooks' | ||
|
|
||
| export function useContractName(address: AddressKey): string | undefined { | ||
| const chainId = useNetworkId() as SupportedChainId | null | ||
|
|
||
| const { data } = useSWR<string>( | ||
| chainId && address ? `contract-name:${chainId}:${address}` : null, | ||
| () => { | ||
| if (!chainId || !address) throw new Error('missing chainId or address') | ||
| return getPublicClient(chainId).readContract({ | ||
| address: address as `0x${string}`, | ||
| abi: ERC20_ABI, | ||
| functionName: 'name', | ||
| }) as Promise<string> | ||
| }, | ||
| { onError: () => undefined }, | ||
| ) | ||
|
|
||
| return data | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OrderWrapperDetails.styled.tsx