Skip to content

Commit

Permalink
[Optimism] Feature/custom network gas estimates (#2865)
Browse files Browse the repository at this point in the history
* Move to new dependencies

* move navigation.getparam to route.params

* add navigationOptions

* Fix dismiss and drawer working

* Fix remaining route params

* Fix switch navigator and fiat on ramp nav

* Fix routename and pop

* Remove screen props

* Fix deeplink navigation

* Fix navigation for inner screens

* Ignore navigation warning

* Fix get route

* Fix showing protect wallet modal

* Add route to proptypes

* Add more missing proptypes

* Update tests

* Fix some more navigations

* Update collectibles navigatoin

* Use useNavigation

* Use optional chaining on `dangerouslyGetParent()`

* Removing ?? null and ?? undefined

* Reorganize nav imports in App/index

* Update findRouteNameFromNavigatorState

* Remove noop functions

* Adding testing for navigation

* Add more navigation tests

* Add comment explaining the test files

* Remove unnecessary boolean casting

* Remove unnecessary variable

* Remove unnecessary boolean casting

* Fixes navigation issues

* Fix navigation issues

* Fix QR scanner

* fixed enroll navigation reset issue

* Fix going to wallet view

* updated test cases

* Fix simple notification

* Fix going to onboarding

* added snapshots to test

* fixed what new modal test

* added picker to package.json

* yarn clean

* yarn update command

* snapshot update

* removed the dive method on the wrapper

* snapshot update

* update yarn unit test

* added logic for gas calculations on custom networks identified by the network controller

* added test controller

* updated path for temp controller

* updated for local file ref

* update lock for local dep

* updated dep

* disable cache

* updated dep

* updated dep

* added stub for getTokenListState

* removed cache comments

* removed console.log

* updated spacing

* update token list get and added todo

* added undefined check

* updated the logic for contractMap:wq

* updated logic for token list

* updated getTokensList

* updated lock file

* cache commented on bitrise

* updated yarn

* added resolutions for pbkdf

* updated package

* added resolutions

* updated controllers and engine code

* updated snapshots

* refactor conditional

* Remove hard coded upper limit to gas limit (#2884)

* updated controller version

* updated yarn lock

Co-authored-by: andrepimenta <andrepimenta7@gmail.com>
Co-authored-by: Pedro Pablo Aste Kompen <wachunei@gmail.com>
Co-authored-by: Dan J Miller <danjm.com@gmail.com>
Co-authored-by: ricky <ricky.miller@gmail.com>
  • Loading branch information
5 people authored Jul 10, 2021
1 parent 3076d63 commit bc81b78
Show file tree
Hide file tree
Showing 24 changed files with 2,945 additions and 3,303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ exports[`ActionModal should render correctly 1`] = `
onModalShow={[Function]}
onModalWillHide={[Function]}
onModalWillShow={[Function]}
panResponderThreshold={4}
propagateSwipe={false}
scrollHorizontal={false}
scrollOffset={0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ exports[`BlockingActionModal should render correctly 1`] = `
onModalShow={[Function]}
onModalWillHide={[Function]}
onModalWillShow={[Function]}
panResponderThreshold={4}
propagateSwipe={false}
scrollHorizontal={false}
scrollOffset={0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ exports[`CustomAlert should render correctly 1`] = `
onModalShow={[Function]}
onModalWillHide={[Function]}
onModalWillShow={[Function]}
panResponderThreshold={4}
propagateSwipe={false}
scrollHorizontal={false}
scrollOffset={0}
Expand Down
3 changes: 1 addition & 2 deletions app/components/UI/CustomGas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,7 @@ class CustomGas extends PureComponent {
let warningGasLimit;
if (!value || value === '' || !isDecimal(value)) warningGasLimit = strings('transaction.invalid_gas');
else if (bnValue && !isBN(bnValue)) warningGasLimit = strings('transaction.invalid_gas');
else if (bnValue.lt(new BN(21000)) || bnValue.gt(new BN(7920028)))
warningGasLimit = strings('custom_gas.warning_gas_limit');
else if (bnValue.lt(new BN(21000))) warningGasLimit = strings('custom_gas.warning_gas_limit');
else if (this.props.minimumGasLimit && bnValue.lt(new BN(this.props.minimumGasLimit)))
warningGasLimit = strings('custom_gas.warning_gas_limit_estimated', {
gas: this.props.minimumGasLimit.toString(10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ exports[`CustomNonceModal should render correctly 1`] = `
onModalShow={[Function]}
onModalWillHide={[Function]}
onModalWillShow={[Function]}
panResponderThreshold={4}
propagateSwipe={true}
scrollHorizontal={false}
scrollOffset={0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ exports[`GlobalAlert should render correctly 1`] = `
onModalShow={[Function]}
onModalWillHide={[Function]}
onModalWillShow={[Function]}
panResponderThreshold={4}
propagateSwipe={false}
scrollHorizontal={false}
scrollOffset={0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ exports[`OnboardingWizard should render correctly 1`] = `
onModalShow={[Function]}
onModalWillHide={[Function]}
onModalWillShow={[Function]}
panResponderThreshold={4}
propagateSwipe={false}
scrollHorizontal={false}
scrollOffset={0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ exports[`SelectComponent should render correctly 1`] = `
onModalShow={[Function]}
onModalWillHide={[Function]}
onModalWillShow={[Function]}
panResponderThreshold={4}
propagateSwipe={false}
scrollHorizontal={false}
scrollOffset={0}
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/TransactionEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ class TransactionEditor extends PureComponent {
if (gas && !isBN(gas)) return strings('transaction.invalid_gas');
if (!gasPrice) return strings('transaction.invalid_gas_price');
if (gasPrice && !isBN(gasPrice)) return strings('transaction.invalid_gas_price');
if (gas.lt(new BN(21000)) || gas.gt(new BN(7920028))) return strings('custom_gas.warning_gas_limit');
if (gas.lt(new BN(21000))) return strings('custom_gas.warning_gas_limit');

const checksummedFrom = safeToChecksumAddress(from) || '';
const fromAccount = this.props.accounts[checksummedFrom];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ exports[`Approval should render correctly 1`] = `
onModalWillHide={[Function]}
onModalWillShow={[Function]}
onSwipeComplete={[Function]}
panResponderThreshold={4}
propagateSwipe={true}
scrollHorizontal={false}
scrollOffset={0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ exports[`Browser should render correctly 1`] = `
onModalShow={[Function]}
onModalWillHide={[Function]}
onModalWillShow={[Function]}
panResponderThreshold={4}
propagateSwipe={false}
scrollHorizontal={false}
scrollOffset={0}
Expand Down Expand Up @@ -113,6 +114,7 @@ exports[`Browser should render correctly 1`] = `
onModalShow={[Function]}
onModalWillHide={[Function]}
onModalWillShow={[Function]}
panResponderThreshold={4}
propagateSwipe={false}
scrollHorizontal={false}
scrollOffset={0}
Expand Down Expand Up @@ -227,6 +229,7 @@ exports[`Browser should render correctly 1`] = `
onModalWillHide={[Function]}
onModalWillShow={[Function]}
onSwipeComplete={[Function]}
panResponderThreshold={4}
propagateSwipe={false}
scrollHorizontal={false}
scrollOffset={0}
Expand Down Expand Up @@ -284,6 +287,7 @@ exports[`Browser should render correctly 1`] = `
onModalWillHide={[Function]}
onModalWillShow={[Function]}
onSwipeComplete={[Function]}
panResponderThreshold={4}
propagateSwipe={true}
scrollHorizontal={false}
scrollOffset={0}
Expand Down Expand Up @@ -351,6 +355,7 @@ exports[`Browser should render correctly 1`] = `
onModalWillHide={[Function]}
onModalWillShow={[Function]}
onSwipeComplete={[Function]}
panResponderThreshold={4}
propagateSwipe={false}
scrollHorizontal={false}
scrollOffset={0}
Expand Down Expand Up @@ -408,6 +413,7 @@ exports[`Browser should render correctly 1`] = `
onModalWillHide={[Function]}
onModalWillShow={[Function]}
onSwipeComplete={[Function]}
panResponderThreshold={4}
propagateSwipe={false}
scrollHorizontal={false}
scrollOffset={0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ exports[`Collectible should render correctly 1`] = `
onModalWillHide={[Function]}
onModalWillShow={[Function]}
onSwipeComplete={[Function]}
panResponderThreshold={4}
propagateSwipe={false}
scrollHorizontal={false}
scrollOffset={0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exports[`QrScanner should render correctly 1`] = `
androidRecordAudioPermissionOptions={null}
autoFocus={1}
barCodeTypes={Array []}
cameraId={null}
cameraId=""
captureAudio={false}
exposure={-1}
faceDetectionClassifications={0}
Expand Down Expand Up @@ -79,6 +79,7 @@ exports[`QrScanner should render correctly 1`] = `
permissionDialogTitle=""
pictureSize="None"
playSoundOnCapture={false}
playSoundOnRecord={false}
ratio="4:3"
style={
Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ exports[`Amount should render correctly 1`] = `
onModalWillHide={[Function]}
onModalWillShow={[Function]}
onSwipeComplete={[Function]}
panResponderThreshold={4}
propagateSwipe={true}
scrollHorizontal={false}
scrollOffset={0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ exports[`Confirm should render correctly 1`] = `
onModalWillHide={[Function]}
onModalWillShow={[Function]}
onSwipeComplete={[Function]}
panResponderThreshold={4}
propagateSwipe={true}
scrollHorizontal={false}
scrollOffset={0}
Expand Down Expand Up @@ -352,6 +353,7 @@ exports[`Confirm should render correctly 1`] = `
onModalWillHide={[Function]}
onModalWillShow={[Function]}
onSwipeComplete={[Function]}
panResponderThreshold={4}
propagateSwipe={true}
scrollHorizontal={false}
scrollOffset={0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ exports[`SendTo should render correctly 1`] = `
onModalWillHide={[Function]}
onModalWillShow={[Function]}
onSwipeComplete={[Function]}
panResponderThreshold={4}
propagateSwipe={true}
scrollHorizontal={false}
scrollOffset={0}
Expand Down
17 changes: 13 additions & 4 deletions app/core/Engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import {
} from '@metamask/controllers';

import SwapsController from '@metamask/swaps-controller';

import AsyncStorage from '@react-native-community/async-storage';

import Encryptor from './Encryptor';
import { toChecksumAddress } from 'ethereumjs-util';
import Networks from '../util/networks';
Expand Down Expand Up @@ -139,7 +137,17 @@ class Engine {
addTokens: assetsController.addTokens.bind(assetsController),
addCollectible: assetsController.addCollectible.bind(assetsController),
removeCollectible: assetsController.removeCollectible.bind(assetsController),
getAssetsState: () => assetsController.state
getAssetsState: () => assetsController.state,
//TODO: replace during Token List Refactor
getTokenListState: () => {
const tokenList = Object.entries(contractMap).reduce((final, [key, value]) => {
if (value.erc20) {
final[key] = value;
}
return final;
}, {});
return { tokenList };
}
}),
currencyRateController,
new PersonalMessageManager(),
Expand All @@ -158,7 +166,8 @@ class Engine {
new TokenRatesController({
onAssetsStateChange: listener => assetsController.subscribe(listener),
onCurrencyRateStateChange: listener =>
this.controllerMessenger.subscribe(`${currencyRateController.name}:stateChange`, listener)
this.controllerMessenger.subscribe(`${currencyRateController.name}:stateChange`, listener),
onNetworkStateChange: listener => networkController.subscribe(listener)
}),
new TransactionController({
getNetworkState: () => networkController.state,
Expand Down
8 changes: 6 additions & 2 deletions app/util/custom-gas.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ export async function getBasicGasEstimates() {
export async function getGasPriceByChainId(transaction) {
const { TransactionController, NetworkController } = Engine.context;
const chainId = NetworkController.state.provider.chainId;

let estimation, basicGasEstimates;
try {
estimation = await TransactionController.estimateGas(transaction);
Expand Down Expand Up @@ -193,8 +192,13 @@ export async function getGasPriceByChainId(transaction) {
// Will use gas price from network that was fetched above
}
}

const gas = hexToBN(estimation.gas);
const gasPrice = toWei(convertApiValueToGWEI(basicGasEstimates.average), 'gwei');
//The transaction controller returns custom network values in hex
const gasPrice = NetworkController.state.isCustomNetwork
? hexToBN(estimation.gasPrice)
: toWei(convertApiValueToGWEI(basicGasEstimates.average), 'gwei');

return { gas, gasPrice };
}

Expand Down
Loading

0 comments on commit bc81b78

Please sign in to comment.