Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Create custom detectSnapLocation to install Snap from NPM on Android #6052

Closed
wants to merge 107 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
2478f4a
Add some poc code
gantunesr Nov 11, 2022
62cf98f
Move constants to new file
gantunesr Nov 17, 2022
a0f41a5
Move mockss to new file
gantunesr Nov 17, 2022
449ebc0
Update POC code with new solution
gantunesr Nov 17, 2022
1fa6956
Move utils to new file
gantunesr Nov 17, 2022
4ffeeca
Create HTML files for testing
gantunesr Nov 17, 2022
be10aec
Delete old file
gantunesr Nov 17, 2022
59cf205
Remove eslint disable comment
gantunesr Nov 17, 2022
457e6f0
Update eslint ignorePattern (revert later)
gantunesr Nov 17, 2022
0460f17
Add helloWorld_snap bundle
gantunesr Nov 17, 2022
50a70e9
Update bundle helloWorld_snap
gantunesr Nov 17, 2022
d08df4f
Update bundle helloWorld_snap
gantunesr Nov 17, 2022
22b103a
Add start snap command
gantunesr Nov 17, 2022
9313c67
Update example iframe
gantunesr Nov 17, 2022
40a50ee
Update base html
gantunesr Nov 17, 2022
fcd417d
Update @types/react
gantunesr Nov 18, 2022
b09054f
Remove code
gantunesr Nov 18, 2022
de5ac4c
Add new file for communication
gantunesr Nov 18, 2022
45fe053
Update script
gantunesr Nov 18, 2022
a6976d9
Update dependencies
gantunesr Nov 20, 2022
1e7dd6c
Add SnapExecutionService
gantunesr Nov 20, 2022
1b44b0f
Update code
gantunesr Nov 21, 2022
2a9ee01
WebviewPostMessageStream
andrepimenta Nov 24, 2022
5aede1a
Update POC
gantunesr Nov 23, 2022
a3e703c
Adding missing files
andrepimenta Nov 24, 2022
7416909
Update Engine.js
andrepimenta Nov 24, 2022
e87133a
Update UI
gantunesr Nov 26, 2022
67a9816
Fix interface name
gantunesr Nov 26, 2022
62bdf22
Add config to resolve stream
gantunesr Dec 4, 2022
39c165a
Add pako module
gantunesr Dec 4, 2022
605d26a
Add methods to fetch snap
gantunesr Dec 4, 2022
4eb7e4f
Update mock id
gantunesr Dec 4, 2022
6d1ca59
Update logic
gantunesr Dec 8, 2022
009df8e
Add @metamask/snap-controllers patch
gantunesr Dec 8, 2022
c23e724
Update logic to call SnapController
gantunesr Dec 12, 2022
e650d1a
Fix _initEnvStream bug
gantunesr Dec 12, 2022
52846a5
Add method to install snap from localhost
gantunesr Dec 13, 2022
400b97b
Ideas to install a snap from NPM
gantunesr Dec 13, 2022
ab0ce8f
Add SnapBridge
gantunesr Dec 13, 2022
3472008
Update SnapController patch
gantunesr Dec 13, 2022
12959cb
Working version
gantunesr Dec 13, 2022
3562ff6
Update code to test snap
gantunesr Dec 14, 2022
ef1e0f2
Add SnapDuplex
gantunesr Dec 14, 2022
200b5b8
Update log
gantunesr Dec 14, 2022
e7d6979
Add SnapWebviewPostMessageStream
gantunesr Dec 14, 2022
249ec69
Update WebviewExecutionService
gantunesr Dec 14, 2022
7230a84
Update WebviewPostMessageStream
gantunesr Dec 14, 2022
a96fa60
Update SnapController patch
gantunesr Dec 14, 2022
561c672
Terminate snap after install
gantunesr Dec 14, 2022
aaf53d8
Add mock methods
gantunesr Dec 14, 2022
6e47f6e
Remove logs from SnapWebviewPostMessageStream
gantunesr Dec 14, 2022
0a5faf7
Update test UI
gantunesr Dec 14, 2022
4681619
Update test UI
gantunesr Dec 14, 2022
ad3d970
Add logs to SnapWebviewPostMessageStream
gantunesr Dec 14, 2022
c82afa4
Update logs in WebviewExecutionService
gantunesr Dec 14, 2022
5cac541
Update logs in WebviewPostMessageStream
gantunesr Dec 14, 2022
3e69ef8
Update logs in SnapBridge
gantunesr Dec 14, 2022
71de66f
Update patch
gantunesr Dec 14, 2022
cdba21f
Add action to get installed snaps
gantunesr Dec 15, 2022
433f982
Comment terminateSnap method
gantunesr Dec 15, 2022
a212f4b
Move SnapDuplex to core
gantunesr Dec 15, 2022
e7b57ae
Move SnapWebviewPostMessageStream to core
gantunesr Dec 15, 2022
cbdfe0f
Move WebviewExecutionService to core
gantunesr Dec 15, 2022
e641d20
Move WebviewPostMessageStream to core
gantunesr Dec 15, 2022
dfc5168
Move SnapBridge to core
gantunesr Dec 15, 2022
8c6ce29
Delete SnapExecutionService
gantunesr Dec 15, 2022
139cb56
Upadte Snaps core index
gantunesr Dec 15, 2022
d9e8c44
Update paths
gantunesr Dec 15, 2022
d08905c
Move fetchNPMPackage to utils/snaps
gantunesr Dec 15, 2022
bc22e11
Remoce POC code
gantunesr Dec 15, 2022
3117374
Move Snaps WebView to different component
gantunesr Dec 15, 2022
78ec05a
Update structure
gantunesr Dec 15, 2022
9d6a20f
Add styles to SnapsExecutionWebView for debugging
gantunesr Dec 16, 2022
687e9c3
Send valid method
gantunesr Dec 16, 2022
88cb40f
Update patch
gantunesr Dec 16, 2022
0128e67
Include SnapController to engine init
gantunesr Dec 21, 2022
8d81c4d
Clean fetchNPMPackage file
gantunesr Dec 28, 2022
c012379
Merge main
gantunesr Jan 30, 2023
2e3e53d
Merge main
gantunesr Jan 30, 2023
2c40431
Add snap UI (base)
gantunesr Jan 30, 2023
56712f8
Snaps developer UI
gantunesr Jan 29, 2023
d1ece96
Update UI
gantunesr Jan 30, 2023
4878832
Remove logs
gantunesr Jan 30, 2023
f936a25
Update structure
gantunesr Jan 30, 2023
de43e3b
Revert "Remove logs"
gantunesr Jan 30, 2023
0e5c6ad
Solve merge bugs
gantunesr Feb 3, 2023
dac0135
Integrate PS
gantunesr Feb 3, 2023
0e5b9ed
Fix imports
gantunesr Feb 3, 2023
a095e57
Update snaps-controller package
gantunesr Feb 20, 2023
d2dd581
Update snaps-controller package
gantunesr Feb 20, 2023
f07d769
Update patch
gantunesr Feb 20, 2023
983fd67
[FEATURE] Create detectSnapLocation method to install a Local Snap (#…
owencraston Mar 17, 2023
99ed491
Integrate SubjectMetadataController
gantunesr Mar 19, 2023
ef1a031
[FEATURE] Create detectSnapLocation method to install a Snap From NPM…
owencraston Mar 23, 2023
4c43310
Install snap from a Dapp (#6002)
owencraston Mar 27, 2023
2ed6c76
[Patch fix] Android build for snaps integration system (#6053)
owencraston Mar 27, 2023
b91fe80
[Feature] execute snaps methods from Dapp on iOS (#6049)
owencraston Apr 11, 2023
dcd70e3
add native module
owencraston Mar 27, 2023
b370333
wip decompresstgz
owencraston Mar 28, 2023
bfc7f3e
use apache compress and return value
owencraston Mar 29, 2023
53de063
debugging
owencraston Apr 17, 2023
213c5f8
debug more
owencraston Apr 18, 2023
f13c34e
closer
owencraston Apr 18, 2023
12d8ee7
native module working
owencraston Apr 19, 2023
67bdd2f
remove useless code
owencraston Apr 20, 2023
e3f16e5
try and use react-native-blob-utils
owencraston Apr 21, 2023
8395f96
pin version
owencraston Apr 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 0 additions & 12 deletions .eslintignore

This file was deleted.

2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,5 @@ module.exports = {
radix: 0,
},

ignorePatterns: ['wdio.conf.js'],
ignorePatterns: ['wdio.conf.js', 'snap_bundles/*.js'],
};
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/android/app/src/main/assets/InpageBridgeWeb3.js
/app/core/InpageBridgeWeb3.js
/app/util/blockies.js
__snapshots__
Expand All @@ -9,3 +10,4 @@ node_modules
CHANGELOG.md
# Ignore auto generated file used for react-native-storybook-loader
/storybook/storyLoader.js
wdio
19 changes: 19 additions & 0 deletions 2q
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Update @types/react

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Author: Gustavo Antunes <[email protected]>
#
# interactive rebase in progress; onto c96634fd4
# Last commands done (16 commands done):
# pick 0c3c9909f Update base html
# pick 831a33b10 Update @types/react
# Next commands to do (123 remaining commands):
# pick 5c30f89ae Remove code
# pick 4aeed70f9 Add new file for communication
# You are currently rebasing branch 'decompress-snap-tarball-android' on 'c96634fd4'.
#
# Changes to be committed:
# modified: app/components/UI/AccountOverview/index.js
#
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ sudo gem install cocoapods -v 1.11.3

#### Android

- Install [Java](https://www.java.com/en/download/). To check if Java is already installed, run:
```
java -version
```
- Install the Android SDK, via [Android Studio](https://developer.android.com/studio).
- _MetaMask Only:_ To create production builds, you need to install Google Play Licensing Library via the SDK Manager in Android Studio.
- Install the Android NDK (version `21.4.7075529`), via [Android Studio](https://developer.android.com/studio)'s SDK Manager.
Expand All @@ -64,9 +60,7 @@ sudo gem install cocoapods -v 1.11.3
- You should use the following:
- **Android OS Version:** Latest, unless told otherwise
- **Device:** Google Pixel 3
- Finally, start the emulator from Android Studio:
- Open "Virtual Device Manager"
- Launch emulator for "Pixel 3 <relevant API version mentioned in [React Native Getting Started](https://reactnative.dev/docs/environment-setup#installing-dependencies)>"
- Finally, start the emulator from Android Studio, and run:


#### iOS
Expand Down
11 changes: 11 additions & 0 deletions android/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1680108115802</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
11 changes: 11 additions & 0 deletions android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=
jvm.arguments=
offline.mode=false
override.workspace.settings=false
show.console.view=false
show.executions.view=false
2 changes: 2 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ configurations.all {
}

dependencies {
implementation project(':react-native-blob-util')
implementation project(':lottie-react-native')

implementation project(':react-native-gesture-handler')
Expand All @@ -288,6 +289,7 @@ dependencies {
androidTestImplementation 'junit:junit:4.12'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
implementation "com.android.installreferrer:installreferrer:2.2"
implementation 'org.apache.commons:commons-compress:1.22'

debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
Expand Down
6 changes: 6 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-sdk tools:overrideLibrary="com.tectiv3.aes" />

<application
Expand Down Expand Up @@ -34,6 +37,9 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
</intent-filter>
</activity>
<activity
android:launchMode="singleTask"
Expand Down
4 changes: 2 additions & 2 deletions android/app/src/main/java/io/metamask/MainApplication.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.metamask;

import com.facebook.react.ReactApplication;
import com.cmcewen.blurview.BlurViewPackage;
import com.brentvatne.react.ReactVideoPackage;
import android.content.Context;
import com.facebook.react.PackageList;
Expand All @@ -17,6 +16,7 @@
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import io.metamask.nativeModules.PreventScreenshotPackage;
import io.metamask.nativeModules.RNTar.RNTarPackage;
import android.webkit.WebView;

import androidx.multidex.MultiDexApplication;
Expand All @@ -43,7 +43,7 @@ protected List<ReactPackage> getPackages() {
packages.add(new RCTAnalyticsPackage());
packages.add(new PreventScreenshotPackage());
packages.add(new ReactVideoPackage());

packages.add(new RNTarPackage());
return packages;
}

Expand Down
115 changes: 115 additions & 0 deletions android/app/src/main/java/io/metamask/nativeModules/RNTar/RNTar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package io.metamask.nativeModules.RNTar;

import androidx.annotation.NonNull;

import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import java.util.Map;
import java.util.HashMap;
import android.util.Log;
import com.facebook.react.bridge.Promise;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;

public class RNTar extends ReactContextBaseJavaModule {
private static String MODULE_NAME = "RNTar";

RNTar(ReactApplicationContext context) {
super(context);
}

@NonNull
@Override
public String getName() {
return MODULE_NAME;
}

private String extractTgzFile(String tgzPath, String outputPath) throws IOException {
try {
// Check if .tgz file exists
File tgzFile = new File(tgzPath);
if (!tgzFile.exists()) {
throw new IOException("The specified .tgz file does not exist.");
}

// Create output directory if it doesn't exist
File outputDirectory = new File(outputPath);
if (!outputDirectory.exists()) {
outputDirectory.mkdirs();
}

// Check if the output directory is readable and writable
if (!outputDirectory.canRead() || !outputDirectory.canWrite()) {
throw new IOException("The output directory is not readable and/or writable.");
}

// Set up the input streams for reading the .tgz file
FileInputStream fileInputStream = new FileInputStream(tgzFile);
GZIPInputStream gzipInputStream = new GZIPInputStream(fileInputStream);
TarArchiveInputStream tarInputStream = new TarArchiveInputStream(new BufferedInputStream(gzipInputStream));

TarArchiveEntry entry;

// Loop through the entries in the .tgz file
while ((entry = (TarArchiveEntry) tarInputStream.getNextEntry()) != null) {
File outputFile = new File(outputDirectory, entry.getName());
System.out.println("Snaps/ entry " + entry.getName());

// If it is a directory, create the output directory
if (entry.isDirectory()) {
outputFile.mkdirs();
} else {
// Create parent directories if they don't exist
outputFile.getParentFile().mkdirs();

// Set up the output streams for writing the file
FileOutputStream fos = new FileOutputStream(outputFile);
BufferedOutputStream dest = new BufferedOutputStream(fos, 1024);

// Initialize a buffer and a variable to hold the number of bytes read
int count;
byte[] data = new byte[1024];

// Read the file data from the .tgz file and write it to the output file
while ((count = tarInputStream.read(data, 0, 1024)) != -1) {
dest.write(data, 0, count);
}
dest.flush();
dest.close();
}
}
fileInputStream.close();
gzipInputStream.close();
tarInputStream.close();

// Return the output directory path
return new File(outputDirectory, "package").getAbsolutePath();
} catch (IOException e) {
Log.e("DecompressTgzFile", "Error decompressing tgz file", e);
throw new IOException("Error decompressing tgz file: " + e.getMessage(), e);
}
}

@ReactMethod
public void unTar(String pathToRead, String pathToWrite, final Promise promise) {
Log.d(MODULE_NAME, "Create event called with name: " + pathToRead
+ " and location: " + pathToWrite);
try {
String decompressedPath = extractTgzFile(pathToRead, pathToWrite);
promise.resolve(decompressedPath);
} catch(Exception e) {
promise.reject("Error uncompressing file:", e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.metamask.nativeModules.RNTar;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class RNTarPackage implements ReactPackage {

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}

@Override
public List<NativeModule> createNativeModules(
ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();

modules.add(new RNTar(reactContext));

return modules;
}

}
2 changes: 2 additions & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ rootProject.name = 'MetaMask'
include ':app'
include ':@react-native-community_blur'
project(':@react-native-community_blur').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/blur/android')
include ':react-native-blob-util'
project(':react-native-blob-util').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-blob-util/android');
include ':lottie-react-native'
project(':lottie-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/lottie-react-native/src/android')
include ':react-native-gesture-handler'
Expand Down
4 changes: 3 additions & 1 deletion app/components/Base/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import {
TextStyle,
} from 'react-native';
import IonicIcon from 'react-native-vector-icons/Ionicons';
import Text from './Text';
import CustomText from './Text';
import { useTheme } from '../../util/theme';
// TODO: Convert into typescript and correctly type optionals
const Text = CustomText as any;

export enum AlertType {
Info = 'Info',
Expand Down
1 change: 0 additions & 1 deletion app/components/Base/RangeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const createStyles = (colors) =>
alignItems: 'center',
justifyContent: 'space-between',
marginBottom: 14,
flexWrap: 'wrap',
},
rangeInputContainer: (error) => ({
borderColor: error ? colors.error.default : colors.border.default,
Expand Down
3 changes: 1 addition & 2 deletions app/components/Base/Text/Text.styles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { StyleSheet } from 'react-native';
import { scale } from 'react-native-size-matters';
import { fontStyles } from '../../../styles/common';
import { Colors } from '../../../util/theme/models';

Expand All @@ -9,7 +8,7 @@ const createStyles = (colors: Colors) =>
...fontStyles.normal,
color: colors.text.default,
marginVertical: 2,
fontSize: scale(14),
fontSize: 14,
},
centered: {
textAlign: 'center',
Expand Down
4 changes: 2 additions & 2 deletions app/components/Base/Title/Title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { useTheme } from '../../../util/theme';
import styles from './Title.styles';

interface TitleProps extends React.ComponentPropsWithoutRef<typeof Text> {
centered?: boolean;
hero?: boolean;
centered: boolean;
hero: boolean;
}

const Title: React.FC<TitleProps> = ({
Expand Down
9 changes: 4 additions & 5 deletions app/components/Nav/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,23 +367,22 @@ const App = ({ userLoggedIn }) => {
}, [navigator]);

useEffect(() => {
async function checkExisting() {
async function checkExsiting() {
const existingUser = await AsyncStorage.getItem(EXISTING_USER);
const route = !existingUser
? Routes.ONBOARDING.ROOT_NAV
: Routes.ONBOARDING.LOGIN;
setRoute(route);
}

checkExisting();
/* eslint-disable react-hooks/exhaustive-deps */
}, []);
checkExsiting();
});

useEffect(() => {
async function startApp() {
const existingUser = await AsyncStorage.getItem(EXISTING_USER);
try {
const currentVersion = getVersion();
const currentVersion = await getVersion();
const savedVersion = await AsyncStorage.getItem(CURRENT_APP_VERSION);
if (currentVersion !== savedVersion) {
if (savedVersion)
Expand Down
Loading