import uuid from 'uuid'
-import {chainClient} from 'utility/environment'
+import {chainClient, btmID} from 'utility/environment'
import {parseNonblankJSON} from 'utility/string'
import {push} from 'react-router-redux'
import {baseCreateActions, baseListActions} from 'features/shared/actions'
const accountAlias = formParams.accountAlias
const accountInfo = Object.assign({}, accountAlias!== ''? {alias: accountAlias}: {id: accountId})
+ const isBTM = (formParams.assetId === btmID) || (formParams.assetAlias === 'BTM')
+
return client.accounts.query(accountInfo)
.then( resp => {
if(resp.data[0].xpubs.length > 1){
if(!result.data.checkResult){
throw new Error('PasswordWrong')
}
- return client.transactions.build(builderFunction)
+ if(isBTM)
+ return client.transactions.buildChain(builderFunction)
+ else
+ return client.transactions.build(builderFunction)
})
.then( tpl => {
- const body = Object.assign({}, {password: formParams.password, transaction: tpl.data})
- return client.transactions.sign(body)
+ if(isBTM){
+ const body = Object.assign({}, {password: formParams.password, transactions: tpl.data})
+ return client.transactions.signBatch(body)
+ }
+ else{
+ const body = Object.assign({}, {password: formParams.password, transaction: tpl.data})
+ return client.transactions.sign(body)
+ }
})
.then(signed => {
if(!signed.data.signComplete){
throw {code: 'F_BTM100'}
}
- return client.transactions.submit(signed.data.transaction.rawTransaction)
+ if(isBTM){
+ const rawTransactions = signed.data.transaction.map(tx => tx.rawTransaction)
+ return client.transactions.submitBatch(rawTransactions)
+ }
+ else{
+ return client.transactions.submit(signed.data.transaction.rawTransaction)
+ }
})
.then(submitSucceeded)
}
const body = {actions, ttl: 1}
this.connection.request('/build-transaction', body).then(resp => {
- if (resp.status === 'fail') {
- this.setState({estimateGas: null})
- const errorMsg = resp.code && i18n.exists(`btmError.${resp.code}`) && t(`btmError.${resp.code}`) || resp.msg
- this.props.showError(new Error(errorMsg))
- return
- }
-
return this.connection.request('/estimate-transaction-gas', {
transactionTemplate: resp.data
}).then(resp => {
- if (resp.status === 'fail') {
- this.setState({estimateGas: null})
- const errorMsg = resp.code && i18n.exists(`btmError.${resp.code}`) && t(`btmError.${resp.code}`) || resp.msg
- this.props.showError(new Error(errorMsg))
- return
- }
this.setState({estimateGas: Math.ceil(resp.data.totalNeu/100000)*100000})
+ }).catch(err =>{
+ throw err
})
+ }).catch(err=>{
+ this.setState({estimateGas: null, address: null})
+ const errorMsg = err.code && i18n.exists(`btmError.${err.code}`) && t(`btmError.${err.code}`) || err.msg
+ this.props.showError(new Error(errorMsg))
})
}
).then(resp => checkForError(resp))
},
+ buildChain: (builderBlock, cb) => {
+ const builder = new TransactionBuilder()
+
+ try {
+ builderBlock(builder)
+ } catch (err) {
+ return Promise.reject(err)
+ }
+
+ return shared.tryCallback(
+ client.request('/build-chain-transactions', builder),
+ cb
+ ).then(resp => checkForError(resp)).catch(errors => {throw checkForError(errors)})
+ },
+
buildBatch: (builderBlocks, cb) => {
const builders = []
for (let i in builderBlocks) {
cb
),
- signBatch: (templates, cb) => finalizeBatch(templates)
- // TODO: merge batch errors from finalizeBatch
- .then(finalized => client.signer.signBatch(finalized.successes, cb)),
+ signBatch: (template, cb) => finalize(template)
+ .then(finalized => client.request('/sign-transactions', finalized ).then(resp => checkForError(resp)).catch(errors => {throw checkForError(errors)}),
+ cb
+ ),
submit: (signed, cb) => shared.tryCallback(
client.request('/submit-transaction', {'raw_transaction': signed}).then(resp => checkForError(resp)),
),
submitBatch: (signed, cb) => shared.tryCallback(
- client.request('/submit-transaction', {transactions: signed})
- .then(resp => new shared.BatchResponse(resp)),
+ client.request('/submit-transactions', {'raw_transactions': signed}).then(resp => checkForError(resp))
+ .catch(errors => {throw checkForError(errors)}),
cb
),