Skip to content

Commit

Permalink
Merge branch 'main' into feat/eth-json-rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioAslau committed Jun 22, 2024
2 parents 8eef3b7 + 803c384 commit 4107d70
Show file tree
Hide file tree
Showing 99 changed files with 3,424 additions and 2,760 deletions.
5 changes: 4 additions & 1 deletion .github/scripts/fitness-functions/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ enum AUTOMATION_TYPE {
PRE_PUSH_HOOK = 'pre-push-hook',
}

export { EXCLUDE_REGEX, AUTOMATION_TYPE };
// only allow TS and TSX files in the app directory only
const APP_FOLDER_JS_REGEX = /^(app).*\.(js|jsx)$/;

export { EXCLUDE_REGEX, APP_FOLDER_JS_REGEX, AUTOMATION_TYPE };
29 changes: 29 additions & 0 deletions .github/scripts/fitness-functions/common/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,34 @@ function filterDiffByFilePath(diff: string, regex: RegExp): string {
return filteredDiff;
}

function restrictedFilePresent(diff: string, regex: RegExp): boolean {
// split by `diff --git` and remove the first element which is empty
const diffBlocks = diff.split(`diff --git`).slice(1);
let jsOrJsxFilePresent = false;
diffBlocks
.map((block) => block.trim())
.filter((block) => {
block
// get the first line of the block which has the paths
.split('\n')[0]
.trim()
// split the two paths
.split(' ')
// remove `a/` and `b/` from the paths
.map((path) => path.substring(2))
// if at least one of the two paths matches the regex, filter the
// corresponding diff block in
.forEach((path) => {
if (regex.test(path)) {
// Not excluded, include in check
jsOrJsxFilePresent = true;
}
});
return jsOrJsxFilePresent;
})
return jsOrJsxFilePresent;
}

