-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display proxy pattern info on contract page (#2230)
* Display proxy pattern info in UI Fixes #2209 * update texts * [skip ci] adjust alert condition
- Loading branch information
Showing
11 changed files
with
131 additions
and
23 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
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,20 @@ | ||
import React from 'react'; | ||
|
||
import { test, expect } from 'playwright/lib'; | ||
|
||
import ContractCodeProxyPattern from './ContractCodeProxyPattern'; | ||
|
||
test('proxy type with link +@mobile', async({ render }) => { | ||
const component = await render(<ContractCodeProxyPattern type="eip1167"/>); | ||
await expect(component).toHaveScreenshot(); | ||
}); | ||
|
||
test('proxy type with link but without description', async({ render }) => { | ||
const component = await render(<ContractCodeProxyPattern type="master_copy"/>); | ||
await expect(component).toHaveScreenshot(); | ||
}); | ||
|
||
test('proxy type without link', async({ render }) => { | ||
const component = await render(<ContractCodeProxyPattern type="basic_implementation"/>); | ||
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,89 @@ | ||
import { Alert } from '@chakra-ui/react'; | ||
import React from 'react'; | ||
|
||
import type { SmartContractProxyType } from 'types/api/contract'; | ||
|
||
import LinkExternal from 'ui/shared/links/LinkExternal'; | ||
|
||
interface Props { | ||
type: NonNullable<SmartContractProxyType>; | ||
} | ||
|
||
const PROXY_TYPES: Record<NonNullable<SmartContractProxyType>, { | ||
name: string; | ||
link?: string; | ||
description?: string; | ||
}> = { | ||
eip1167: { | ||
name: 'EIP-1167', | ||
link: 'https://eips.ethereum.org/EIPS/eip-1167', | ||
description: 'Minimal proxy', | ||
}, | ||
eip1967: { | ||
name: 'EIP-1967', | ||
link: 'https://eips.ethereum.org/EIPS/eip-1967', | ||
description: 'Proxy storage slots', | ||
}, | ||
eip1822: { | ||
name: 'EIP-1822', | ||
link: 'https://eips.ethereum.org/EIPS/eip-1822', | ||
description: 'Universal upgradeable proxy standard (UUPS)', | ||
}, | ||
eip2535: { | ||
name: 'EIP-2535', | ||
link: 'https://eips.ethereum.org/EIPS/eip-2535', | ||
description: 'Diamond proxy', | ||
}, | ||
eip930: { | ||
name: 'ERC-930', | ||
link: 'https://github.com/ethereum/EIPs/issues/930', | ||
description: 'Eternal storage', | ||
}, | ||
clone_with_immutable_arguments: { | ||
name: 'Clones with immutable arguments', | ||
link: 'https://github.com/wighawag/clones-with-immutable-args', | ||
}, | ||
master_copy: { | ||
name: 'GnosisSafe', | ||
link: 'https://github.com/safe-global/safe-smart-account', | ||
}, | ||
comptroller: { | ||
name: 'Compound protocol', | ||
link: 'https://github.com/compound-finance/compound-protocol', | ||
}, | ||
basic_implementation: { | ||
name: 'public implementation getter in proxy smart-contract', | ||
}, | ||
basic_get_implementation: { | ||
name: 'public getImplementation getter in proxy smart-contract', | ||
}, | ||
unknown: { | ||
name: 'Unknown proxy pattern', | ||
}, | ||
}; | ||
|
||
const ContractCodeProxyPattern = ({ type }: Props) => { | ||
const proxyInfo = PROXY_TYPES[type]; | ||
|
||
if (!proxyInfo || type === 'unknown') { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Alert status="warning" flexWrap="wrap" whiteSpace="pre-wrap"> | ||
{ proxyInfo.link ? ( | ||
<> | ||
This proxy smart-contract is detected via <LinkExternal href={ proxyInfo.link }>{ proxyInfo.name }</LinkExternal> | ||
{ proxyInfo.description && ` - ${ proxyInfo.description }` } | ||
</> | ||
) : ( | ||
<> | ||
This proxy smart-contract is detected via { proxyInfo.name } | ||
{ proxyInfo.description && ` - ${ proxyInfo.description }` } | ||
</> | ||
) } | ||
</Alert> | ||
); | ||
}; | ||
|
||
export default React.memo(ContractCodeProxyPattern); |
Binary file modified
BIN
-2.87 KB
(68%)
...screenshots__/ContractCode.pw.tsx_default_with-proxy-address-alert-mobile-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 modified
BIN
-2.98 KB
(67%)
..._screenshots__/ContractCode.pw.tsx_mobile_with-proxy-address-alert-mobile-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
+6.28 KB
...eProxyPattern.pw.tsx_default_proxy-type-with-link-but-without-description-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
+5.65 KB
...ots__/ContractCodeProxyPattern.pw.tsx_default_proxy-type-with-link-mobile-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
+5.23 KB
...enshots__/ContractCodeProxyPattern.pw.tsx_default_proxy-type-without-link-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
+5.43 KB
...hots__/ContractCodeProxyPattern.pw.tsx_mobile_proxy-type-with-link-mobile-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.