Skip to content

Commit

Permalink
fixed max amount calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
V-Staykov committed Jun 27, 2022
1 parent abe4037 commit c51a7b8
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 123 deletions.
1 change: 0 additions & 1 deletion config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ const Config = {
GAS: process.env.GAS,
STAKING: process.env.STAKING,
BLOCK_EXPLORER: process.env.BLOCK_EXPLORER,
MESSAGE_TYPE_URL: '/gravity.v1.MsgSendToEth',
},
ORCHESTRATOR: {
ERC20_CONTRACT_ADDRESS: process.env.ERC20_CONTRACT_ADDRESS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

.LoadingForm .Wrapper {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
Expand All @@ -47,6 +48,17 @@
margin-top: 20px;
}

.LoadingForm .AdditionalText {
font-family: Poppins, sans-serif;
margin-bottom: 5px;
font-size: 12px;
font-weight: 600;
text-align: center;
margin-top: 20px;
margin-left: 20px;
margin-right: 20px;
}

/*Loading dots animation */

@keyframes blink {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@
}

.ModalContent .SummaryForm .AttentionIcon {
width: 55px;
width: 40px;
height: 20px;
margin-right: 7px;
padding-right: 7px;
align-self: center;
}

Expand Down
7 changes: 3 additions & 4 deletions src/frontend/resources/common/js/components-inc/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React from 'react';
import PropTypes from 'prop-types';

import { createMuiTheme } from '@material-ui/core/styles';
import { createTheme } from '@material-ui/core/styles';
import { ThemeProvider } from '@material-ui/styles';
import MuiButton from '@material-ui/core/Button';

import './../../css/components-inc/button.css';
import S from '../utilities/Main';

const theme01 = createMuiTheme({
const theme01 = createTheme({
palette: {
action: {
disabledBackground: 'rgba(54, 62, 89, 1)',
Expand All @@ -25,7 +24,7 @@ const theme01 = createMuiTheme({
},
});

const theme02 = createMuiTheme({
const theme02 = createTheme({
palette: {
action: {
disabledBackground: 'rgba(99, 109, 143, 0.3)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import '../../css/components-popups/loading-modal.css';
const LoadingModal = ({
closeModal,
isOpen,
additionalText,
}
: {
closeModal: Function
isOpen: boolean
additionalText: string
}) => {

const cudosMainLogo = '../../../../resources/common/img/favicon/cudos-80x80.svg';
Expand All @@ -32,6 +34,9 @@ const LoadingModal = ({
<span>.</span>
<span>.</span>
</div>
<div className={'AdditionalText'}>
{additionalText}
</div>
</div>
</div>
</ModalComponent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const SummaryModal = ({
}) => {

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}.`;
const ETHEREUM_SUCCESS_MESSAGE = `Your bridge transaction was successfully submitted to ${ProjectUtils.ETHEREUM_NETWORK_TEXT} and will be fully executed on ${ProjectUtils.CUDOS_NETWORK_TEXT} in roughly 6 minutes.`;
const ETHEREUM_SUCCESS_MESSAGE = `Your bridge transaction was successfully submitted to ${ProjectUtils.ETHEREUM_NETWORK_TEXT} and ${ProjectUtils.CUDOS_NETWORK_TEXT}.`;

const cudosLogoSmall = '../../../../resources/common/img/favicon/cudos-18x18.svg';
const ethLogoSmall = '../../../../resources/common/img/favicon/eth-18x18.svg';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export default class CosmosNetworkH {
static BECH32_PREFIX_CONS_PUB = 'cudosvalconspub';
static BECH32_ACC_ADDR_LENGTH = 44;

static MESSAGE_TYPE_URL = '/gravity.v1.MsgSendToEth';
}
71 changes: 8 additions & 63 deletions src/frontend/resources/common/js/models/ledgers/KeplrLedger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export default class KeplrLedger implements Ledger {
},
});
} catch (ex) {
console.log(ex);
this.walletError = 'Failed to suggest the chain'
}

Expand Down Expand Up @@ -169,7 +168,7 @@ export default class KeplrLedger implements Ledger {
const offlineSigner = window.getOfflineSigner(this.chainID);
const myRegistry = new Registry([
...defaultRegistryTypes,
[Config.CUDOS_NETWORK.MESSAGE_TYPE_URL, MsgSendToEth],
[CosmosNetworkH.MESSAGE_TYPE_URL, MsgSendToEth],
]);
const client = await SigningStargateClient.connectWithSigner(this.rpcEndpoint, offlineSigner, {
registry: myRegistry,
Expand All @@ -184,7 +183,7 @@ export default class KeplrLedger implements Ledger {
const [client, account] = await this.GetKeplrClientAndAccount();

const msgSend = [{
typeUrl: Config.CUDOS_NETWORK.MESSAGE_TYPE_URL,
typeUrl: CosmosNetworkH.MESSAGE_TYPE_URL,
value: {
sender: account.address,
ethDest: destiantionAddress,
Expand All @@ -203,76 +202,23 @@ export default class KeplrLedger implements Ledger {
this.walletError = null;
const msgFee = await this.EstimateFee(
client,
GasPrice.fromString(Config.CUDOS_NETWORK.FEE+'acudos'),
account.address,
msgSend,
'Fee Estimation Message'
);

const result = await client.signAndBroadcast(
GasPrice.fromString(`${Config.CUDOS_NETWORK.GAS_PRICE}acudos`),
account.address,
msgSend,
msgFee,
'Sent with CUDOS Gravity Bridge'
'Fee Estimation Message',
);

this.txHash = result.transactionHash;
assertIsDeliverTxSuccess(result);
} catch (e) {
console.log(e);
throw new Error(this.walletError = 'Failed to send transaction!');
}
}

async requestBatch() {
const proposalTypePath = '/gravity.v1.MsgRequestBatch'

const chainId = Config.CUDOS_NETWORK.CHAIN_ID;
await window.keplr.enable(chainId);
const offlineSigner = window.getOfflineSigner(chainId);

const account = (await offlineSigner.getAccounts())[0];

const msgSend = [{
typeUrl: proposalTypePath,
value: {
sender: account.address,
denom: CosmosNetworkH.CURRENCY_DENOM,
},

}];

const msgFee = {
amount: [{
denom: CosmosNetworkH.CURRENCY_DENOM,
amount: Config.CUDOS_NETWORK.FEE,
}],
gas: Config.CUDOS_NETWORK.GAS,
}

try {
this.walletError = null;
const myRegistry = new Registry([
...defaultRegistryTypes,
[proposalTypePath, MsgRequestBatch],
])

const rpcEndpoint = Config.CUDOS_NETWORK.RPC;
const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, offlineSigner, {
registry: myRegistry,
});

const result = await client.signAndBroadcast(
account.address,
msgSend,
msgFee,
'Sent with CUDOS Gravity Bridge',
);

assertIsBroadcastTxSuccess(result);
this.txHash = result.transactionHash;
assertIsDeliverTxSuccess(result);
} catch (e) {
console.log(e);
this.walletError = 'Failed to send transaction!'
throw new Error('Failed to send transaction!');
throw new Error(this.walletError = 'Failed to send transaction!');
}
}

Expand All @@ -287,7 +233,6 @@ export default class KeplrLedger implements Ledger {

return new BigNumber(amount).div(CosmosNetworkH.CURRENCY_1_CUDO);
} catch (e) {
console.log(e);
this.walletError = 'Failed to get balance!'
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/frontend/resources/common/js/models/ledgers/Ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default interface Ledger {
account: string,
walletError: string,
txHash: string,
txNonce: Number,
txNonce: string,
connect: () => Promise<void>,
disconnect: () => Promise<void>,
send: (amount: BigNumber, destination: string) => Promise<void>,
Expand All @@ -17,7 +17,6 @@ export default interface Ledger {
gas: string;
}>,
GetKeplrClientAndAccount: () => Promise<any[]>,
requestBatch: () => Promise < void >,
isAddressValid: (address: string) => boolean,
getBalance(): Promise<BigNumber>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class MetamaskLedger implements Ledger {
@observable account: string;
@observable walletError: string;
@observable txHash: string;
@observable txNonce: Number;
@observable txNonce: string;
erc20Instance: any;
gas: string;

Expand Down Expand Up @@ -61,7 +61,6 @@ export default class MetamaskLedger implements Ledger {

async disconnect(): Promise<void> {
return new Promise < void >((resolve, reject) => {
console.log('disconnecting...');
resolve();
});
}
Expand Down Expand Up @@ -111,12 +110,6 @@ export default class MetamaskLedger implements Ledger {

}

async requestBatch(): Promise<void> {
return new Promise < void >((resolve, reject) => {
resolve();
});
}

async getBalance(): Promise<BigNumber> {
this.walletError = null;
try {
Expand Down
Loading

0 comments on commit c51a7b8

Please sign in to comment.