Skip to content

Commit

Permalink
Remove unnecessary calls for Uniswap liquidity info (#354)
Browse files Browse the repository at this point in the history
* Remove unnecessary calls for Uniswap liquidity info

* Rename rainbow2 back to rainbow
  • Loading branch information
jinchung authored Feb 11, 2020
1 parent fee66f0 commit 1aa3e32
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 44 deletions.
22 changes: 11 additions & 11 deletions ios/Rainbow.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
A4D04BA923D12F99008C1DEC /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = A4D04BA823D12F99008C1DEC /* Button.swift */; };
A4D04BAC23D12FD5008C1DEC /* ButtonManager.m in Sources */ = {isa = PBXBuildFile; fileRef = A4D04BAB23D12FD5008C1DEC /* ButtonManager.m */; };
A4D04BAE23D13299008C1DEC /* ButtonManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A4D04BAD23D13299008C1DEC /* ButtonManager.swift */; };
ADBDB9381DFEBF1600ED6528 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; };
ADBDB9381DFEBF1600ED6528 /* (null) in Frameworks */ = {isa = PBXBuildFile; };
AE47B46652EA48AFB68E7832 /* SF-Pro-Text-Semibold.otf in Resources */ = {isa = PBXBuildFile; fileRef = AA6B0A8BE2484F46980BE9AC /* SF-Pro-Text-Semibold.otf */; };
AFCABA638327463693E67FD4 /* SF-Pro-Text-RegularItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 715DAAA3174542BAB93807A6 /* SF-Pro-Text-RegularItalic.otf */; };
AFD75D0B6EC9465C92C493A7 /* SF-Pro-Display-BlackItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = A8AE8DE50B9544B6BC186E6C /* SF-Pro-Display-BlackItalic.otf */; };
Expand Down Expand Up @@ -234,7 +234,7 @@
ED2971652150620600B7C4FE /* JavaScriptCore.framework in Frameworks */,
C72F456C99A646399192517D /* libz.tbd in Frameworks */,
F504FABC04ED3FF96616663B /* libPods-Rainbow.a in Frameworks */,
ADBDB9381DFEBF1600ED6528 /* BuildFile in Frameworks */,
ADBDB9381DFEBF1600ED6528 /* (null) in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -500,7 +500,7 @@
ORGANIZATIONNAME = Facebook;
TargetAttributes = {
13B07F861A680F5B00A75B9A = {
DevelopmentTeam = J5FM626PE2;
DevelopmentTeam = L74NQAQB8H;
LastSwiftMigration = 1120;
ProvisioningStyle = Automatic;
SystemCapabilities = {
Expand Down Expand Up @@ -737,7 +737,7 @@
CURRENT_PROJECT_VERSION = 4;
DEAD_CODE_STRIPPING = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = J5FM626PE2;
DEVELOPMENT_TEAM = L74NQAQB8H;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Frameworks",
Expand Down Expand Up @@ -769,7 +769,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = me.rainbow2;
PRODUCT_BUNDLE_IDENTIFIER = me.rainbow;
PRODUCT_NAME = Rainbow;
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -793,7 +793,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 4;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = J5FM626PE2;
DEVELOPMENT_TEAM = L74NQAQB8H;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Frameworks",
Expand Down Expand Up @@ -825,7 +825,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = me.rainbow2;
PRODUCT_BUNDLE_IDENTIFIER = me.rainbow;
PRODUCT_NAME = Rainbow;
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -885,7 +885,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 4;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = J5FM626PE2;
DEVELOPMENT_TEAM = L74NQAQB8H;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Frameworks",
Expand Down Expand Up @@ -916,7 +916,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = me.rainbow2;
PRODUCT_BUNDLE_IDENTIFIER = me.rainbow;
PRODUCT_NAME = Rainbow;
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -977,7 +977,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 4;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = J5FM626PE2;
DEVELOPMENT_TEAM = L74NQAQB8H;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Frameworks",
Expand Down Expand Up @@ -1008,7 +1008,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = me.rainbow2;
PRODUCT_BUNDLE_IDENTIFIER = me.rainbow;
PRODUCT_NAME = Rainbow;
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
73 changes: 42 additions & 31 deletions src/handlers/uniswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ export const executeSwap = async (tradeDetails, gasLimit, gasPrice) => {
}
};

export const getLiquidityInfo = async (accountAddress, exchangeContracts) => {
export const getLiquidityInfo = async (
accountAddress,
exchangeContracts,
pairs
) => {
const promises = map(exchangeContracts, async exchangeAddress => {
try {
const ethReserveCall = web3Provider.getBalance(exchangeAddress);
Expand Down Expand Up @@ -221,42 +225,49 @@ export const getLiquidityInfo = async (accountAddress, exchangeContracts) => {
erc20ABI,
web3Provider
);
const tokenReserveCall = tokenContract.balanceOf(exchangeAddress);
const tokenDecimalsCall = tokenContract.decimals();

const [reserve, decimals] = await Promise.all([
tokenReserveCall,
tokenDecimalsCall,
]);
const token = get(pairs, `[${toLower(tokenAddress)}]`);

let decimals = 18;
let name = '';
try {
name = await tokenContract.name().catch();
} catch (error) {
name = get(contractMap, `[${tokenAddress}].name`, '');
if (!name) {
console.log(
'error getting name for token: ',
tokenAddress,
' Error = ',
error
);
let symbol = '';
if (token) {
name = token.name;
symbol = token.symbol;
decimals = token.decimals;
} else {
decimals = await tokenContract.decimals();

try {
name = await tokenContract.name().catch();
} catch (error) {
name = get(contractMap, `[${tokenAddress}].name`, '');
if (!name) {
console.log(
'error getting name for token: ',
tokenAddress,
' Error = ',
error
);
}
}
}

let symbol = get(contractMap, `[${tokenAddress}].symbol`, '');
try {
symbol = await tokenContract.symbol().catch();
} catch (error) {
if (!symbol) {
console.log(
'error getting symbol for token: ',
tokenAddress,
' Error = ',
error
);
let symbol = get(contractMap, `[${tokenAddress}].symbol`, '');
try {
symbol = await tokenContract.symbol().catch();
} catch (error) {
if (!symbol) {
console.log(
'error getting symbol for token: ',
tokenAddress,
' Error = ',
error
);
}
}
}

const reserve = await tokenContract.balanceOf(exchangeAddress);

const ethBalance = fromWei(
divide(multiply(ethReserve, balance), totalSupply)
);
Expand Down
5 changes: 3 additions & 2 deletions src/redux/uniswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ export const uniswapUpdateLiquidityTokens = (
liquidityTokens,
appendOrChange
) => (dispatch, getState) => {
if (isEmpty(liquidityTokens)) return;
let updatedLiquidityTokens = filter(liquidityTokens, hasTokenQuantity);
if (appendOrChange) {
const { liquidityTokens: existingLiquidityTokens } = getState().uniswap;
Expand All @@ -311,7 +312,7 @@ export const uniswapUpdateLiquidityTokens = (
export const uniswapUpdateState = () => (dispatch, getState) =>
new Promise((resolve, promiseReject) => {
const { accountAddress, network } = getState().settings;
const { liquidityTokens } = getState().uniswap;
const { liquidityTokens, pairs } = getState().uniswap;

if (isEmpty(liquidityTokens)) {
return resolve(false);
Expand All @@ -320,7 +321,7 @@ export const uniswapUpdateState = () => (dispatch, getState) =>
dispatch({ type: UNISWAP_UPDATE_REQUEST });

const exchangeContracts = map(liquidityTokens, getAssetCode);
return getLiquidityInfo(accountAddress, exchangeContracts)
return getLiquidityInfo(accountAddress, exchangeContracts, pairs)
.then(liquidityInfo => {
saveLiquidityInfo(liquidityInfo, accountAddress, network);
dispatch({
Expand Down

0 comments on commit 1aa3e32

Please sign in to comment.