Skip to content
This repository has been archived by the owner on May 5, 2022. It is now read-only.

Commit

Permalink
Merge pull request #32 from darwinia-network/fix-ios-error
Browse files Browse the repository at this point in the history
Fix iOS error
  • Loading branch information
WoeOm authored Mar 17, 2021
2 parents 8d15a41 + 8e58b50 commit 3ac9fed
Show file tree
Hide file tree
Showing 5 changed files with 273 additions and 138 deletions.
5 changes: 4 additions & 1 deletion src/locales/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
"Destination": "Destination",
"darwinaPage": "https://darwinia.network/",
"Claims": "Claimed",
"Not claimed": "Not claimed"
"Not claimed": "Not claimed",
"Extension": "Extension",
"Manual": "Manual",
"Please input the Darwinia address to be queried": "Please input the Darwinia address to be queried"
},
"crosschain": {
"title": "Cross-chain Transfer",
Expand Down
5 changes: 4 additions & 1 deletion src/locales/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@
"The amount exceeds the account available balance": "输入数量超过账户可用余额",
"The entered recipient account is incorrect": "输入的接收账号错误",
"d2e crosschain gas tip 1": "· 请在「跨链历史交易」中发起以太坊网络的「领取交易」。",
"d2e crosschain gas tip 2": "· 每笔以太坊网络的「领取交易」预计消耗 600000 Gas。"
"d2e crosschain gas tip 2": "· 每笔以太坊网络的「领取交易」预计消耗 600000 Gas。",
"Extension": "从插件获取",
"Manual": "手动输入",
"Please input the Darwinia address to be queried": "输入需要查询的 Darwinia 账号"
},
"crosschain_ethtron": {
"claim": "跨链转账",
Expand Down
196 changes: 149 additions & 47 deletions src/page/CrossChain/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from "react";
import { Button, Form, Spinner, Dropdown, ButtonGroup, Modal } from 'react-bootstrap'
import { Button, Form, Spinner, Dropdown, ButtonGroup, Modal, Col } from 'react-bootstrap'
import { withRouter } from 'react-router-dom';

import 'react-toastify/dist/ReactToastify.css';
Expand Down Expand Up @@ -113,6 +113,11 @@ class CrossChain extends Component {
d2eModalData: {
isShow: false,
hash: ''
},
crabAndDarwiniaHistory: {
isManual: false,
address: '',
isFetchingClaimParams: false
}
}
this.querySubscribe = null
Expand Down Expand Up @@ -258,6 +263,8 @@ class CrossChain extends Component {
// this.querySubscribe = subscribe;
if (Array.isArray(_account) && _account.length > 0) {
initAccount = _account[0].address
} else if (Array.isArray(_account) && _account.length === 0) {
initAccount = ''
} else {
initAccount = _account
}
Expand All @@ -272,6 +279,7 @@ class CrossChain extends Component {
crossChainFee: Web3.utils.toBN(0),
}
}, async () => {

if (this.state.account[_networkType]) {
this.setState({
status: status
Expand Down Expand Up @@ -315,6 +323,11 @@ class CrossChain extends Component {
isReady: true
}
})
} else {
if (status === 4) {
this.queryClaims()
return;
}
}
})
}, t);
Expand Down Expand Up @@ -355,7 +368,6 @@ class CrossChain extends Component {
}, t);
break;
case 'darwinia':

