-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat-cow-swap' into block-recipient
- Loading branch information
Showing
22 changed files
with
956 additions
and
74 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { render, waitFor } from '@/tests/test-utils' | ||
import NamedAddressInfo from '.' | ||
import { faker } from '@faker-js/faker' | ||
import { getContract, type ChainInfo } from '@safe-global/safe-gateway-typescript-sdk' | ||
|
||
const mockChainInfo = { | ||
chainId: '4', | ||
shortName: 'tst', | ||
blockExplorerUriTemplate: { | ||
address: 'https://test.scan.eth/{address}', | ||
api: 'https://test.scan.eth/', | ||
txHash: 'https://test.scan.eth/{txHash}', | ||
}, | ||
} as ChainInfo | ||
|
||
jest.mock('@safe-global/safe-gateway-typescript-sdk', () => ({ | ||
...jest.requireActual('@safe-global/safe-gateway-typescript-sdk'), | ||
getContract: jest.fn(), | ||
__esModule: true, | ||
})) | ||
|
||
describe('NamedAddressInfo', () => { | ||
const getContractMock = getContract as jest.Mock | ||
it('should not fetch contract info if name / logo is given', async () => { | ||
const result = render( | ||
<NamedAddressInfo | ||
address={faker.finance.ethereumAddress()} | ||
name="TestAddressName" | ||
customAvatar="https://img.test.safe.global" | ||
/>, | ||
{ | ||
initialReduxState: { | ||
chains: { | ||
loading: false, | ||
data: [mockChainInfo], | ||
}, | ||
}, | ||
}, | ||
) | ||
|
||
expect(result.getByText('TestAddressName')).toBeVisible() | ||
expect(getContractMock).not.toHaveBeenCalled() | ||
}) | ||
|
||
it('should fetch contract info if name / logo is not given', async () => { | ||
const address = faker.finance.ethereumAddress() | ||
getContractMock.mockResolvedValue({ | ||
displayName: 'Resolved Test Name', | ||
name: 'ResolvedTestName', | ||
logoUri: 'https://img-resolved.test.safe.global', | ||
}) | ||
const result = render(<NamedAddressInfo address={address} />, { | ||
initialReduxState: { | ||
chains: { | ||
loading: false, | ||
data: [mockChainInfo], | ||
}, | ||
}, | ||
}) | ||
|
||
await waitFor(() => { | ||
expect(result.getByText('Resolved Test Name')).toBeVisible() | ||
}) | ||
|
||
expect(getContractMock).toHaveBeenCalledWith('4', address) | ||
}) | ||
}) |
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 useAsync from '@/hooks/useAsync' | ||
import useChainId from '@/hooks/useChainId' | ||
import { getContract } from '@safe-global/safe-gateway-typescript-sdk' | ||
import EthHashInfo from '../EthHashInfo' | ||
import type { EthHashInfoProps } from '../EthHashInfo/SrcEthHashInfo' | ||
|
||
const NamedAddressInfo = ({ address, name, customAvatar, ...props }: EthHashInfoProps) => { | ||
const chainId = useChainId() | ||
const [contract] = useAsync( | ||
() => (!name && !customAvatar ? getContract(chainId, address) : undefined), | ||
[address, chainId, name, customAvatar], | ||
) | ||
|
||
return ( | ||
<EthHashInfo | ||
address={address} | ||
name={name || contract?.displayName || contract?.name} | ||
customAvatar={customAvatar || contract?.logoUri} | ||
{...props} | ||
/> | ||
) | ||
} | ||
|
||
export default NamedAddressInfo |
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
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
Oops, something went wrong.