Skip to content

Commit

Permalink
Merge recent changes (abe561c) from RaidGuild repo
Browse files Browse the repository at this point in the history
  • Loading branch information
akolotov authored Feb 19, 2021
2 parents 9991650 + 7d4c929 commit 31e1c9e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 35 deletions.
9 changes: 1 addition & 8 deletions packages/react-app/src/lib/amb.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Contract, utils } from 'ethers';
import { gql, request } from 'graphql-request';

import { getGasPrice } from './gasPrice';
import { getAMBAddress, getGraphEndpoint, logError } from './helpers';
import { isEIP1193 } from './providers';

export const fetchConfirmations = async (chainId, ethersProvider) => {
const abi = ['function requiredBlockConfirmations() view returns (uint256)'];
Expand Down Expand Up @@ -50,12 +48,7 @@ export const executeSignatures = async (ethersProvider, chainId, message) => {
);
const address = getAMBAddress(chainId);
const ambContract = new Contract(address, abi, ethersProvider.getSigner());
const options = isEIP1193(ethersProvider)
? undefined
: { gasPrice: getGasPrice(chainId) };
return options
? ambContract.executeSignatures(message.msgData, signatures, options)
: ambContract.executeSignatures(message.msgData, signatures);
return ambContract.executeSignatures(message.msgData, signatures);
};

const messagesTXQuery = gql`
Expand Down
20 changes: 5 additions & 15 deletions packages/react-app/src/lib/bridge.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { BigNumber, Contract } from 'ethers';

import { REVERSE_BRIDGE_ENABLED } from './constants';
import { getGasPrice } from './gasPrice';
import {
getBridgeNetwork,
getMediatorAddress,
isxDaiChain,
logError,
} from './helpers';
import { getOverriddenToToken, isOverridden } from './overrides';
import { getEthersProvider, isEIP1193 } from './providers';
import { getEthersProvider } from './providers';
import { fetchTokenDetails } from './token';

const getToName = (fromName, fromxDai) => {
Expand Down Expand Up @@ -241,32 +240,23 @@ export const fetchTokenLimits = async (

export const relayTokens = async (ethersProvider, token, receiver, amount) => {
const signer = ethersProvider.getSigner();
const { chainId, mode, mediator, address } = token;
const options = isEIP1193(ethersProvider)
? undefined
: { gasPrice: getGasPrice(chainId) };
const { mode, mediator, address } = token;
switch (mode) {
case 'erc677': {
const abi = ['function transferAndCall(address, uint256, bytes)'];
const tokenContract = new Contract(address, abi, signer);
return options
? tokenContract.transferAndCall(mediator, amount, receiver, options)
: tokenContract.transferAndCall(mediator, amount, receiver);
return tokenContract.transferAndCall(mediator, amount, receiver);
}
case 'dedicated-erc20': {
const abi = ['function relayTokens(address, uint256)'];
const mediatorContract = new Contract(mediator, abi, signer);
return options
? mediatorContract.relayTokens(receiver, amount, options)
: mediatorContract.relayTokens(receiver, amount);
return mediatorContract.relayTokens(receiver, amount);
}
case 'erc20':
default: {
const abi = ['function relayTokens(address, address, uint256)'];
const mediatorContract = new Contract(mediator, abi, signer);
return options
? mediatorContract.relayTokens(token.address, receiver, amount, options)
: mediatorContract.relayTokens(token.address, receiver, amount);
return mediatorContract.relayTokens(token.address, receiver, amount);
}
}
};
Expand Down
4 changes: 1 addition & 3 deletions packages/react-app/src/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ export const uniqueTokens = list => {
export const formatValue = (num, dec) => {
const str = utils.formatUnits(num, dec);
if (str.length > 50) {
const expStr = Number(str)
.toExponential()
.replace(/e\+?/, ' x 10^');
const expStr = Number(str).toExponential().replace(/e\+?/, ' x 10^');
const split = expStr.split(' x 10^');
const first = Number(split[0]).toLocaleString('en', {
maximumFractionDigits: 4,
Expand Down
12 changes: 3 additions & 9 deletions packages/react-app/src/lib/token.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { BigNumber, Contract } from 'ethers';

import { ADDRESS_ZERO, REVERSE_BRIDGE_ENABLED } from './constants';
import { getGasPrice } from './gasPrice';
import { getMediatorAddress, isxDaiChain, logError } from './helpers';
import {
getOverriddenMediator,
getOverriddenMode,
isOverridden,
} from './overrides';
import { getEthersProvider, isEIP1193 } from './providers';
import { getEthersProvider } from './providers';

export const fetchAllowance = async (
{ mediator, address },
Expand Down Expand Up @@ -100,17 +99,12 @@ export const fetchTokenDetails = async token => {

export const approveToken = async (
ethersProvider,
{ chainId, address, mediator },
{ address, mediator },
amount,
) => {
const abi = ['function approve(address, uint256)'];
const options = isEIP1193(ethersProvider)
? undefined
: { gasPrice: getGasPrice(chainId) };
const tokenContract = new Contract(address, abi, ethersProvider.getSigner());
return options
? tokenContract.approve(mediator, amount.toString(), options)
: tokenContract.approve(mediator, amount.toString());
return tokenContract.approve(mediator, amount);
};

export const fetchTokenBalance = async (token, account) => {
Expand Down

0 comments on commit 31e1c9e

Please sign in to comment.