Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
WIP edit contract parameters #3282
Browse files Browse the repository at this point in the history
  • Loading branch information
ngotchac committed Dec 7, 2016
1 parent 0513066 commit 2152b8f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 50 deletions.
18 changes: 15 additions & 3 deletions js/src/modals/WalletSettings/walletSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,19 @@ class WalletSettings extends Component {
title='The modifications are currently being sent'
state={ this.store.deployState }
>
{ this.store.txhash ? (<TxHash hash={ this.store.txhash } />) : null }
{
this.store.requests.map((req) => {
const key = req.id;

if (req.txhash) {
return (<TxHash key={ key } hash={ req.txhash } />);
}

if (req.rejected) {
return (<p key={ key }>The transaction #{parseInt(key, 16)} has been rejected</p>);
}
})
}
</BusyStep>
);

Expand Down Expand Up @@ -225,7 +237,7 @@ class WalletSettings extends Component {

renderDialogActions () {
const { onClose } = this.props;
const { step, hasErrors, rejected, onNext, send } = this.store;
const { step, hasErrors, rejected, onNext, send, done } = this.store;

const cancelBtn = (
<Button
Expand Down Expand Up @@ -275,7 +287,7 @@ class WalletSettings extends Component {

switch (step) {
case 'SENDING':
return [ closeBtn, sendingBtn ];
return done ? [ closeBtn ] : [ closeBtn, sendingBtn ];

case 'CONFIRMATION':
return [ cancelBtn, sendBtn ];
Expand Down
62 changes: 30 additions & 32 deletions js/src/modals/WalletSettings/walletSettingsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ const STEPS = {

export default class WalletSettingsStore {
@observable step = null;
@observable rejected = false;

@observable txhash = null;
@observable requests = [];
@observable deployState = '';
@observable done = false;

@observable wallet = {
owners: null,
Expand Down Expand Up @@ -178,28 +178,39 @@ export default class WalletSettingsStore {
const walletInstance = this.walletInstance;
this.step = 'SENDING';

this.onTransactionsState('postTransaction');
Promise
.all(changes.map((change) => this.sendChange(change, walletInstance)))
.then((requestIds) => {
this.busyState = 'Waiting for authorization in the Parity Signer';
this.onTransactionsState('checkRequest');
this.requests = requestIds.map((id) => ({ id, rejected: false, txhash: null }));

return Promise
.all(requestIds.map((id) => this.api.pollMethod('parity_checkRequest', id)))
.catch((e) => {
if (e.code === ERROR_CODES.REQUEST_REJECTED) {
this.rejected = true;
return false;
}

throw e;
});
.all(requestIds.map((id) => {
return this.api
.pollMethod('parity_checkRequest', id)
.then((txhash) => {
const index = this.requests.findIndex((r) => r.id === id);
this.requests[index].txhash = txhash;
})
.catch((e) => {
if (e.code === ERROR_CODES.REQUEST_REJECTED) {
const index = this.requests.findIndex((r) => r.id === id);
this.requests[index].rejected = true;
return false;
}

throw e;
});
}));
})
.then((txHashes) => {
this.txhash = txHashes[0];
.then(() => {
this.done = true;
this.onTransactionsState('completed');
});
}

sendChange = (change, walletInstance) => {
@action sendChange = (change, walletInstance) => {
const { method, values } = this.getChangeMethod(change, walletInstance);

const options = {
Expand Down Expand Up @@ -252,12 +263,8 @@ export default class WalletSettingsStore {
}
}

onDeploymentState = (error, data) => {
if (error) {
return console.error('walletSettings::onDeploymentState', error);
}

switch (data.state) {
@action onTransactionsState = (state) => {
switch (state) {
case 'estimateGas':
case 'postTransaction':
this.deployState = 'Preparing transaction for network transmission';
Expand All @@ -267,17 +274,8 @@ export default class WalletSettingsStore {
this.deployState = 'Waiting for confirmation of the transaction in the Parity Secure Signer';
return;

case 'getTransactionReceipt':
this.deployState = 'Waiting for the transaction receipt';
this.txhash = data.txhash;
return;

case 'completed':
this.deployState = 'The modification of the wallet settings have been sent';
return;

default:
console.error('walletSettings::onDeploymentState', 'unknow transaction state', data);
this.deployState = '';
return;
}
}
Expand Down
28 changes: 13 additions & 15 deletions js/src/redux/providers/walletActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function fetchWalletInfo (contract, update, getState) {
const owners = ownersUpdate && ownersUpdate.value || null;
const transactions = transactionsUpdate && transactionsUpdate.value || null;

return fetchWalletConfirmations(contract, owners, transactions, getState)
return fetchWalletConfirmations(contract, update[UPDATE_CONFIRMATIONS], owners, transactions, getState)
.then((update) => {
updates.push(update);
return updates;
Expand Down Expand Up @@ -292,7 +292,7 @@ function fetchWalletDailylimit (contract) {
});
}

function fetchWalletConfirmations (contract, _owners = null, _transactions = null, getState) {
function fetchWalletConfirmations (contract, _operations, _owners = null, _transactions = null, getState) {
const walletInstance = contract.instance;

const wallet = getState().wallet.wallets[contract.address];
Expand Down Expand Up @@ -331,6 +331,8 @@ function fetchWalletConfirmations (contract, _owners = null, _transactions = nul
return confirmations;
}

// Only fetch confirmations for operations not
// yet confirmed (ie. not yet a transaction)
if (transactions) {
const operations = transactions
.filter((t) => t.operation)
Expand All @@ -348,7 +350,12 @@ function fetchWalletConfirmations (contract, _owners = null, _transactions = nul
return confirmations;
}

// const operations = uniq([].concat(
// confirmations.map((conf) => conf.operation),
// Array.isArray(operations) ? operations : []
// ));
const operations = confirmations.map((conf) => conf.operation);

return Promise
.all(operations.map((op) => fetchOperationConfirmations(contract, op, owners)))
.then((confirmedBys) => {
Expand Down Expand Up @@ -439,16 +446,18 @@ function parseLogs (logs) {
};
return;

case signatures.ConfirmationNeeded:
case signatures.Confirmation:
case signatures.Revoke:
const operation = log.params.operation.value;
const operation = bytesToHex(log.params.operation.value);

updates[address] = {
...prev,
[ UPDATE_CONFIRMATIONS ]: uniq(
(prev.operations || []).concat(operation)
(prev[UPDATE_CONFIRMATIONS] || []).concat(operation)
)
};

return;

case signatures.Deposit:
Expand All @@ -459,17 +468,6 @@ function parseLogs (logs) {
[ UPDATE_TRANSACTIONS ]: true
};
return;

case signatures.ConfirmationNeeded:
const op = log.params.operation.value;

updates[address] = {
...prev,
[ UPDATE_CONFIRMATIONS ]: uniq(
(prev.operations || []).concat(op)
)
};
return;
}
});

Expand Down

0 comments on commit 2152b8f

Please sign in to comment.