openethereum/js/src/dapps/registry/actions.js
Arkadiy Paronyan 46ac2cb94b Backporting to beta (#4741)
* New chains (#4720)

* Add Kovan chain.

* Fix up --testnet.

* Fix tests.

* Fix test.

* fix test

* Fix test.

* Fix to UglifyJS 2.8.2 to fix app build issues (#4723)

* Update classic bootnodes, ref #4717 (#4735)

* allow failure docker beta

* adjust pruning history default to 64 (#4709)

* backporting from master

[ci-skip]update docker-build.sh

* update gitlab.ci

fix docker hub build
[ci skip]

* update gitlab

docker beta-release->latest

* Add registry.

* Add info on forks.

* Fixed spec file

* Support both V1 & V2 DataChanged events in registry (#4734)

* Add info on forks.

* Add new registry ABI

* Import registry2 & fix exports

* Select ABI based on code hash

* Render new event types (owner not available)

* New registry.

* Rename old chain.

* Fix test.

* Another fix.

* Finish rename.

* Fixed fonts URLs (#4579)

* Fix Token Reg Dapp issues in Firefox (#4489)

* Fix overflow issues in Firefox (#4348)

* Fix wrong Promise inferance

* Add new Componennt for Token Images (#4496)

* Revert "Add new Componennt for Token Images (#4496)"

This reverts commit 6ffbdab891f85e4d988e3e8e96fc2c651bd68e04.

* Add StackEventListener (#4745)

* Update testnet detection (#4746)

* Fix Account Selection in Signer (#4744)

* Can pass FormattedMessage to Input (eg. Status // RPC Enabled)

* Simple fixed-width fix for Accoutn Selection in Parity Signer
2017-03-04 18:54:34 +01:00

121 lines
3.5 KiB
JavaScript

// Copyright 2015, 2016 Parity Technologies (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import { registry as registryAbi, registry2 as registryAbi2 } from '~/contracts/abi';
import { api } from './parity.js';
import * as addresses from './addresses/actions.js';
import * as accounts from './Accounts/actions.js';
import * as lookup from './Lookup/actions.js';
import * as events from './Events/actions.js';
import * as names from './Names/actions.js';
import * as records from './Records/actions.js';
import * as reverse from './Reverse/actions.js';
export { addresses, accounts, lookup, events, names, records, reverse };
const REGISTRY_V1_HASHES = [
'0x34f7c51bbb1b1902fbdabfdf04811100f5c9f998f26dd535d2f6f977492c748e', // ropsten
'0x64c3ee34851517a9faecd995c102b339f03e564ad6772dc43a26f993238b20ec' // homestead
];
export const setIsTestnet = (isTestnet) => ({ type: 'set isTestnet', isTestnet });
export const fetchIsTestnet = () => (dispatch) =>
api.net.version()
.then((netVersion) => {
dispatch(setIsTestnet([
'2', // morden
'3', // ropsten
'42' // kovan
].includes(netVersion)));
})
.catch((err) => {
console.error('could not check if testnet');
if (err) {
console.error(err.stack);
}
});
export const setContract = (contract) => ({ type: 'set contract', contract });
export const fetchContract = () => (dispatch) =>
api.parity
.registryAddress()
.then((address) => {
return api.eth
.getCode(address)
.then((code) => {
const codeHash = api.util.sha3(code);
const isVersion1 = REGISTRY_V1_HASHES.includes(codeHash);
console.log(`registry at ${address}, code ${codeHash}, version ${isVersion1 ? 1 : 2}`);
const contract = api.newContract(
isVersion1
? registryAbi
: registryAbi2,
address
);
dispatch(setContract(contract));
dispatch(fetchFee());
dispatch(fetchOwner());
});
})
.catch((err) => {
console.error('could not fetch contract');
if (err) {
console.error(err.stack);
}
});
export const setFee = (fee) => ({ type: 'set fee', fee });
const fetchFee = () => (dispatch, getState) => {
const { contract } = getState();
if (!contract) {
return;
}
contract.instance.fee.call()
.then((fee) => dispatch(setFee(fee)))
.catch((err) => {
console.error('could not fetch fee');
if (err) {
console.error(err.stack);
}
});
};
export const setOwner = (owner) => ({ type: 'set owner', owner });
export const fetchOwner = () => (dispatch, getState) => {
const { contract } = getState();
if (!contract) {
return;
}
contract.instance.owner.call()
.then((owner) => dispatch(setOwner(owner)))
.catch((err) => {
console.error('could not fetch owner');
if (err) {
console.error(err.stack);
}
});
};