-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe58be8
commit b1d7ed7
Showing
33 changed files
with
1,900 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
app/components/UI/SnapsExecutionWebView/SnapsExecutionWebView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, { useRef } from 'react'; | ||
import { View, ScrollView } from 'react-native'; | ||
import WebView from 'react-native-webview'; | ||
import { snapsState, WebviewPostMessageStream } from '../../../core/Snaps'; | ||
import { createStyles } from './styles'; | ||
|
||
let stream: any; | ||
|
||
const SnapsExecutionWebView = () => { | ||
const styles = createStyles(); | ||
|
||
const webviewRef = useRef(); | ||
|
||
const setWebviewPostMessage = () => { | ||
stream = new WebviewPostMessageStream({ | ||
name: 'rnside', | ||
target: 'webview', | ||
targetOrigin: '*', | ||
targetWindow: webviewRef.current, | ||
}); | ||
|
||
// eslint-disable-next-line no-console | ||
stream.on('data', (data: any) => | ||
// eslint-disable-next-line no-console | ||
console.log( | ||
'[APP LOG] setWebviewPostMessage: Message from Webview ' + data, | ||
), | ||
); | ||
|
||
snapsState.stream = stream; | ||
snapsState.webview = webviewRef.current; | ||
}; | ||
|
||
const messageFromWebview = (data: any) => { | ||
stream?._onMessage(data); | ||
}; | ||
|
||
const envURI = { | ||
prod: 'https://gantunesr.github.io/mobile-execution-environment/', | ||
localIOS: 'http://localhost:3001/mobile-execution-environment', | ||
localAndroid: 'http://10.0.2.2:3001/mobile-execution-environment', | ||
}; | ||
|
||
return ( | ||
<ScrollView style={styles.container}> | ||
<View style={styles.webview}> | ||
<WebView | ||
ref={webviewRef} | ||
source={{ | ||
uri: envURI.prod, | ||
}} | ||
onMessage={messageFromWebview} | ||
onLoadEnd={setWebviewPostMessage} | ||
originWhitelist={['*']} | ||
javaScriptEnabled | ||
/> | ||
</View> | ||
</ScrollView> | ||
); | ||
}; | ||
|
||
export default SnapsExecutionWebView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import SnapsExecutionWebView from './SnapsExecutionWebView'; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export { SnapsExecutionWebView }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* eslint-disable react-native/no-color-literals */ | ||
import { StyleSheet } from 'react-native'; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const createStyles = () => | ||
StyleSheet.create({ | ||
webview: { | ||
height: 0, | ||
// marginBottom: 50, | ||
// borderWidth: 1, | ||
// borderStyle: 'dashed', | ||
// borderColor: 'red', | ||
}, | ||
container: { | ||
// flex: 1, | ||
// borderWidth: 1, | ||
// borderStyle: 'dashed', | ||
// borderColor: 'green', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
import type { SupportedCurve } from '@metamask/key-tree'; | ||
|
||
export type SnapsDerivationPathType = ['m', ...string[]]; | ||
|
||
export interface SnapsDerivationPath { | ||
path: SnapsDerivationPathType; | ||
curve: SupportedCurve; | ||
name: string; | ||
} | ||
|
||
// Copy of extension mapping: https://github.com/MetaMask/metamask-extension/blob/49f8052b157374370ac71373708933c6e639944e/shared/constants/snaps.ts#L52 | ||
export const SNAPS_DERIVATION_PATHS: SnapsDerivationPath[] = [ | ||
{ | ||
path: ['m', `44'`, `0'`], | ||
curve: 'ed25519', | ||
name: 'Test BIP-32 Path (ed25519)', | ||
}, | ||
{ | ||
path: ['m', `44'`, `1'`], | ||
curve: 'secp256k1', | ||
name: 'Test BIP-32 Path (secp256k1)', | ||
}, | ||
{ | ||
path: ['m', `44'`, `0'`], | ||
curve: 'secp256k1', | ||
name: 'Bitcoin Legacy', | ||
}, | ||
{ | ||
path: ['m', `49'`, `0'`], | ||
curve: 'secp256k1', | ||
name: 'Bitcoin Nested SegWit', | ||
}, | ||
{ | ||
path: ['m', `49'`, `1'`], | ||
curve: 'secp256k1', | ||
name: 'Bitcoin Testnet Nested SegWit', | ||
}, | ||
{ | ||
path: ['m', `84'`, `0'`], | ||
curve: 'secp256k1', | ||
name: 'Bitcoin Native SegWit', | ||
}, | ||
{ | ||
path: ['m', `84'`, `1'`], | ||
curve: 'secp256k1', | ||
name: 'Bitcoin Testnet Native SegWit', | ||
}, | ||
{ | ||
path: ['m', `44'`, `501'`], | ||
curve: 'secp256k1', | ||
name: 'Solana', | ||
}, | ||
{ | ||
path: ['m', `44'`, `2'`], | ||
curve: 'secp256k1', | ||
name: 'Litecoin', | ||
}, | ||
{ | ||
path: ['m', `44'`, `3'`], | ||
curve: 'secp256k1', | ||
name: 'Dogecoin', | ||
}, | ||
{ | ||
path: ['m', `44'`, `60'`], | ||
curve: 'secp256k1', | ||
name: 'Ethereum', | ||
}, | ||
{ | ||
path: ['m', `44'`, `118'`], | ||
curve: 'secp256k1', | ||
name: 'Atom', | ||
}, | ||
{ | ||
path: ['m', `44'`, `145'`], | ||
curve: 'secp256k1', | ||
name: 'Bitcoin Cash', | ||
}, | ||
{ | ||
path: ['m', `44'`, `714'`], | ||
curve: 'secp256k1', | ||
name: 'Binance (BNB)', | ||
}, | ||
{ | ||
path: ['m', `44'`, `931'`], | ||
curve: 'secp256k1', | ||
name: 'THORChain (RUNE)', | ||
}, | ||
{ | ||
path: ['m', `44'`, `330'`], | ||
curve: 'secp256k1', | ||
name: 'Terra (LUNA)', | ||
}, | ||
{ | ||
path: ['m', `44'`, `459'`], | ||
curve: 'secp256k1', | ||
name: 'Kava', | ||
}, | ||
{ | ||
path: ['m', `44'`, `529'`], | ||
curve: 'secp256k1', | ||
name: 'Secret Network', | ||
}, | ||
{ | ||
path: ['m', `44'`, `397'`], | ||
curve: 'ed25519', | ||
name: 'NEAR Protocol', | ||
}, | ||
{ | ||
path: ['m', `44'`, `1'`, `0'`], | ||
curve: 'ed25519', | ||
name: 'NEAR Protocol Testnet', | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.