mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-02-20 23:08:34 +00:00
* Fix #1569 * Use common component for handling "to" address * If to address becomes invalid, hide contract interact explorer * Add IS_CONTRACT_INTERACTION mode - fix bugs related to contract interact * Bump shepherd version to fix bugs related to metamask + network switches * Update mycrypto link downloads * Update facebook link * Remove console log from checktx * Fix dollar sign on contract address in conf modal * Fix unchecksummed address for metamask signing * Cleanup unused classname * Update generate keystore file description to be correct * Add space to create new wallet banner * Remove extra variable * Do checksumming in library function instead of component * Clear state on address change
72 lines
1.9 KiB
TypeScript
72 lines
1.9 KiB
TypeScript
import React, { Component } from 'react';
|
|
import InteractForm from './components/InteractForm';
|
|
import { InteractExplorer } from './components//InteractExplorer';
|
|
import Contract from 'libs/contracts';
|
|
import { showNotification, TShowNotification } from 'actions/notifications';
|
|
import { connect } from 'react-redux';
|
|
import { getCurrentTo } from 'selectors/transaction';
|
|
|
|
interface State {
|
|
currentContract: Contract | null;
|
|
showExplorer: boolean;
|
|
}
|
|
|
|
interface StateProps {
|
|
currentTo: ReturnType<typeof getCurrentTo>;
|
|
}
|
|
|
|
interface DispatchProps {
|
|
showNotification: TShowNotification;
|
|
}
|
|
|
|
type Props = StateProps & DispatchProps;
|
|
class InteractClass extends Component<Props, State> {
|
|
public initialState: State = {
|
|
currentContract: null,
|
|
showExplorer: false
|
|
};
|
|
public state: State = this.initialState;
|
|
|
|
public accessContract = (contractAbi: string) => () => {
|
|
try {
|
|
const parsedAbi = JSON.parse(contractAbi);
|
|
const contractInstance = new Contract(parsedAbi);
|
|
|
|
this.setState({
|
|
currentContract: contractInstance,
|
|
showExplorer: true
|
|
});
|
|
} catch (e) {
|
|
this.props.showNotification(
|
|
'danger',
|
|
`Contract Access Error: ${(e as Error).message || 'Can not parse contract'}`
|
|
);
|
|
this.resetState();
|
|
}
|
|
};
|
|
|
|
public render() {
|
|
const { showExplorer, currentContract } = this.state;
|
|
|
|
const interactProps = {
|
|
accessContract: this.accessContract,
|
|
resetState: this.resetState
|
|
};
|
|
|
|
return (
|
|
<main className="Interact Tab-content-pane" role="main">
|
|
<InteractForm {...interactProps} />
|
|
<hr />
|
|
{showExplorer &&
|
|
currentContract && (
|
|
<InteractExplorer contractFunctions={Contract.getFunctions(currentContract)} />
|
|
)}
|
|
</main>
|
|
);
|
|
}
|
|
|
|
private resetState = () => this.setState(this.initialState);
|
|
}
|
|
|
|
export const Interact = connect(null, { showNotification })(InteractClass);
|