Skip to content

Commit

Permalink
feat: 🎸 cross chain finish
Browse files Browse the repository at this point in the history
  • Loading branch information
hzz780 committed Feb 22, 2020
1 parent 8726417 commit b256cb1
Show file tree
Hide file tree
Showing 15 changed files with 617 additions and 192 deletions.
14 changes: 8 additions & 6 deletions app/controller/crossTransactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ class CrossTransactionsController extends baseController {
try {
const result = await ctx.model.CrossTransactions.findAll({
where: {
address,
from: address,
status: 0
},
offset: parseInt(offset, 10),
limit: parseInt(limit, 10)
limit: parseInt(limit, 10),
order: [[ 'id', 'DESC' ]]
});
this.formatOutput('get', result);
} catch (error) {
Expand All @@ -36,7 +37,6 @@ class CrossTransactionsController extends baseController {
const { ctx } = this;
const {
tx_id,
address,
from,
to,
symbol,
Expand All @@ -53,7 +53,6 @@ class CrossTransactionsController extends baseController {

const options = {
tx_id,
address,
from,
to,
symbol,
Expand All @@ -70,12 +69,15 @@ class CrossTransactionsController extends baseController {

const keysRule = {
tx_id: 'string',
address: 'string',
from: 'string',
to: 'string',
symbol: 'string',
amount: 'string',
memo: 'string',
memo: {
type: 'string',
required: false,
allowEmpty: true
},
time: 'string',
send_node: 'string',
receive_node: 'string',
Expand Down
6 changes: 2 additions & 4 deletions app/service/crossTransactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class CrossTransactionsService extends Service {
const {ctx} = this;
const {
tx_id,
address,
from,
to,
symbol,
Expand All @@ -43,14 +42,13 @@ class CrossTransactionsService extends Service {
} = options;

const verifyResult = signatureVerify({
address,
address: from,
signed_address,
public_key
});
if (verifyResult) {
return ctx.model.CrossTransactions.create({
tx_id,
address,
from,
to,
symbol,
Expand Down Expand Up @@ -86,7 +84,7 @@ class CrossTransactionsService extends Service {
}, {
where: {
tx_id,
address
from: address
}
});
}
Expand Down
2 changes: 2 additions & 0 deletions app/web/js/langConfig/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default {
'aelf.Contact': 'Contact',
'aelf.Commit': 'Commit',
'aelf.Confirm': 'Confirm',
'aelf.Pending': 'Pending',
'aelf.New contacts': 'New contacts',
'aelf.Name': 'Name',
'aelf.Payee wallet address': 'Payee wallet address',
Expand Down Expand Up @@ -127,6 +128,7 @@ export default {
'aelf.To Address': 'To Address',
'aelf.Transaction': 'Transaction',
'aelf.Amount to send': 'Value / Amount to Send',
'aelf.Memo to send': 'Memo to Send',
'aelf.Balance': 'Balance',
'aelf.New Provider': 'New Provider',
'aelf.slow': 'Slow',
Expand Down
2 changes: 2 additions & 0 deletions app/web/js/langConfig/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default {
'aelf.Contact': '联系人',
'aelf.Commit': '提交',
'aelf.Confirm': '确认',
'aelf.Pending': '请稍等',
'aelf.New contacts': '新建联系人',
'aelf.Name': '姓名',
'aelf.Payee wallet address': '钱包地址',
Expand Down Expand Up @@ -127,6 +128,7 @@ export default {
'aelf.To Address': '发送地址',
'aelf.Transaction': '交易',
'aelf.Amount to send': '发送值/价值',
'aelf.Memo to send': '备注',
'aelf.Balance': '等量',
'aelf.New Provider': '新供应商',
'aelf.slow': '慢',
Expand Down
56 changes: 43 additions & 13 deletions app/web/js/pages/Asset/TransactionDetail/TransactionDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import style from './TransactionDetail.scss';
import {hashHistory} from 'react-router';

import { BigNumber } from 'bignumber.js';
import AElf from 'aelf-sdk';

import NavNormal from '../../NavNormal/NavNormal';

Expand Down Expand Up @@ -40,20 +41,28 @@ export default class TransactionDetail extends Component {
this.tokenName = getParam('token', stringTemp);
this.decimals = getParam('decimals', stringTemp);
this.contractAddress = getParam('contract_address', stringTemp);
this.isCrossChain = getParam('is_cross_chain', stringTemp);
this.from = getParam('from', stringTemp);
this.to = getParam('to', stringTemp);
this.type = getParam('type', stringTemp);

this.aelf = initAelf({
chainOnly: true,
tokenName: this.tokenName,
contractAddress: this.contractAddress
});
this.aelf = new AElf(new AElf.providers.HttpProvider(
window.defaultConfig.WEB_API_INFO[window.defaultConfig.chainId].url)
);

// cross transfer txid
if (this.from && this.to) {
const providerUrl = window.defaultConfig.WEB_API_INFO[this.to].url;
this.aelf.setProvider(new AElf.providers.HttpProvider(providerUrl));
}
}

componentDidMount() {
this.getChainStatus();
}

getChainStatus() {
this.aelf.aelf.chain.getChainStatus().then(result => {
this.aelf.chain.getChainStatus().then(result => {
this.setState({
chainStatus: result
});
Expand All @@ -63,18 +72,17 @@ export default class TransactionDetail extends Component {
getTxInfo() {
let txid = this.txid;
let tokenName = this.tokenName;
let contractAddress = this.contractAddress;

let txInfo = {
txState: false,
txResult: null,
txid,
tokenName,
contractAddress
tokenName
};
try {
if (txid && contractAddress) {
let result = this.aelf.aelf.chain.getTxResult(txid, {sync: true});
if (txid) {

let result = this.aelf.chain.getTxResult(txid, {sync: true});
if (result.error) {
txInfo.txResult = result.error;
}
Expand Down Expand Up @@ -141,7 +149,12 @@ export default class TransactionDetail extends Component {

let addressFromShow = Transaction.From;
let addressToShow = toShow;
if (MethodName === 'CrossChainTransfer') {
// cross chain
if (this.from && this.to) {
addressFromShow = addressPrefixSuffix(addressFromShow, null, this.from);
addressToShow = addressPrefixSuffix(addressToShow, null, this.to);
}
else if (MethodName === 'CrossChainTransfer') {
addressFromShow = addressPrefixSuffix(addressFromShow);
addressToShow = addressPrefixSuffix(addressToShow, toChainId);
}
Expand Down Expand Up @@ -254,8 +267,22 @@ export default class TransactionDetail extends Component {
</div>;
}

renderTurnToCrossPendingHTML() {
return (<div className={style.crossPendingBottom}>
<AelfButton
onClick={() => {
hashHistory.push('/personalcenter/unconfirmedtransactions');
}}
text = 'Cross chain transactions to be confirmed'
/>
</div>);
}

renderTurnToExplorerHTML(txId) {
const explorerURL = window.defaultConfig.explorerURL + '/tx/' + txId;
let explorerURL = window.defaultConfig.explorerURL + '/tx/' + txId;
if (this.to) {
explorerURL = window.defaultConfig.WEB_API_INFO[this.to].explorer + '/tx/' + txId;
}

return (<div className={style.bottom}>
<AelfButton
Expand Down Expand Up @@ -307,6 +334,8 @@ export default class TransactionDetail extends Component {
const blockHeightHTML = this.renderBlockHeightHTML(BlockNumber, Status);
const turnToExplorerHTML = this.renderTurnToExplorerHTML(txid);

const turnToCrossPendingList = this.isCrossChain ? this.renderTurnToCrossPendingHTML() : null;

const containerStyle = getPageContainerStyle();
let txInfoContainerStyle = Object.assign({}, containerStyle);
txInfoContainerStyle.height -= 150;
Expand Down Expand Up @@ -334,6 +363,7 @@ export default class TransactionDetail extends Component {
{notTransferHtml}
</div>
</div>
{turnToCrossPendingList}
{turnToExplorerHTML}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@

.bottom {
width: 80%;
margin: 0 0 50px 10%;
margin: 0 0 32px 10%;
}

.crossPendingBottom {
width: 80%;
margin: 0 0 8px 10%;
}

.stateError {
Expand Down
Loading

0 comments on commit b256cb1

Please sign in to comment.