Skip to content

Commit

Permalink
Merge branch 'cudos-dev' into cudos-master
Browse files Browse the repository at this point in the history
  • Loading branch information
V-Staykov committed Jun 27, 2022
2 parents 947b5c8 + 67a8a5d commit abe4037
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 10 deletions.
2 changes: 0 additions & 2 deletions config/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ RPC=
API=
GAS_PRICE=
GAS=
FEE=
STAKING=<url_for_staking_button_in_keplr_wallet>
PARAMS_ENDPOINT=""
BLOCK_EXPLORER=(http://<explorer-web-address>/transactions)

#orchestrator variables
Expand Down
4 changes: 0 additions & 4 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ const envVariables = [
'API',
'GAS_PRICE',
'GAS',
'FEE',
'ERC20_CONTRACT_ADDRESS',
'BRIDGE_CONTRACT_ADDRESS',
'ETHEREUM_GAS',
'STAKING',
'PARAMS_ENDPOINT',
'BLOCK_EXPLORER',
'NETWORK_TYPE'
];
Expand Down Expand Up @@ -209,10 +207,8 @@ const Config = {
RPC: process.env.RPC,
API: process.env.API,
GAS_PRICE: process.env.GAS_PRICE,
FEE: process.env.FEE,
GAS: process.env.GAS,
STAKING: process.env.STAKING,
PARAMS_ENDPOINT: process.env.PARAMS_ENDPOINT,
BLOCK_EXPLORER: process.env.BLOCK_EXPLORER,
MESSAGE_TYPE_URL: '/gravity.v1.MsgSendToEth',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const SummaryModal = ({
displayAmount,
onGetBalance,
txHash,
destTxHash,
}
: { closeModal: Function,
isOpen: boolean,
Expand All @@ -26,6 +27,7 @@ const SummaryModal = ({
displayAmount: string,
onGetBalance: Function,
txHash: string,
destTxHash: string,
}) => {

const CUDOS_SUCCESS_MESSAGE = `Your bridge transaction was successfully submitted to ${ProjectUtils.CUDOS_NETWORK_TEXT}. It is awaiting to be included in a batch and can take up to 120 ${ProjectUtils.CUDOS_NETWORK_TEXT} blocks to be fully executed on ${ProjectUtils.ETHEREUM_NETWORK_TEXT}.`;
Expand Down Expand Up @@ -109,10 +111,18 @@ const SummaryModal = ({
</div>
<div className={'Row Spacing LinkWrapper'}>
<div className={'LinkContent'}><a href= {`${selectedFromNetwork ? CUDOS_EXPLORER : ETHERSCAN_EXPLORER}/${txHash}`} rel='noreferrer' target='_blank'>
Bridge transaction link</a>
{selectedFromNetwork ? 'Cudos' : 'Ethereum'} Bridge transaction link</a>
<div className={'LinkIcon'} style={ProjectUtils.makeBgImgStyle(linkIcon)} />
</div>
</div>
{ selectedFromNetwork ? ''
: <div className={'Row Spacing LinkWrapper'}>
<div className={'LinkContent'}><a href= {`${CUDOS_EXPLORER}/${txHash}`} rel='noreferrer' target='_blank'>
Cudos Bridge transaction link</a>
<div className={'LinkIcon'} style={ProjectUtils.makeBgImgStyle(linkIcon)} />
</div>
</div>
}
<div className={'Row DoubleSpacing'}>
<div className={'TransactionMesasge'}>
<div className={'AttentionIcon'} style={ProjectUtils.makeBgImgStyle(attentionIcon)}/>
Expand Down
1 change: 1 addition & 0 deletions src/frontend/resources/common/js/models/ledgers/Ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default interface Ledger {
account: string,
walletError: string,
txHash: string,
txNonce: Number,
connect: () => Promise<void>,
disconnect: () => Promise<void>,
send: (amount: BigNumber, destination: string) => Promise<void>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default class MetamaskLedger implements Ledger {
@observable account: string;
@observable walletError: string;
@observable txHash: string;
@observable txNonce: Number;
erc20Instance: any;
gas: string;

Expand Down Expand Up @@ -93,9 +94,10 @@ export default class MetamaskLedger implements Ledger {
}

gravityContract.methods.sendToCosmos(Config.ORCHESTRATOR.ERC20_CONTRACT_ADDRESS, `0x${toHex(addressBytes32Array)}`, stringAmount).send({ from: account, gas: this.gas })
.on('receipt', (confirmationNumber, receipt) => {
.on('receipt', (confirmationNumber) => {
resolve();
this.txHash = confirmationNumber.transactionHash;
this.txNonce = confirmationNumber.events.SendToCosmosEvent.returnValues._eventNonce;
})
.on('error', (e) => {
reject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ interface State {
isLoading: boolean;
errorMessage: string;
txHash: string;
destTxHash: string;
minTransferAmount: BigNumber;
minBridgeFeeAmount: BigNumber;
estimatedGasFees: BigNumber;
Expand All @@ -68,6 +69,11 @@ const cudosFont = '../../../../resources/common/img/favicon/cudos-font.svg'
const transferLogoAlt = '../../../../resources/common/img/favicon/transfer-logo-alt.svg'
const keplrLink = 'https://chrome.google.com/webstore/detail/keplr/dmkamcknogkgcdfhhbddcghachkejeap?hl=en'

const GRAVITY_TX_BY_HASH_REST_ENDPOINT = '/cosmos/tx/v1beta1/txs/'
const GRAVITY_TXS_RPC_ENDPOINT = '/tx_search?query="message.action=\'/gravity.v1.MsgSendToCosmosClaim\'"'
const PARAMS_REST_ENDPOINT = '/gravity/v1beta/params'
const BLOCK_HEIGHT__RPC_ENDPOINT = '/abci_info'

export default class CudosBridgeComponent extends ContextPageComponent<Props, State> {

inputTimeouts: any;
Expand Down Expand Up @@ -106,6 +112,7 @@ export default class CudosBridgeComponent extends ContextPageComponent<Props, St
isLoading: false,
errorMessage: null,
txHash: null,
destTxHash: null,
minTransferAmount: new BigNumber(0),
minBridgeFeeAmount: new BigNumber(0),
estimatedGasFees: new BigNumber(0),
Expand Down Expand Up @@ -465,12 +472,18 @@ export default class CudosBridgeComponent extends ContextPageComponent<Props, St
executeTransaction = async () => {
this.setState({ preFlight: false })
try {

this.props.appStore.disableActions();
this.setState({ isTransferring: true, isLoading: true })
const ledger = await this.checkWalletConnected();
await ledger.send(this.state.amount, this.getAddress(this.state.selectedToNetwork, 0));
const txHash = ledger.txHash
this.setState({ isOpen: true, isLoading: false, txHash })

let destTxHash = '';
if (!this.isFromCosmos(this.state.selectedFromNetwork)) {
destTxHash = await this.getCosmosGravityTxByNonce(ledger.txNonce);
}
this.setState({ isOpen: true, isLoading: false, txHash, destTxHash });
} catch (e) {
const ledger = await this.checkWalletConnected();
this.setState({ isTransactionFail: true, isLoading: false, errorMessage: ledger.walletError });
Expand Down Expand Up @@ -706,7 +719,7 @@ export default class CudosBridgeComponent extends ContextPageComponent<Props, St
}

getMinTransferAndBridgeFeeAmounts = async (): Promise<void> => {
const response = await axios.get(Config.CUDOS_NETWORK.PARAMS_ENDPOINT);
const response = await axios.get(Config.CUDOS_NETWORK.API + PARAMS_REST_ENDPOINT);
const minTransferAmount = response.data.params.minimum_transfer_to_eth;
const minBridgeFeeAmount = response.data.params.minimum_fee_transfer_to_eth;

Expand All @@ -723,6 +736,35 @@ export default class CudosBridgeComponent extends ContextPageComponent<Props, St
})
}

getCosmosGravityTxByNonce = async (nonce: Number): Promise<string> => {
let result = '';
const heightRes = await (await fetch(Config.CUDOS_NETWORK.RPC + BLOCK_HEIGHT__RPC_ENDPOINT)).json();
let height = heightRes.result.response.last_block_height;
while (result === '') {
const txData = await (await fetch(Config.CUDOS_NETWORK.RPC + GRAVITY_TXS_RPC_ENDPOINT)).json();
const txHashes: string[] = txData.result.txs.filter((tx) => tx.height > height).map((tx) => tx.hash);

height = txData.result.txs.reduce((a, b) => {
return a.height > b.height ? a : b;
}).height;

for (let i=0; i < txHashes.length; i++) {
const hash = txHashes[i];
let res = await (await fetch(Config.CUDOS_NETWORK.API + GRAVITY_TX_BY_HASH_REST_ENDPOINT + hash)).json();
const txEventNonce = res.tx.body.messages[0].event_nonce;

if (nonce === txEventNonce) {
result = hash;
return result;
}
}

await new Promise((resolve) => setTimeout(resolve, 10000));
}

return '';
}

renderContent() {
return (
<div>
Expand Down Expand Up @@ -756,6 +798,7 @@ export default class CudosBridgeComponent extends ContextPageComponent<Props, St
selectedFromNetwork={this.state.selectedFromNetwork}
selectedToNetwork={this.state.selectedToNetwork}
txHash={this.state.txHash}
destTxHash={this.state.destTxHash}
closeModal={() => this.setState({ isOpen: false, displayAmount: S.Strings.EMPTY })}
isOpen={this.state.isOpen}
onGetBalance={this.onGetBalance}
Expand Down

0 comments on commit abe4037

Please sign in to comment.