// This function returns all lines that are additions to files that are being
// modified but that previously already existed. Example:
// diff --git a/test.js b/test.js
Expand Down Expand Up @@ -111,6 +139,7 @@ function hasNumberOfCodeBlocksIncreased(

export {
filterDiffByFilePath,
restrictedFilePresent,
filterDiffFileCreations,
filterDiffLineAdditions,
hasNumberOfCodeBlocksIncreased,
Expand Down
8 changes: 7 additions & 1 deletion .github/scripts/fitness-functions/rules/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { preventJavaScriptFileAdditions } from './javascript-additions';
import { preventCodeBlocksRule } from './prevent-code-blocks';

const RULES: IRule[] = [
Expand All @@ -6,6 +7,11 @@ const RULES: IRule[] = [
fn: preventCodeBlocksRule,
docURL: '[WIP] No documentation exists for this rule yet.',
},
{
name: 'Check for js or jsx file being added',
fn: preventJavaScriptFileAdditions,
docURL: '[WIP] No documentation exists for this rule yet.',
},
];

interface IRule {
Expand All @@ -32,5 +38,5 @@ function runFitnessFunctionRule(rule: IRule, diff: string): void {
}
}

export { RULES, runFitnessFunctionRule };
export { RULES, runFitnessFunctionRule, preventJavaScriptFileAdditions };
export type { IRule };
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {
generateModifyFilesDiff,
generateCreateFileDiff,
} from '../common/test-data';
import { preventJavaScriptFileAdditions } from './javascript-additions';

describe('preventJavaScriptFileAdditions()', (): void => {
it('should pass when receiving an empty diff', (): void => {
const testDiff = '';

const hasRulePassed = preventJavaScriptFileAdditions(testDiff);

expect(hasRulePassed).toBe(true);
});

it('should pass when receiving a diff with a new TS file on the shared folder', (): void => {
const testDiff = [
generateModifyFilesDiff('new-file.ts', 'foo', 'bar'),
generateModifyFilesDiff('old-file.js', undefined, 'pong'),
generateCreateFileDiff('app/test.ts', 'yada yada yada yada'),
].join('');

const hasRulePassed = preventJavaScriptFileAdditions(testDiff);

expect(hasRulePassed).toBe(true);
});

it('should not pass when receiving a diff with a new JS file on the shared folder', (): void => {
const testDiff = [
generateModifyFilesDiff('new-file.ts', 'foo', 'bar'),
generateModifyFilesDiff('old-file.js', undefined, 'pong'),
generateCreateFileDiff('app/test.js', 'yada yada yada yada'),
].join('');

const hasRulePassed = preventJavaScriptFileAdditions(testDiff);

expect(hasRulePassed).toBe(false);
});

it('should not pass when receiving a diff with a new JSX file on the shared folder', (): void => {
const testDiff = [
generateModifyFilesDiff('new-file.ts', 'foo', 'bar'),
generateModifyFilesDiff('old-file.js', undefined, 'pong'),
generateCreateFileDiff('app/test.jsx', 'yada yada yada yada'),
].join('');

const hasRulePassed = preventJavaScriptFileAdditions(testDiff);

expect(hasRulePassed).toBe(false);
});
});
12 changes: 12 additions & 0 deletions .github/scripts/fitness-functions/rules/javascript-additions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { APP_FOLDER_JS_REGEX } from '../common/constants';
import { filterDiffFileCreations, restrictedFilePresent } from '../common/shared';

function preventJavaScriptFileAdditions(diff: string): boolean {
const diffAdditions = filterDiffFileCreations(diff);
if (restrictedFilePresent(diffAdditions, APP_FOLDER_JS_REGEX)) {
return false;
}
return true;
}

export { preventJavaScriptFileAdditions };
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Current Main Branch

## 7.24.3 - Jun 19, 2024
### Fixed
- [#10045](https://github.com/MetaMask/metamask-mobile/pull/10045): fix: Update ppom package to 1.4.8 (#10041)

## 7.24.2 - Jun 13, 2024
### Added
- [#9687](https://github.com/MetaMask/metamask-mobile/pull/9687): feat: adds "data collection for marketing" toggles
Expand Down
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ android {
applicationId "io.metamask"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1348
versionName "7.24.2"
versionCode 1351
versionName "7.24.3"
testBuildType System.getProperty('testBuildType', 'debug')
missingDimensionStrategy 'react-native-camera', 'general'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
36 changes: 20 additions & 16 deletions app/components/Nav/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,9 @@ const App = ({ userLoggedIn }) => {
animationNameRef?.current?.play();
}
};
appTriggeredAuth()
.then(() => {
queueOfHandleDeeplinkFunctions.current.forEach((func) => func());

queueOfHandleDeeplinkFunctions.current = [];
})
.catch((error) => {
Logger.error(error, 'App: Error in appTriggeredAuth');
});
appTriggeredAuth().catch((error) => {
Logger.error(error, 'App: Error in appTriggeredAuth');
});
}, [navigator, queueOfHandleDeeplinkFunctions]);

const handleDeeplink = useCallback(({ error, params, uri }) => {
Expand Down Expand Up @@ -415,9 +409,11 @@ const App = ({ userLoggedIn }) => {
handleDeeplink(opts);
} else {
queueOfHandleDeeplinkFunctions.current =
queueOfHandleDeeplinkFunctions.current.concat(() => {
handleDeeplink(opts);
});
queueOfHandleDeeplinkFunctions.current.concat([
() => {
handleDeeplink(opts);
},
]);
}
});
}
Expand Down Expand Up @@ -456,17 +452,25 @@ const App = ({ userLoggedIn }) => {
try {
const sdkConnect = SDKConnect.getInstance();
await sdkConnect.init({ navigation: navigator, context: 'Nav/App' });
await SDKConnect.getInstance().postInit();
await SDKConnect.getInstance().postInit(() => {
setTimeout(() => {
queueOfHandleDeeplinkFunctions.current = [];
}, 1000);
});
sdkInit.current = true;
} catch (err) {
sdkInit.current = undefined;
console.error(`Cannot initialize SDKConnect`, err);
}
}
}
initSDKConnect().catch((err) => {
Logger.error(err, 'Error initializing SDKConnect');
});
initSDKConnect()
.then(() => {
queueOfHandleDeeplinkFunctions.current.forEach((func) => func());
})
.catch((err) => {
Logger.error(err, 'Error initializing SDKConnect');
});
}, [navigator, onboarded, userLoggedIn]);

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/AssetOverview/AssetOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const AssetOverview: React.FC<AssetOverviewProps> = ({
const itemAddress = safeToChecksumAddress(asset.address);
const exchangeRate =
itemAddress && itemAddress in tokenExchangeRates
? tokenExchangeRates[itemAddress]
? tokenExchangeRates?.[itemAddress]?.price
: undefined;

let balance, balanceFiat;
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/NetworkInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { connect, useSelector } from 'react-redux';
import Description from './InfoDescription';
import { useTheme } from '../../../util/theme';
import { fontStyles } from '../../../styles/common';
import { isTokenDetectionSupportedForNetwork } from '@metamask/assets-controllers/dist/assetsUtil';
import { isTokenDetectionSupportedForNetwork } from '@metamask/assets-controllers';
import { NETWORK_EDUCATION_MODAL_CLOSE_BUTTON } from '../../../../wdio/screen-objects/testIDs/Screens/NetworksScreen.testids.js';
import { selectProviderConfig } from '../../../selectors/networkController';
import {
Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/Notification/BaseNotification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import IonicIcon from 'react-native-vector-icons/Ionicons';
import AntIcon from 'react-native-vector-icons/AntDesign';
import Text from '../../../Base/Text';
import { useTheme } from '../../../../util/theme';
import { CommonSelectorsIDs } from '../../../../../e2e/selectors/Common.selectors';
import { ToastSelectorsIDs } from '../../../../../e2e/selectors/Modals/ToastModal.selectors';

const createStyles = (colors) =>
StyleSheet.create({
Expand Down Expand Up @@ -185,7 +185,7 @@ const BaseNotification = ({
<View style={styles.flashLabel}>
<Text
style={styles.flashTitle}
testID={CommonSelectorsIDs.TOAST_NOTIFICATION_TITLE}
testID={ToastSelectorsIDs.NOTIFICATION_TITLE}
>
{!title ? getTitle(status, data) : title}
</Text>
Expand Down
13 changes: 8 additions & 5 deletions app/components/UI/PaymentRequest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { toLowerCaseEquals } from '../../../util/general';
import { utils as ethersUtils } from 'ethers';
import { ThemeContext, mockTheme } from '../../../util/theme';
import { isTestNet } from '../../../util/networks';
import { isTokenDetectionSupportedForNetwork } from '@metamask/assets-controllers/dist/assetsUtil';
import { isTokenDetectionSupportedForNetwork } from '@metamask/assets-controllers';
import {
selectChainId,
selectTicker,
Expand Down Expand Up @@ -553,7 +553,7 @@ class PaymentRequest extends PureComponent {
const exchangeRate =
selectedAsset &&
selectedAsset.address &&
contractExchangeRates[selectedAsset.address];
contractExchangeRates?.[selectedAsset.address]?.price;
if (selectedAsset.symbol !== 'ETH') {
secondaryAmount = exchangeRate
? balanceToFiat(
Expand Down Expand Up @@ -587,7 +587,8 @@ class PaymentRequest extends PureComponent {
const exchangeRate =
selectedAsset &&
selectedAsset.address &&
contractExchangeRates[selectedAsset.address];
contractExchangeRates &&
contractExchangeRates[selectedAsset.address]?.price;
const undefAmount = (isDecimal(amount) && amount) || 0;
let secondaryAmount, cryptoAmount;
if (selectedAsset.symbol !== 'ETH' && exchangeRate && exchangeRate !== 0) {
Expand Down Expand Up @@ -631,7 +632,8 @@ class PaymentRequest extends PureComponent {
const exchangeRate =
selectedAsset &&
selectedAsset.address &&
contractExchangeRates[selectedAsset.address];
contractExchangeRates &&
contractExchangeRates[selectedAsset.address]?.price;
let res;
// If primary currency is not crypo we need to know if there are conversion and exchange rates to handle0,
// fiat conversion for the payment request
Expand Down Expand Up @@ -745,7 +747,8 @@ class PaymentRequest extends PureComponent {
const exchangeRate =
selectedAsset &&
selectedAsset.address &&
contractExchangeRates[selectedAsset.address];
contractExchangeRates &&
contractExchangeRates[selectedAsset.address]?.price;
let switchable = true;
const colors = this.context.colors || mockTheme.colors;
const themeAppearance = this.context.themeAppearance || 'light';
Expand Down
5 changes: 1 addition & 4 deletions app/components/UI/Ramp/hooks/useBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ export default function useBalance(asset?: Asset) {
);
balanceFiat = weiToFiat(balanceBN, conversionRate, currentCurrency);
} else {
const exchangeRate =
assetAddress && assetAddress in tokenExchangeRates
? tokenExchangeRates[assetAddress]
: undefined;
const exchangeRate = tokenExchangeRates?.[assetAddress]?.price;
balance =
assetAddress && assetAddress in balances
? renderFromTokenMinimalUnit(
Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/Swaps/components/TokenSelectModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ function TokenSelectModal({
);
} else {
const exchangeRate =
itemAddress in tokenExchangeRates
? tokenExchangeRates[itemAddress]
tokenExchangeRates && itemAddress in tokenExchangeRates
? tokenExchangeRates[itemAddress]?.price
: undefined;
balance =
itemAddress in balances
Expand Down
19 changes: 2 additions & 17 deletions app/components/UI/Swaps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ import { MetaMetricsEvents } from '../../../core/Analytics';

import {
getFeatureFlagChainId,
setSwapsHasOnboarded,
setSwapsLiveness,
swapsControllerTokens,
swapsHasOnboardedSelector,
swapsTokensSelector,
swapsTokensWithBalanceSelector,
swapsTopAssetsSelector,
Expand Down Expand Up @@ -198,8 +196,6 @@ function SwapsAmountView({
conversionRate,
tokenExchangeRates,
currentCurrency,
userHasOnboarded,
setHasOnboarded,
setLiveness,
}) {
const navigation = useNavigation();
Expand Down Expand Up @@ -502,8 +498,8 @@ function SwapsAmountView({
} else {
const sourceAddress = safeToChecksumAddress(sourceToken.address);
const exchangeRate =
sourceAddress in tokenExchangeRates
? tokenExchangeRates[sourceAddress]
tokenExchangeRates && sourceAddress in tokenExchangeRates
? tokenExchangeRates[sourceAddress]?.price
: undefined;
balanceFiat = balanceToFiat(
amount,
Expand Down Expand Up @@ -978,14 +974,6 @@ SwapsAmountView.propTypes = {
* An object containing token exchange rates in the format address => exchangeRate
*/
tokenExchangeRates: PropTypes.object,
/**
* Wether the user has been onboarded or not
*/
userHasOnboarded: PropTypes.bool,
/**
* Function to set hasOnboarded
*/
setHasOnboarded: PropTypes.func,
/**
* Current network provider configuration
*/
Expand Down Expand Up @@ -1018,12 +1006,9 @@ const mapStateToProps = (state) => ({
chainId: selectChainId(state),
tokensWithBalance: swapsTokensWithBalanceSelector(state),
tokensTopAssets: swapsTopAssetsSelector(state),
userHasOnboarded: swapsHasOnboardedSelector(state),
});

const mapDispatchToProps = (dispatch) => ({
setHasOnboarded: (hasOnboarded) =>
dispatch(setSwapsHasOnboarded(hasOnboarded)),
setLiveness: (chainId, featureFlags) =>
dispatch(setSwapsLiveness(chainId, featureFlags)),
});
Expand Down
Loading

0 comments on commit 4107d70

Please sign in to comment.