actions: copy.actions || [],
}
- const normalT = formParams
- if (builder.actions.length == 0) {
+ if (formParams.form === 'normalTx') {
let gasPrice = 0
- switch (normalT.gas.type) {
+ switch (formParams.gas.type) {
case 'Fast':
gasPrice = formParams.state.estimateGas * 2
break
case 'Customize':
- gasPrice = normalT.gas.price
+ gasPrice = formParams.gas.price
break
case 'Standard':
default:
}
builder.actions.push({
- accountAlias: normalT.accountAlias,
- accountId: normalT.accountId,
+ accountAlias: formParams.accountAlias,
+ accountId: formParams.accountId,
assetAlias: 'BTM',
amount: Number(gasPrice),
type: 'spend_account'
})
builder.actions.push({
- accountAlias: normalT.accountAlias,
- accountId: normalT.accountId,
- assetAlias: normalT.assetAlias,
- assetId: normalT.assetId,
- amount: normalT.amount,
+ accountAlias: formParams.accountAlias,
+ accountId: formParams.accountId,
+ assetAlias: formParams.assetAlias,
+ assetId: formParams.assetId,
+ amount: formParams.amount,
type: 'spend_account'
})
builder.actions.push({
- address: normalT.address,
- assetAlias: normalT.assetAlias,
- assetId: normalT.assetId,
- amount: normalT.amount,
+ address: formParams.address,
+ assetAlias: formParams.assetAlias,
+ assetId: formParams.assetId,
+ amount: formParams.amount,
type: 'control_address'
})
}
}))
}
- if (formParams.actions.length !== 0
- && formParams.state.showAdvanced
- && formParams.baseTransaction
- && formParams.submitAction == 'submit') {
- const transaction = JSON.parse(formParams.baseTransaction)
- return signAndSubmitTransaction(transaction, formParams.password)
+ // normal transactions
+ if(formParams.form === 'normalTx'){
+ return buildPromise
+ .then((resp) => {
+ if (resp.status === 'fail') {
+ throw new Error(resp.msg)
+ }
+
+ const body = Object.assign({}, {password: formParams.password, 'transaction': resp.data})
+ return connection.request('/sign-transaction', body)
+ })
+ .then(signResp => {
+ if (signResp.status === 'fail') {
+ throw new Error(signResp.msg)
+ }
+ else if(!signResp.data.signComplete){
+ throw new Error('Signature failed, it might be your password is wrong.')
+ }
+
+ const rawTransaction = signResp.data.transaction.rawTransaction
+ return connection.request('/submit-transaction', {rawTransaction})
+ }).then(dealSignSubmitResp)
}
+ //advanced transactions
+ else{
+ if ( formParams.state.showAdvanced
+ && formParams.baseTransaction
+ && formParams.submitAction == 'submit') {
+ const transaction = JSON.parse(formParams.baseTransaction)
+ return signAndSubmitTransaction(transaction, formParams.password)
+ }
- if (formParams.actions.length !== 0
- && formParams.state.showAdvanced
- && formParams.baseTransaction
- && formParams.submitAction !== 'submit') {
- const transaction = JSON.parse(formParams.baseTransaction)
- return connection.request('/sign-transaction', {
- password: formParams.password,
- transaction
- }).then(resp => {
+ if (formParams.state.showAdvanced
+ && formParams.baseTransaction
+ && formParams.submitAction !== 'submit') {
+ const transaction = JSON.parse(formParams.baseTransaction)
+ return connection.request('/sign-transaction', {
+ password: formParams.password,
+ transaction
+ }).then(resp => {
+ if (resp.status === 'fail') {
+ throw new Error(resp.msg)
+ }
+
+ const id = uuid.v4()
+ dispatch({
+ type: 'GENERATED_TX_HEX',
+ generated: {
+ id: id,
+ hex: JSON.stringify(resp.data.transaction),
+ },
+ })
+ dispatch(push(`/transactions/generated/${id}`))
+ })
+ }
+
+ if (formParams.submitAction == 'submit') {
+ return buildPromise
+ .then((resp) => {
+ if (resp.status === 'fail') {
+ throw new Error(resp.msg)
+ }
+
+ return signAndSubmitTransaction(resp.data, formParams.password)
+ })
+ }
+
+ // submitAction == 'generate'
+ return buildPromise.then(resp => {
if (resp.status === 'fail') {
throw new Error(resp.msg)
}
+ const body = Object.assign({}, {password: formParams.password, 'transaction': resp.data})
+ return connection.request('/sign-transaction', body)
+ }).then(resp => {
+ if (resp.status === 'fail') {
+ throw new Error(resp.msg)
+ }
const id = uuid.v4()
dispatch({
type: 'GENERATED_TX_HEX',
dispatch(push(`/transactions/generated/${id}`))
})
}
-
- if (formParams.submitAction == 'submit') {
- return buildPromise
- .then((resp) => {
- if (resp.status === 'fail') {
- throw new Error(resp.msg)
- }
-
- return signAndSubmitTransaction(resp.data, formParams.password)
- })
- }
-
- // submitAction == 'generate'
- return buildPromise.then(resp => {
- if (resp.status === 'fail') {
- throw new Error(resp.msg)
- }
-
- const body = Object.assign({}, {password: formParams.password, 'transaction': resp.data})
- return connection.request('/sign-transaction', body)
- }).then(resp => {
- if (resp.status === 'fail') {
- throw new Error(resp.msg)
- }
- const id = uuid.v4()
- dispatch({
- type: 'GENERATED_TX_HEX',
- generated: {
- id: id,
- hex: JSON.stringify(resp.data.transaction),
- },
- })
- dispatch(push(`/transactions/generated/${id}`))
- })
}
export default {