forked from blockscout/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Contract interaction improvements (blockscout#1875)
* add contract method id tag * add form submit type * refactor types for SmartConstract and make new component for Contract ABI methods * move contract method form inside ABI folder * handle form submit and display result * clean-up * change copied text * handle case when blockchain interaction is not configured * tests and screenshots update * fix bug wit WEI checkbox
- Loading branch information
1 parent
7862859
commit f812b89
Showing
99 changed files
with
996 additions
and
933 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { UseAccountReturnType } from 'wagmi'; | ||
import { useAccount } from 'wagmi'; | ||
|
||
import config from 'configs/app'; | ||
|
||
function useAccountFallback(): UseAccountReturnType { | ||
return { | ||
address: undefined, | ||
addresses: undefined, | ||
chain: undefined, | ||
chainId: undefined, | ||
connector: undefined, | ||
isConnected: false, | ||
isConnecting: false, | ||
isDisconnected: true, | ||
isReconnecting: false, | ||
status: 'disconnected', | ||
}; | ||
} | ||
|
||
const hook = config.features.blockchainInteraction.isEnabled ? useAccount : useAccountFallback; | ||
|
||
export default hook; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import React from 'react'; | ||
|
||
import * as addressMock from 'mocks/address/address'; | ||
import * as contractInfoMock from 'mocks/contract/info'; | ||
import * as contractMethodsMock from 'mocks/contract/methods'; | ||
import { ENVS_MAP } from 'playwright/fixtures/mockEnvs'; | ||
import * as socketServer from 'playwright/fixtures/socketServer'; | ||
import { test, expect } from 'playwright/lib'; | ||
|
||
import AddressContract from './AddressContract.pwstory'; | ||
|
||
const hash = addressMock.contract.hash; | ||
|
||
test.beforeEach(async({ mockApiResponse }) => { | ||
await mockApiResponse('address', addressMock.contract, { pathParams: { hash } }); | ||
await mockApiResponse('contract', contractInfoMock.verified, { pathParams: { hash } }); | ||
await mockApiResponse('contract_methods_read', contractMethodsMock.read, { pathParams: { hash }, queryParams: { is_custom_abi: 'false' } }); | ||
await mockApiResponse('contract_methods_write', contractMethodsMock.write, { pathParams: { hash }, queryParams: { is_custom_abi: 'false' } }); | ||
}); | ||
|
||
test.describe('ABI functionality', () => { | ||
test('read', async({ render, createSocket }) => { | ||
const hooksConfig = { | ||
router: { | ||
query: { hash, tab: 'read_contract' }, | ||
}, | ||
}; | ||
const component = await render(<AddressContract/>, { hooksConfig }, { withSocket: true }); | ||
const socket = await createSocket(); | ||
await socketServer.joinChannel(socket, 'addresses:' + addressMock.contract.hash.toLowerCase()); | ||
|
||
await expect(component.getByRole('button', { name: 'Connect wallet' })).toBeVisible(); | ||
await component.getByText('FLASHLOAN_PREMIUM_TOTAL').click(); | ||
await expect(component.getByRole('button', { name: 'Read' })).toBeVisible(); | ||
}); | ||
|
||
test('read, no wallet client', async({ render, createSocket, mockEnvs }) => { | ||
const hooksConfig = { | ||
router: { | ||
query: { hash, tab: 'read_contract' }, | ||
}, | ||
}; | ||
await mockEnvs(ENVS_MAP.noWalletClient); | ||
const component = await render(<AddressContract/>, { hooksConfig }, { withSocket: true, withWalletClient: false }); | ||
const socket = await createSocket(); | ||
await socketServer.joinChannel(socket, 'addresses:' + addressMock.contract.hash.toLowerCase()); | ||
|
||
await expect(component.getByRole('button', { name: 'Connect wallet' })).toBeHidden(); | ||
await component.getByText('FLASHLOAN_PREMIUM_TOTAL').click(); | ||
await expect(component.getByRole('button', { name: 'Read' })).toBeVisible(); | ||
}); | ||
|
||
test('write', async({ render, createSocket }) => { | ||
const hooksConfig = { | ||
router: { | ||
query: { hash, tab: 'write_contract' }, | ||
}, | ||
}; | ||
const component = await render(<AddressContract/>, { hooksConfig }, { withSocket: true }); | ||
const socket = await createSocket(); | ||
await socketServer.joinChannel(socket, 'addresses:' + addressMock.contract.hash.toLowerCase()); | ||
|
||
await expect(component.getByRole('button', { name: 'Connect wallet' })).toBeVisible(); | ||
await component.getByText('setReserveInterestRateStrategyAddress').click(); | ||
await expect(component.getByLabel('2.').getByRole('button', { name: 'Simulate' })).toBeEnabled(); | ||
await expect(component.getByLabel('2.').getByRole('button', { name: 'Write' })).toBeEnabled(); | ||
|
||
await component.getByText('pause').click(); | ||
await expect(component.getByLabel('5.').getByRole('button', { name: 'Simulate' })).toBeHidden(); | ||
await expect(component.getByLabel('5.').getByRole('button', { name: 'Write' })).toBeEnabled(); | ||
}); | ||
|
||
test('write, no wallet client', async({ render, createSocket, mockEnvs }) => { | ||
const hooksConfig = { | ||
router: { | ||
query: { hash, tab: 'write_contract' }, | ||
}, | ||
}; | ||
await mockEnvs(ENVS_MAP.noWalletClient); | ||
|
||
const component = await render(<AddressContract/>, { hooksConfig }, { withSocket: true, withWalletClient: false }); | ||
const socket = await createSocket(); | ||
await socketServer.joinChannel(socket, 'addresses:' + addressMock.contract.hash.toLowerCase()); | ||
|
||
await expect(component.getByRole('button', { name: 'Connect wallet' })).toBeHidden(); | ||
await component.getByText('setReserveInterestRateStrategyAddress').click(); | ||
await expect(component.getByLabel('2.').getByRole('button', { name: 'Simulate' })).toBeEnabled(); | ||
await expect(component.getByLabel('2.').getByRole('button', { name: 'Write' })).toBeDisabled(); | ||
|
||
await component.getByText('pause').click(); | ||
await expect(component.getByLabel('5.').getByRole('button', { name: 'Simulate' })).toBeHidden(); | ||
await expect(component.getByLabel('5.').getByRole('button', { name: 'Write' })).toBeDisabled(); | ||
}); | ||
}); |
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,18 @@ | ||
import { useRouter } from 'next/router'; | ||
import React from 'react'; | ||
|
||
import useApiQuery from 'lib/api/useApiQuery'; | ||
import useContractTabs from 'lib/hooks/useContractTabs'; | ||
import getQueryParamString from 'lib/router/getQueryParamString'; | ||
|
||
import AddressContract from './AddressContract'; | ||
|
||
const AddressContractPwStory = () => { | ||
const router = useRouter(); | ||
const hash = getQueryParamString(router.query.hash); | ||
const addressQuery = useApiQuery('address', { pathParams: { hash } }); | ||
const { tabs } = useContractTabs(addressQuery.data, false); | ||
return <AddressContract tabs={ tabs } shouldRender={ true } isLoading={ false }/>; | ||
}; | ||
|
||
export default AddressContractPwStory; |
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.