Skip to content

Commit

Permalink
[Patch fix] Android build for snaps integration system (#6053)
Browse files Browse the repository at this point in the history
* swap for rn-fetch-blob

* remove unused file
  • Loading branch information
owencraston authored Mar 27, 2023
1 parent 4ffc810 commit 5ec6a86
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 147 deletions.
6 changes: 3 additions & 3 deletions app/core/Snaps/location/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable import/prefer-default-export */
import ReactNativeBlobUtil, { FetchBlobResponse } from 'react-native-blob-util';
import RNFetchBlob, { FetchBlobResponse } from 'rn-fetch-blob';
import Logger from '../../../util/Logger';

const SNAPS_FETCH_LOG_TAG = 'Snaps/ fetch';
Expand All @@ -11,7 +11,7 @@ const SNAPS_FETCH_LOG_TAG = 'Snaps/ fetch';
*/
const readAndParseFile = async (path: string) => {
try {
const data = await ReactNativeBlobUtil.fs.readFile(path, 'utf8');
const data = await RNFetchBlob.fs.readFile(path, 'utf8');
return data;
} catch (error) {
Logger.log(SNAPS_FETCH_LOG_TAG, 'readAndParseFile error', error);
Expand All @@ -37,7 +37,7 @@ const convertFetchBlobResponseToResponse = async (
export const fetchFunction = async (
inputRequest: RequestInfo,
): Promise<Response> => {
const { config } = ReactNativeBlobUtil;
const { config } = RNFetchBlob;
const urlToFetch: string =
typeof inputRequest === 'string' ? inputRequest : inputRequest.url;
const response: FetchBlobResponse = await config({ fileCache: true }).fetch(
Expand Down
19 changes: 9 additions & 10 deletions app/core/Snaps/location/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { assert, assertStruct, isObject } from '@metamask/utils';

import { DetectSnapLocationOptions, SnapLocation } from './location';
import { NativeModules } from 'react-native';
import RNFetchBlob, { FetchBlobResponse } from 'rn-fetch-blob';
import Logger from '../../../util/Logger';

const { RNTar } = NativeModules;

const DEFAULT_NPM_REGISTRY = 'https://registry.npmjs.org';
Expand Down Expand Up @@ -52,10 +55,6 @@ export interface NpmOptions {
allowCustomRegistries?: boolean;
}

/* eslint-disable import/prefer-default-export */
import ReactNativeBlobUtil, { FetchBlobResponse } from 'react-native-blob-util';
import Logger from '../../../util/Logger';

const SNAPS_NPM_LOG_TAG = 'snaps/ NPM';

/**
Expand All @@ -82,7 +81,7 @@ const decompressFile = async (
const readAndParseSourceCode = async (path: string) => {
try {
const sourceCodePath = `${path}/package/dist/bundle.js`;
const data = await ReactNativeBlobUtil.fs.readFile(sourceCodePath, 'utf8');
const data = await RNFetchBlob.fs.readFile(sourceCodePath, 'utf8');
return data;
} catch (error) {
Logger.log(SNAPS_NPM_LOG_TAG, 'readAndParseSourceCode error', error);
Expand All @@ -92,7 +91,7 @@ const readAndParseSourceCode = async (path: string) => {
const readAndParseManifest = async (path: string) => {
try {
const manifestPath = `${path}/package/snap.manifest.json`;
const data = await ReactNativeBlobUtil.fs.readFile(manifestPath, 'utf8');
const data = await RNFetchBlob.fs.readFile(manifestPath, 'utf8');
return data;
} catch (error) {
Logger.log(SNAPS_NPM_LOG_TAG, 'readAndParseManifest error', error);
Expand All @@ -102,7 +101,7 @@ const readAndParseManifest = async (path: string) => {
const readAndParseIcon = async (path: string) => {
try {
const iconPath = `${path}/package/images/icon.svg`;
const data = await ReactNativeBlobUtil.fs.readFile(iconPath, 'utf8');
const data = await RNFetchBlob.fs.readFile(iconPath, 'utf8');
return data;
} catch (error) {
Logger.log(SNAPS_NPM_LOG_TAG, 'readAndParseManifest error', error);
Expand All @@ -112,8 +111,8 @@ const readAndParseIcon = async (path: string) => {
const fetchAndStoreNPMPackage = async (
inputRequest: RequestInfo,
): Promise<string> => {
const { config } = ReactNativeBlobUtil;
const filePath = `${ReactNativeBlobUtil.fs.dirs.DocumentDir}/archive.tgz`;
const { config } = RNFetchBlob;
const filePath = `${RNFetchBlob.fs.dirs.DocumentDir}/archive.tgz`;
const urlToFetch: string =
typeof inputRequest === 'string' ? inputRequest : inputRequest.url;

Expand All @@ -123,7 +122,7 @@ const fetchAndStoreNPMPackage = async (
path: filePath,
}).fetch('GET', urlToFetch);
const dataPath = response.data;
const targetPath = ReactNativeBlobUtil.fs.dirs.DocumentDir;
const targetPath = RNFetchBlob.fs.dirs.DocumentDir;
try {
const decompressedPath = await decompressFile(dataPath, targetPath);
return decompressedPath;
Expand Down
5 changes: 2 additions & 3 deletions app/util/browser/downloadFile.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Linking } from 'react-native';
import Share, { ShareOptions } from 'react-native-share';
import { ShareOpenResult } from 'react-native-share/lib/typescript/types';
// import RNFetchBlob, { FetchBlobResponse } from 'rn-fetch-blob';
import ReactNativeBlobUtil, { FetchBlobResponse } from 'react-native-blob-util';
import RNFetchBlob, { FetchBlobResponse } from 'rn-fetch-blob';
import { strings } from '../../../locales/i18n';
import Device from '../device';

Expand Down Expand Up @@ -55,7 +54,7 @@ const checkAppleWalletPass = async (
};

const downloadFile = async (downloadUrl: string): Promise<DownloadResult> => {
const { config } = ReactNativeBlobUtil;
const { config } = RNFetchBlob;
const response: FetchBlobResponse = await config({ fileCache: true }).fetch(
'GET',
downloadUrl,
Expand Down
96 changes: 0 additions & 96 deletions app/util/snaps/fetchNPMPackage.ts

This file was deleted.

12 changes: 6 additions & 6 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,6 @@ PODS:
- React
- react-native-background-timer (2.1.1):
- React
- react-native-blob-util (0.17.2):
- React-Core
- react-native-blur (0.8.0):
- React
- react-native-branch (5.6.2):
Expand Down Expand Up @@ -415,6 +413,8 @@ PODS:
- React-perflogger (= 0.66.5)
- ReactNativePayments (1.5.0):
- React
- rn-fetch-blob (0.12.0):
- React-Core
- RNCAsyncStorage (1.17.10):
- React-Core
- RNCCheckbox (0.5.12):
Expand Down Expand Up @@ -544,7 +544,6 @@ DEPENDENCIES:
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
- react-native-aes (from `../node_modules/react-native-aes-crypto`)
- react-native-background-timer (from `../node_modules/react-native-background-timer`)
- react-native-blob-util (from `../node_modules/react-native-blob-util`)
- "react-native-blur (from `../node_modules/@react-native-community/blur`)"
- react-native-branch (from `../node_modules/react-native-branch`)
- react-native-camera (from `../node_modules/react-native-camera`)
Expand Down Expand Up @@ -575,6 +574,7 @@ DEPENDENCIES:
- React-runtimeexecutor (from `../node_modules/react-native/ReactCommon/runtimeexecutor`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- "ReactNativePayments (from `../node_modules/@exodus/react-native-payments/lib/ios`)"
- rn-fetch-blob (from `../node_modules/rn-fetch-blob`)
- "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)"
- "RNCCheckbox (from `../node_modules/@react-native-community/checkbox`)"
- "RNCClipboard (from `../node_modules/@react-native-clipboard/clipboard`)"
Expand Down Expand Up @@ -667,8 +667,6 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native-aes-crypto"
react-native-background-timer:
:path: "../node_modules/react-native-background-timer"
react-native-blob-util:
:path: "../node_modules/react-native-blob-util"
react-native-blur:
:path: "../node_modules/@react-native-community/blur"
react-native-branch:
Expand Down Expand Up @@ -729,6 +727,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon"
ReactNativePayments:
:path: "../node_modules/@exodus/react-native-payments/lib/ios"
rn-fetch-blob:
:path: "../node_modules/rn-fetch-blob"
RNCAsyncStorage:
:path: "../node_modules/@react-native-async-storage/async-storage"
RNCCheckbox:
Expand Down Expand Up @@ -818,7 +818,6 @@ SPEC CHECKSUMS:
React-logger: fa4ff1e9c7e115648f7c5dafb7c20822ab4f7a7e
react-native-aes: ff31f0dd4c791eb423a631ee04570fcf3c618924
react-native-background-timer: 1b6e6b4e10f1b74c367a1fdc3c72b67c619b222b
react-native-blob-util: 31b9463ef2efe90e841e7525d687ec69b1d71157
react-native-blur: cad4d93b364f91e7b7931b3fa935455487e5c33c
react-native-branch: 4e42fda662d96893afbbd02839806931398e3d2e
react-native-camera: b8cc03e2feec0c04403d0998e37cf519d8fd4c6f
Expand Down Expand Up @@ -849,6 +848,7 @@ SPEC CHECKSUMS:
React-runtimeexecutor: 09041c28ce04143a113eac2d357a6b06bd64b607
ReactCommon: 8a7a138ae43c04bb8dd760935589f326ca810484
ReactNativePayments: a4e3ac915256a4e759c8a04338b558494a63a0f5
rn-fetch-blob: f065bb7ab7fb48dd002629f8bdcb0336602d3cba
RNCAsyncStorage: 0c357f3156fcb16c8589ede67cc036330b6698ca
RNCCheckbox: ed1b4ca295475b41e7251ebae046360a703b6eb5
RNCClipboard: ddd4d291537f1667209c9c405aaa4307297e252e
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@
"@metamask/network-controller": "^2.0.0",
"@metamask/permission-controller": "^1.0.2",
"@metamask/phishing-controller": "^2.0.0",
"@metamask/rpc-methods": "0.24.1",
"@metamask/post-message-stream": "6.0.0",
"@metamask/preferences-controller": "^2.1.0",
"@metamask/rpc-methods": "0.24.1",
"@metamask/sdk-communication-layer": "^0.1.0",
"@metamask/snaps-controllers": "0.26.2",
"@metamask/snaps-utils": "0.26.2",
Expand Down Expand Up @@ -253,7 +253,6 @@
"react-native-animatable": "^1.3.3",
"react-native-animated-fox": "git+https://github.com/MetaMask/react-native-animated-fox.git#16e38d54d829709e497f196e31fa8ff00cdf2aa9",
"react-native-background-timer": "2.1.1",
"react-native-blob-util": "^0.17.2",
"react-native-branch": "^5.6.2",
"react-native-browser-polyfill": "0.1.2",
"react-native-button": "git+https://github.com/MetaMask/react-native-button.git#c685e7882034543ceea3f09f6e3d205d18fce46e",
Expand Down Expand Up @@ -313,8 +312,9 @@
"redux": "4.1.1",
"redux-mock-store": "1.5.4",
"redux-persist": "6.0.0",
"redux-persist-filesystem-storage": "4.1.0",
"redux-persist-filesystem-storage": "3.0.0",
"reselect": "^4.0.0",
"rn-fetch-blob": "^0.12.0",
"socket.io-client": "^4.5.3",
"stream-browserify": "1.0.0",
"swappable-obj-proxy": "^1.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ index b0caa94..76b0442 100644
) => Promise<void>

diff --git a/node_modules/redux-persist-filesystem-storage/index.js b/node_modules/redux-persist-filesystem-storage/index.js
index d69afb6..dec9c61 100644
index 7198fde..d5936df 100644
--- a/node_modules/redux-persist-filesystem-storage/index.js
+++ b/node_modules/redux-persist-filesystem-storage/index.js
@@ -41,11 +41,14 @@ const FilesystemStorage = {
Expand All @@ -20,14 +20,14 @@ index d69afb6..dec9c61 100644

- setItem: (key: string, value: string, callback?: (error: ?Error) => void) =>
+ setItem: (key: string, value: string, isIOS: boolean = false, callback?: (error: ?Error) => void) => {
ReactNativeBlobUtil.fs
RNFetchBlob.fs
.writeFile(pathForKey(key), value, options.encoding)
- .then(() => callback && callback())
- .catch(error => callback && callback(error)),
+ .then(() => {
+ if (isIOS) ReactNativeBlobUtil.ios.excludeFromBackupKey(pathForKey(key));
+ if (isIOS) RNFetchBlob.ios.excludeFromBackupKey(pathForKey(key));
+ callback && callback();
+ }).catch(error => callback && callback(error));
+ }).catch(error => callback && callback(error));
+ },

getItem: onStorageReady(
Expand Down
36 changes: 14 additions & 22 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14457,7 +14457,7 @@ glob-parent@^5.0.0, glob-parent@^5.1.2, glob-parent@~5.1.2:
dependencies:
is-glob "^4.0.1"

[email protected], glob@^6.0.1, glob@^7.0.0, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6, glob@^7.2.3, glob@^8.0.3, glob@~7.1.1:
glob@7.0.6, glob@8.0.3, glob@^6.0.1, glob@^7.0.0, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6, glob@^8.0.3, glob@~7.1.1:
version "8.0.3"
resolved "https://registry.yarnpkg.com/glob/-/glob-8.0.3.tgz#415c6eb2deed9e502c68fa44a272e6da6eeca42e"
integrity sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==
Expand Down Expand Up @@ -21063,22 +21063,6 @@ [email protected]:
resolved "https://registry.yarnpkg.com/react-native-background-timer/-/react-native-background-timer-2.1.1.tgz#9a2489681ab2f8033c213c73272e9d4c47572cd5"
integrity sha512-cuXIIv+dcG8a8qkTD8pMzeqOEZCO+UGKglZWIe1osve+yJslmCowYQff+bI9xa7NOt2w+Vtd4L3d9JonlSqODg==

react-native-blob-util@^0.16.0:
version "0.16.4"
resolved "https://registry.yarnpkg.com/react-native-blob-util/-/react-native-blob-util-0.16.4.tgz#eeb0e28f6fa6ecb357c10f154be3d2e66c010f62"
integrity sha512-rNKMcVsrVn+l6PQVrCIJy3N2t9zEpXP1yrP3CdnWNHh9Dsup7tJMcoun4S1Cz869L0acx4LiM40XdqqfLyqrDw==
dependencies:
base-64 "0.1.0"
glob "^7.2.3"

react-native-blob-util@^0.17.2:
version "0.17.2"
resolved "https://registry.yarnpkg.com/react-native-blob-util/-/react-native-blob-util-0.17.2.tgz#5a3b31d827bd8cc4306cf6fa39e842a38c5d96b0"
integrity sha512-JXdUt/NfG6lDtDNDJ4/mAXiOl4elzhIPZDWQBlIwiCwQczo4TU10iGZl5+f8uMwKtbh3leuUjL2PESOkBYCRBg==
dependencies:
base-64 "0.1.0"
glob "^7.2.3"

react-native-branch@^5.6.2:
version "5.6.2"
resolved "https://registry.yarnpkg.com/react-native-branch/-/react-native-branch-5.6.2.tgz#c3ec137a5427a21fcd6559b83f02e6162ea627f6"
Expand Down Expand Up @@ -21977,12 +21961,12 @@ [email protected]:
dependencies:
lodash.isplainobject "^4.0.6"

redux-persist-filesystem-storage@4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/redux-persist-filesystem-storage/-/redux-persist-filesystem-storage-4.1.0.tgz#bfe62aa2287d980e43a7987de04fa443d0c62337"
integrity sha512-ufwl883C68aoOzOBc4so5cx0ka4atcXp5VW4S0o/MyykxwgKB976NuNYp723zx/3aAAk3llFMfdbDnhcroju2Q==
redux-persist-filesystem-storage@3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/redux-persist-filesystem-storage/-/redux-persist-filesystem-storage-3.0.0.tgz#4848825d6157f694af5218d8ebb3ca6db09d3cb9"
integrity sha512-rJe8Hb5ULC/rUyqt5E1G62r1cUQA7hmdrVd38q32bWRnv+KiIAORuzpcOW5eDkzaS0w3v1juxUcKciNyZmeCsg==
dependencies:
react-native-blob-util "^0.16.0"
rn-fetch-blob "^0.12.0"

[email protected]:
version "6.0.0"
Expand Down Expand Up @@ -22445,6 +22429,14 @@ rlp@^3.0.0:
resolved "https://registry.yarnpkg.com/rlp/-/rlp-3.0.0.tgz#5a60725ca4314a3a165feecca1836e4f2c1e2343"
integrity sha512-PD6U2PGk6Vq2spfgiWZdomLvRGDreBLxi5jv5M8EpRo3pU6VEm31KO+HFxE18Q3vgqfDrQ9pZA3FP95rkijNKw==

rn-fetch-blob@^0.12.0:
version "0.12.0"
resolved "https://registry.yarnpkg.com/rn-fetch-blob/-/rn-fetch-blob-0.12.0.tgz#ec610d2f9b3f1065556b58ab9c106eeb256f3cba"
integrity sha512-+QnR7AsJ14zqpVVUbzbtAjq0iI8c9tCg49tIoKO2ezjzRunN7YL6zFSFSWZm6d+mE/l9r+OeDM3jmb2tBb2WbA==
dependencies:
base-64 "0.1.0"
glob "7.0.6"

[email protected]:
version "10.0.1"
resolved "https://registry.yarnpkg.com/rn-nodeify/-/rn-nodeify-10.0.1.tgz#b54a3f2a61eda88b40639ee9262f51f34039e353"
Expand Down

0 comments on commit 5ec6a86

Please sign in to comment.