this.setState({
history: null,
account: {
Expand All @@ -378,6 +390,8 @@ class CrossChain extends Component {
initAccount = this.state.account[_networkType]
} else if (Array.isArray(_account) && _account.length > 0) {
initAccount = _account[0].address
} else if (Array.isArray(_account) && _account.length === 0) {
initAccount = ''
} else {
initAccount = _account
}
Expand All @@ -388,7 +402,12 @@ class CrossChain extends Component {
...account,
[_networkType]: initAccount,
[`${_networkType}List`]: _account,
isReady: false
isReady: false,
},
crabAndDarwiniaHistory: {
...this.state.crabAndDarwiniaHistory,
isManual: !initAccount,
address: ''
}
}, async () => {
if (this.state.account[_networkType]) {
Expand All @@ -408,6 +427,11 @@ class CrossChain extends Component {
isReady: true
}
})
} else {
if (status === 4) {
this.queryClaims()
return;
}
}
})
}, t);
Expand Down Expand Up @@ -601,6 +625,10 @@ class CrossChain extends Component {
async queryClaims() {
const { networkType, account } = this.state;
let address = ''
this.setState({
history: null
})

switch (networkType) {
case "eth":
address = account[networkType]
Expand Down Expand Up @@ -669,27 +697,35 @@ class CrossChain extends Component {
break;
case "darwinia":
address = account[networkType]
await getDarwiniaToEthereumGenesisSwapInfo({
query: {
address: '0x' + substrateAddressToPublicKey(address),
row: 200,
page: 0
},
method: "get"
}, (list, data) => {
this.setState({
history: list,
historyMeta: {
best: data.best,
mmrRoot: data.MMRRoot
}
})
}, () => {
try {
await getDarwiniaToEthereumGenesisSwapInfo({
query: {
address: '0x' + substrateAddressToPublicKey(address),
row: 200,
page: 0
},
method: "get"
}, (list, data) => {
this.setState({
history: list,
historyMeta: {
best: data.best,
mmrRoot: data.MMRRoot
}
})
}, () => {
this.setState({
history: [],
historyMeta: {}
})
});
} catch (error) {
this.setState({
history: [],
historyMeta: {}
})
});
}

break;
default:
break;
Expand Down Expand Up @@ -1298,7 +1334,7 @@ class CrossChain extends Component {

step4 = () => {
const { t } = this.props
const { networkType, account, history } = this.state
const { networkType, account, history, crabAndDarwiniaHistory } = this.state
const middleScreen = isMiddleScreen()

return (
Expand All @@ -1311,32 +1347,78 @@ class CrossChain extends Component {
{networkType === 'crab' || networkType === 'darwinia' ?
<>
<p>{convertSS58Address(account[networkType])}</p>
<Form.Group controlId="darwinaAddressGroup">
<Form.Control as="select" value={account[networkType]}
onChange={(value) => this.setCurrentAccount(networkType, value, async (account) => {
// const balances = await getTokenBalance('crab', account);
// this.setState({
// ringBalance: Web3.utils.toBN(balances[0]),
// darwiniaAddress: convertSS58Address(account)
// })
const params = new URLSearchParams()
const {hash} = this.props.location;

if (account) {
params.append("address", account)
} else {
params.delete("address")
<Form.Row>
{crabAndDarwiniaHistory.isManual ?
<Form.Group as={Col}>
<Form.Control onChange={(value) => this.setCurrentAccount(networkType, value, async (account) => {
const params = new URLSearchParams();
const {hash} = this.props.location;

if (account) {
params.append("address", account)
} else {
params.delete("address")
}
this.props.history.replace({hash: hash, search: params.toString()})

this.queryClaims()
})} type="text" placeholder={t('crosschain:Please input the Darwinia address to be queried')} />
</Form.Group>
:
<Form.Group as={Col} controlId="darwinaAddressGroup">
<Form.Control as="select" value={account[networkType]}
onChange={(value) => this.setCurrentAccount(networkType, value, async (account) => {
// const balances = await getTokenBalance('crab', account);
// this.setState({
// ringBalance: Web3.utils.toBN(balances[0]),
// darwiniaAddress: convertSS58Address(account)
// })
const params = new URLSearchParams();
const {hash} = this.props.location;

if (account) {
params.append("address", account)
} else {
params.delete("address")
}
this.props.history.replace({hash: hash, search: params.toString()})

this.queryClaims()
})}>
{account[`${networkType}List`]?.map((item, index) => {
return <option key={item.address} value={item.address}>{convertSS58Address(item.address, middleScreen)} - {item.meta.name}</option>
})
}
this.props.history.replace({hash: hash, search: params.toString()})
</Form.Control>
</Form.Group>}

<Form.Group>
<Button variant="primary" onClick={() => {
if(crabAndDarwiniaHistory.isManual) {
account[`${networkType}List`][0] && this.setCurrentAccount(networkType, {target: {value: account[`${networkType}List`][0].address}}, async (account) => {
const params = new URLSearchParams();
const {hash} = this.props.location;

if (account) {
params.append("address", account)
} else {
params.delete("address")
}
this.props.history.replace({hash: hash, search: params.toString()})

this.queryClaims()
})}>
{account[`${networkType}List`]?.map((item, index) => {
return <option key={item.address} value={item.address}>{convertSS58Address(item.address, middleScreen)} - {item.meta.name}</option>
})
}
</Form.Control>
</Form.Group></> : <p>{account[networkType]}</p>}
this.queryClaims()
})
}
this.setState({crabAndDarwiniaHistory: {
...this.state.crabAndDarwiniaHistory,
isManual: !crabAndDarwiniaHistory.isManual,
address: ''
}})
}
}>{crabAndDarwiniaHistory.isManual ? t('crosschain:Extension') : t('crosschain:Manual')}</Button>
</Form.Group>
</Form.Row>
</> : <p>{account[networkType]}</p>}
</div>
{networkType === 'eth' || networkType === 'tron' ? this.renderEthereumTronHistory(history) : null}
{networkType === 'darwinia' ? this.renderDarwiniaToEthereumHistory(history) : null}
Expand Down Expand Up @@ -1477,7 +1559,13 @@ class CrossChain extends Component {
chain: 'eth'
},
}, true, () =>
item.signatures && !item.tx ? <Button variant="outline-purple" className={styles.hashBtn} onClick={() => {
item.signatures && !item.tx ? <Button variant="outline-purple" disabled={this.state.crabAndDarwiniaHistory.isFetchingClaimParams} className={styles.hashBtn} onClick={() => {
this.setState({
crabAndDarwiniaHistory: {
...this.state.crabAndDarwiniaHistory,
isFetchingClaimParams: true
}
})
ClaimTokenFromD2E({
networkPrefix: config.D2E_NETWORK_PREFIX,
mmrIndex: item.mmr_index,
Expand All @@ -1488,9 +1576,23 @@ class CrossChain extends Component {
blockHash: item.block_hash,
historyMeta: historyMeta
}, (result) => {
this.setState({
crabAndDarwiniaHistory: {
...this.state.crabAndDarwiniaHistory,
isFetchingClaimParams: false
}
})

this.setModalHash(result);
this.setModalShow(true);
} , t);
} , () => {
this.setState({
crabAndDarwiniaHistory: {
...this.state.crabAndDarwiniaHistory,
isFetchingClaimParams: false
}
})
}, t);
}} >{t('crosschain:Claim')}</Button> : null
)}
</div>)
Expand Down
Loading

0 comments on commit 3ac9fed

Please sign in to comment.