Skip to content

Commit

Permalink
Add ABI Cache management tool
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroncox committed Jan 10, 2023
1 parent e164d42 commit 49b81ca
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/modules/main/containers/Sections/Tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { withTranslation } from 'react-i18next';
import { Breadcrumb, Icon, Segment } from 'semantic-ui-react';
import compose from 'lodash/fp/compose';

import ToolsABICache from './Tools/ABICache';
import ToolsAccounts from './Tools/Accounts';
import ToolsAirgrabs from './Tools/Airgrabs';
import ToolsApiPing from './Tools/ApiPing';
Expand Down Expand Up @@ -86,6 +87,7 @@ class ToolsContainer extends Component<Props> {
<Route exact path="/tools" component={ToolsHome} />
<Route path="/tools/accounts" component={ToolsAccounts} />
<Route path="/tools/airgrabs" component={ToolsAirgrabs} />
<Route path="/tools/abi_cache" component={ToolsABICache} />
<Route path="/tools/api_ping" component={ToolsApiPing} />
<Route path="/tools/api_traffic_log" component={ToolsApiTrafficLog} />
<Route path="/tools/contacts" component={ToolsContacts} />
Expand Down
82 changes: 82 additions & 0 deletions app/modules/main/containers/Sections/Tools/ABICache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// @flow
import React, { Component } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import Store from 'electron-store';

import { Button, Header, Segment, Table } from 'semantic-ui-react';
import GlobalFragmentChainLogo from '../../../../../shared/components/Global/Fragment/ChainLogo';

class ToolsABICache extends Component<Props> {
state = {
cleared: undefined
}
clear = () => {
const abiCache = new Store({
name: 'abis'
});
abiCache.clear();
this.setState({
cleared: new Date()
});
}
render = () => {
const { cleared } = this.state;
console.log('cleared', cleared);
const abiCache = new Store({
name: 'abis'
});
return (
<Segment>
<Header>
Network ABI Cache ({abiCache.size} items)
</Header>
<Button onClick={this.clear}>Clear Cache</Button>
<Table definition>
<Table.Body>
{(abiCache.size)
? Object.keys(abiCache.store).map((cache) => {
const [chainId, contract] = cache.split('|');
return (
<Table.Row>
<Table.Cell collapsing>
<GlobalFragmentChainLogo
chainId={chainId}
style={{ height: '2em', width: '2em' }}
/>
</Table.Cell>
<Table.Cell textAlign="left">
{contract}
</Table.Cell>
</Table.Row>
);
})
: (
<Table.Row>
<Table.Cell textAlign="center">
No Cached ABIs
</Table.Cell>
</Table.Row>
)
}
</Table.Body>
</Table>
</Segment>
);
}
}

function mapStateToProps(state) {
return {
};
}

function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
}, dispatch)
};
}

export default withRouter(connect(mapStateToProps, mapDispatchToProps)(ToolsABICache));
4 changes: 4 additions & 0 deletions app/modules/main/containers/Sections/Tools/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ const toolSections = {
}
},
tools_menu_network_utilities_header: {
tools_menu_abi_cache: {
modes: [undefined, false, 'hot', 'ledger', 'watch'],
path: 'tools/abi_cache'
},
tools_menu_performance_header: {
modes: [undefined, false, 'hot', 'ledger', 'watch'],
path: 'tools/api_ping'
Expand Down
1 change: 1 addition & 0 deletions app/renderer/assets/locales/en-US/tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@
"tools_menu_keys": "Key Generator",
"tools_menu_ledger": "Ledger",
"tools_menu_link_service": "Link Service",
"tools_menu_abi_cache": "ABI Cache",
"tools_menu_linkservice_header": "Link Service",
"tools_menu_managekeys": "Manage Keys",
"tools_menu_name_bidding": "Premium Name Bidding",
Expand Down

0 comments on commit 49b81ca

Please sign in to comment.