From 653edd0c5a3be2f4b0d12bf3db4dee7fc380bc28 Mon Sep 17 00:00:00 2001 From: Yongfeng LI Date: Fri, 29 Dec 2017 20:45:20 +0800 Subject: [PATCH] correct build transaction --- src/features/transactions/actions.js | 22 ++++++++++++++++------ .../transactions/components/New/FormActionItem.jsx | 2 +- src/features/transactions/components/New/New.jsx | 18 ++++++++---------- src/sdk/api/transactions.js | 2 +- src/sdk/connection.js | 6 +++--- src/sdk/index.js | 2 ++ 6 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/features/transactions/actions.js b/src/features/transactions/actions.js index 1c69abc..b10a2e5 100644 --- a/src/features/transactions/actions.js +++ b/src/features/transactions/actions.js @@ -59,8 +59,8 @@ function preprocessTransaction(formParams) { function getTemplateXpubs(tpl) { const xpubs = [] - tpl.signingInstructions.forEach((instruction) => { - instruction.witnessComponents.forEach((component) => { + tpl['signing_instructions'].forEach((instruction) => { + instruction['witness_components'].forEach((component) => { component.keys.forEach((key) => { xpubs.push(key.xpub) }) @@ -73,7 +73,16 @@ form.submitForm = (formParams) => function(dispatch) { const buildPromise = chainClient().transactions.build(builder => { const processed = preprocessTransaction(formParams) - builder.actions = processed.actions + builder.actions = processed.actions.map(action => { + return { + amount: action.amount, + account_id: action.accountId, + account_alias: action.accountAlias, + asset_id: action.assetId, + asset_alias: action.assetAlias, + type: action.type + } + }) if (processed.baseTransaction) { builder.baseTransaction = processed.baseTransaction } @@ -81,7 +90,7 @@ form.submitForm = (formParams) => function(dispatch) { if (formParams.submitAction == 'submit') { return buildPromise - .then(tpl => { + .then(({data: tpl}) => { const signer = chainSigner() getTemplateXpubs(tpl).forEach(key => { @@ -104,13 +113,14 @@ form.submitForm = (formParams) => function(dispatch) { // submitAction == 'generate' return buildPromise .then(tpl => { + const data = tpl.data const signer = chainSigner() - getTemplateXpubs(tpl).forEach(key => { + getTemplateXpubs(data).forEach(key => { signer.addKey(key, chainClient().mockHsm.signerConnection) }) - return signer.sign({...tpl, allowAdditionalActions: true}) + return signer.sign({...data, allowAdditionalActions: true}) }) .then(signed => { const id = uuid.v4() diff --git a/src/features/transactions/components/New/FormActionItem.jsx b/src/features/transactions/components/New/FormActionItem.jsx index b37539e..3c6fd4b 100644 --- a/src/features/transactions/components/New/FormActionItem.jsx +++ b/src/features/transactions/components/New/FormActionItem.jsx @@ -111,7 +111,7 @@ export default class ActionItem extends React.Component { {visible.amount && } - {this.state.referenceDataOpen && + {false && this.state.referenceDataOpen && } {!this.state.referenceDataOpen && diff --git a/src/features/transactions/components/New/New.jsx b/src/features/transactions/components/New/New.jsx index 136fbea..df1f57e 100644 --- a/src/features/transactions/components/New/New.jsx +++ b/src/features/transactions/components/New/New.jsx @@ -45,12 +45,11 @@ class Form extends React.Component { } submitWithValidation(data) { - const lagThreshold = 5 - if (this.props.replicationLag === null || this.props.replicationLag >= lagThreshold) { - return Promise.reject({ - _error: `Replication lag must be less than ${lagThreshold} to submit transactions via the dashboard. Please wait for the local core to catch up to the generator.` - }) - } + // if (this.props.replicationLag === null || this.props.replicationLag >= lagThreshold) { + // return Promise.reject({ + // _error: `Replication lag must be less than ${lagThreshold} to submit transactions via the dashboard. Please wait for the local core to catch up to the generator.` + // }) + // } return new Promise((resolve, reject) => { this.props.submitForm(data) @@ -114,11 +113,11 @@ class Form extends React.Component { > Issue Spend from account - Spend unspent output + {/*Spend unspent output*/} Control with account Control with receiver - Retire - Set transaction reference data + {/*Retire*/} + {/*Set transaction reference data*/} @@ -204,7 +203,6 @@ const validate = values => { export default BaseNew.connect( state => ({ ...BaseNew.mapStateToProps('transaction')(state), - replicationLag: state.core.replicationLag, }), BaseNew.mapDispatchToProps('transaction'), reduxForm({ diff --git a/src/sdk/api/transactions.js b/src/sdk/api/transactions.js index 5cba86f..21fe4b4 100644 --- a/src/sdk/api/transactions.js +++ b/src/sdk/api/transactions.js @@ -367,7 +367,7 @@ const transactionsAPI = (client) => { } return shared.tryCallback( - client.request('/build-transaction', [builder]).then(resp => checkForError(resp[0])), + client.request('/build-transaction', builder, true), cb ) }, diff --git a/src/sdk/connection.js b/src/sdk/connection.js index 36d966e..9232622 100644 --- a/src/sdk/connection.js +++ b/src/sdk/connection.js @@ -87,14 +87,14 @@ class Connection { * @param {object} [body={}] * @returns {Promise} */ - request(path, body = {}) { + request(path, body = {}, skipSnakeize = false) { if (!body) { body = {} } // Convert camelcased request body field names to use snakecase for API // processing. - const snakeBody = snakeize(body) // Ssssssssssss + const snakeBody = skipSnakeize ? body : snakeize(body) // Ssssssssssss let req = { method: 'POST', @@ -171,7 +171,7 @@ class Connection { }).then((body) => { // After processing the response, convert snakecased field names to // camelcase to match language conventions. - return camelize(body) + return skipSnakeize? body : camelize(body) }) }) } diff --git a/src/sdk/index.js b/src/sdk/index.js index e294c68..72faead 100644 --- a/src/sdk/index.js +++ b/src/sdk/index.js @@ -1,7 +1,9 @@ const Client = require('./client') const Connection = require('./connection') +const HsmSigner = require('./api/hsmSigner') module.exports = { Client, Connection, + HsmSigner } -- 2.11.0