Use default account for sending transactions (#5588)
* Add default account for Wallet Creation * Use default account by default, save current used account * Fix tests
This commit is contained in:
parent
48ddd8b312
commit
8642300d74
@ -36,7 +36,7 @@ import ContextProvider from '~/ui/ContextProvider';
|
|||||||
import muiTheme from '~/ui/Theme';
|
import muiTheme from '~/ui/Theme';
|
||||||
import MainApplication from './main';
|
import MainApplication from './main';
|
||||||
|
|
||||||
import { patchApi } from '~/util/tx';
|
import { loadSender, patchApi } from '~/util/tx';
|
||||||
import { setApi } from '~/redux/providers/apiActions';
|
import { setApi } from '~/redux/providers/apiActions';
|
||||||
|
|
||||||
import './environment';
|
import './environment';
|
||||||
@ -66,6 +66,7 @@ if (window.location.hash && window.location.hash.indexOf(AUTH_HASH) === 0) {
|
|||||||
const api = new SecureApi(`${urlScheme}${parityUrl}`, token);
|
const api = new SecureApi(`${urlScheme}${parityUrl}`, token);
|
||||||
|
|
||||||
patchApi(api);
|
patchApi(api);
|
||||||
|
loadSender(api);
|
||||||
ContractInstances.create(api);
|
ContractInstances.create(api);
|
||||||
|
|
||||||
const store = initStore(api, hashHistory);
|
const store = initStore(api, hashHistory);
|
||||||
|
@ -27,7 +27,11 @@ let component;
|
|||||||
let onClose;
|
let onClose;
|
||||||
|
|
||||||
function createApi () {
|
function createApi () {
|
||||||
api = {};
|
api = {
|
||||||
|
parity: {
|
||||||
|
getNewDappsDefaultAddress: sinon.stub().resolves('')
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return api;
|
return api;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ import { wallet as walletCode, walletLibrary as walletLibraryCode, walletLibrary
|
|||||||
|
|
||||||
import { validateUint, validateAddress, validateName } from '~/util/validation';
|
import { validateUint, validateAddress, validateName } from '~/util/validation';
|
||||||
import { toWei } from '~/api/util/wei';
|
import { toWei } from '~/api/util/wei';
|
||||||
import { deploy } from '~/util/tx';
|
import { deploy, getSender, loadSender, setSender } from '~/util/tx';
|
||||||
import WalletsUtils from '~/util/wallets';
|
import WalletsUtils from '~/util/wallets';
|
||||||
|
|
||||||
const STEPS = {
|
const STEPS = {
|
||||||
@ -120,10 +120,17 @@ export default class CreateWalletStore {
|
|||||||
this.api = api;
|
this.api = api;
|
||||||
|
|
||||||
this.step = this.stepsKeys[0];
|
this.step = this.stepsKeys[0];
|
||||||
this.wallet.account = Object.values(accounts)[0].address;
|
this.wallet.account = getSender() || Object.values(accounts)[0].address;
|
||||||
this.validateWallet(this.wallet);
|
this.validateWallet(this.wallet);
|
||||||
this.onClose = onClose;
|
this.onClose = onClose;
|
||||||
this.onSetRequest = onSetRequest;
|
this.onSetRequest = onSetRequest;
|
||||||
|
|
||||||
|
loadSender(this.api)
|
||||||
|
.then((defaultAccount) => {
|
||||||
|
if (defaultAccount !== this.wallet.account) {
|
||||||
|
this.onChange({ account: defaultAccount });
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@action onTypeChange = (type) => {
|
@action onTypeChange = (type) => {
|
||||||
@ -221,6 +228,7 @@ export default class CreateWalletStore {
|
|||||||
|
|
||||||
const contract = this.api.newContract(walletAbi);
|
const contract = this.api.newContract(walletAbi);
|
||||||
|
|
||||||
|
setSender(account);
|
||||||
this.wallet = this.getWalletWithMeta(this.wallet);
|
this.wallet = this.getWalletWithMeta(this.wallet);
|
||||||
this.onClose();
|
this.onClose();
|
||||||
return deploy(contract, options, [ owners, required, daylimit ])
|
return deploy(contract, options, [ owners, required, daylimit ])
|
||||||
|
@ -24,7 +24,7 @@ import { bindActionCreators } from 'redux';
|
|||||||
import { Button, GasPriceEditor, IdentityIcon, Portal, Warning } from '~/ui';
|
import { Button, GasPriceEditor, IdentityIcon, Portal, Warning } from '~/ui';
|
||||||
import { CancelIcon } from '~/ui/Icons';
|
import { CancelIcon } from '~/ui/Icons';
|
||||||
import { ERRORS, validateAbi, validateCode, validateName, validatePositiveNumber } from '~/util/validation';
|
import { ERRORS, validateAbi, validateCode, validateName, validatePositiveNumber } from '~/util/validation';
|
||||||
import { deploy, deployEstimateGas } from '~/util/tx';
|
import { deploy, deployEstimateGas, getSender, loadSender, setSender } from '~/util/tx';
|
||||||
import { setRequest } from '~/redux/providers/requestsActions';
|
import { setRequest } from '~/redux/providers/requestsActions';
|
||||||
|
|
||||||
import DetailsStep from './DetailsStep';
|
import DetailsStep from './DetailsStep';
|
||||||
@ -94,7 +94,7 @@ class DeployContract extends Component {
|
|||||||
description: '',
|
description: '',
|
||||||
descriptionError: null,
|
descriptionError: null,
|
||||||
extras: false,
|
extras: false,
|
||||||
fromAddress: Object.keys(this.props.accounts)[0],
|
fromAddress: getSender() || Object.keys(this.props.accounts)[0],
|
||||||
fromAddressError: null,
|
fromAddressError: null,
|
||||||
name: '',
|
name: '',
|
||||||
nameError: ERRORS.invalidName,
|
nameError: ERRORS.invalidName,
|
||||||
@ -110,6 +110,13 @@ class DeployContract extends Component {
|
|||||||
if (abi && code) {
|
if (abi && code) {
|
||||||
this.setState({ abi, code });
|
this.setState({ abi, code });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadSender(this.context.api)
|
||||||
|
.then((defaultAccount) => {
|
||||||
|
if (defaultAccount !== this.state.fromAddress) {
|
||||||
|
this.setState({ fromAddress: defaultAccount });
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps (nextProps) {
|
componentWillReceiveProps (nextProps) {
|
||||||
@ -467,6 +474,7 @@ class DeployContract extends Component {
|
|||||||
|
|
||||||
const contract = api.newContract(abiParsed);
|
const contract = api.newContract(abiParsed);
|
||||||
|
|
||||||
|
setSender(fromAddress);
|
||||||
this.onClose();
|
this.onClose();
|
||||||
deploy(contract, options, params, true)
|
deploy(contract, options, params, true)
|
||||||
.then((requestId) => {
|
.then((requestId) => {
|
||||||
|
@ -25,6 +25,7 @@ import { CancelIcon, NextIcon, PrevIcon } from '~/ui/Icons';
|
|||||||
import { MAX_GAS_ESTIMATION } from '~/util/constants';
|
import { MAX_GAS_ESTIMATION } from '~/util/constants';
|
||||||
import { validateAddress, validateUint } from '~/util/validation';
|
import { validateAddress, validateUint } from '~/util/validation';
|
||||||
import { parseAbiType } from '~/util/abi';
|
import { parseAbiType } from '~/util/abi';
|
||||||
|
import { setSender } from '~/util/tx';
|
||||||
|
|
||||||
import AdvancedStep from './AdvancedStep';
|
import AdvancedStep from './AdvancedStep';
|
||||||
import DetailsStep from './DetailsStep';
|
import DetailsStep from './DetailsStep';
|
||||||
@ -307,6 +308,7 @@ class ExecuteContract extends Component {
|
|||||||
value: api.util.toWei(amount || 0)
|
value: api.util.toWei(amount || 0)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setSender(fromAddress);
|
||||||
func.postTransaction(options, values);
|
func.postTransaction(options, values);
|
||||||
this.onClose();
|
this.onClose();
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,38 @@
|
|||||||
|
|
||||||
import WalletsUtils from '~/util/wallets';
|
import WalletsUtils from '~/util/wallets';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The sender is by default (when the UI loads) the
|
||||||
|
* default dapp address. It can then be modified when
|
||||||
|
* sending transactions....
|
||||||
|
*/
|
||||||
|
let currentSender = '';
|
||||||
|
let hasCurrentSenderChanged = false;
|
||||||
|
|
||||||
|
export function getSender () {
|
||||||
|
currentSender;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function loadSender (api) {
|
||||||
|
// If the current sender has been changed
|
||||||
|
// then don't bother checking changes of the
|
||||||
|
// default sender
|
||||||
|
if (hasCurrentSenderChanged) {
|
||||||
|
return Promise.resolve(currentSender);
|
||||||
|
}
|
||||||
|
|
||||||
|
return api.parity.getNewDappsDefaultAddress()
|
||||||
|
.then((defaultAccount) => {
|
||||||
|
currentSender = defaultAccount;
|
||||||
|
return defaultAccount;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setSender (sender) {
|
||||||
|
currentSender = sender;
|
||||||
|
hasCurrentSenderChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
export function trackRequest (api, options, statusCallback) {
|
export function trackRequest (api, options, statusCallback) {
|
||||||
const { requestId, transactionHash } = options;
|
const { requestId, transactionHash } = options;
|
||||||
const txHashPromise = transactionHash
|
const txHashPromise = transactionHash
|
||||||
|
@ -26,6 +26,7 @@ import { setVisibleAccounts } from '~/redux/providers/personalActions';
|
|||||||
import { Actionbar, Button, Page, Portal } from '~/ui';
|
import { Actionbar, Button, Page, Portal } from '~/ui';
|
||||||
import { CancelIcon, DeleteIcon, EditIcon, PlayIcon, VisibleIcon } from '~/ui/Icons';
|
import { CancelIcon, DeleteIcon, EditIcon, PlayIcon, VisibleIcon } from '~/ui/Icons';
|
||||||
import Editor from '~/ui/Editor';
|
import Editor from '~/ui/Editor';
|
||||||
|
import { getSender, loadSender } from '~/util/tx';
|
||||||
|
|
||||||
import Header from '../Account/Header';
|
import Header from '../Account/Header';
|
||||||
import Delete from '../Address/Delete';
|
import Delete from '../Address/Delete';
|
||||||
@ -52,7 +53,7 @@ class Contract extends Component {
|
|||||||
|
|
||||||
state = {
|
state = {
|
||||||
contract: null,
|
contract: null,
|
||||||
fromAddress: '',
|
fromAddress: getSender(),
|
||||||
showDeleteDialog: false,
|
showDeleteDialog: false,
|
||||||
showEditDialog: false,
|
showEditDialog: false,
|
||||||
showExecuteDialog: false,
|
showExecuteDialog: false,
|
||||||
@ -76,6 +77,13 @@ class Contract extends Component {
|
|||||||
api
|
api
|
||||||
.subscribe('eth_blockNumber', this.queryContract)
|
.subscribe('eth_blockNumber', this.queryContract)
|
||||||
.then(blockSubscriptionId => this.setState({ blockSubscriptionId }));
|
.then(blockSubscriptionId => this.setState({ blockSubscriptionId }));
|
||||||
|
|
||||||
|
loadSender(api)
|
||||||
|
.then((defaultAccount) => {
|
||||||
|
if (defaultAccount !== this.state.fromAddress) {
|
||||||
|
this.onFromAddressChange(null, defaultAccount);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps (nextProps) {
|
componentWillReceiveProps (nextProps) {
|
||||||
|
Loading…
Reference in New Issue
Block a user