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

MetaMask Controller #6

Merged
merged 8 commits into from
Jul 25, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
__snapshots__
android
coverage
app/core
Copy link
Contributor Author

@brunobar79 brunobar79 Jul 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything I brought in from the extension is inside that folder. Ideally we would move it to an npm package (or use GABA)

ios
node_modules
package-lock.json
package.json
shim.js
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shim is autogenerated by the rn-nodeify which allows you to use node stuff in react native

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Can we get more specific with the file path? Won't this ignore any shim.js file anywhere in the repository?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call!

index.js
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one includes the shim and all that stuff, it's a pretty simple and basic file, so I don't really care about being here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above; can we get more specific with the file path so we don't ignore all index.js files, only this generated one?

Edit: Actually, should this file really be ignored? I didn't see a generated index.js but may've missed it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 change: 1 addition & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ android {
}

dependencies {
compile project(':react-native-randombytes')
compile project(':react-native-fs')
compile project(':react-native-vector-icons')
compile fileTree(dir: "libs", include: ["*.jar"])
Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/java/com/metamask/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Application;

import com.facebook.react.ReactApplication;
import com.bitgo.randombytes.RandomBytesPackage;
import com.rnfs.RNFSPackage;
import com.oblador.vectoricons.VectorIconsPackage;
import com.facebook.react.ReactNativeHost;
Expand All @@ -25,6 +26,7 @@ public boolean getUseDeveloperSupport() {
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RandomBytesPackage(),
new RNFSPackage(),
new VectorIconsPackage()
);
Expand Down
2 changes: 2 additions & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
rootProject.name = 'MetaMask'
include ':react-native-randombytes'
project(':react-native-randombytes').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-randombytes/android')
include ':react-native-fs'
project(':react-native-fs').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fs/android')
include ':react-native-vector-icons'
Expand Down
4 changes: 4 additions & 0 deletions app/components/App/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { createBottomTabNavigator } from 'react-navigation';
import BrowserScreen from '../BrowserScreen';
import WalletScreen from '../WalletScreen';

/**
* Root application component responsible for configuring the tab navigator
*/
export default createBottomTabNavigator({
Home: {
screen: BrowserScreen
},
Wallet: {
screen: WalletScreen
}
});
43 changes: 43 additions & 0 deletions app/components/Wallet/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React, { Component } from 'react';
import { StyleSheet, View, Text, ActivityIndicator } from 'react-native';
import initBackground from '../../core/scripts/background-react-native';
import { colors } from '../../styles/common';

const styles = StyleSheet.create({
wrapper: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: colors.slate
}
});

export default class Wallet extends Component {
state = {
rate: null
};

async componentDidMount() {
this.controller = await initBackground();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how I initialize the "background" process and the only thing it does is to initialize an instance of the MM controller (see https://github.com/bitpshr/MetaMask/pull/6/files#diff-cba5272be8f66ce2d8d371b4507dcd15R434)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, I just realized that we could potentially get rid of the background file and instantiate the MM controller directly

this.init();
}

init() {
// Example of how to interact with the MM controller
const API = this.controller.getApi();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below, this is just a minimal demo of how to access the MM controller

API.setCurrentCurrency('usd', (error, rate) => {
this.setState({ rate: rate.conversionRate });
});
}

renderRate() {
if (this.state.rate) {
return <Text>ETH RATE: ${this.state.rate}</Text>;
}
return <ActivityIndicator size="small" />;
}

render() {
return <View style={styles.wrapper}>{this.renderRate()}</View>;
}
}
10 changes: 10 additions & 0 deletions app/components/Wallet/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { shallow } from 'enzyme';
import Wallet from './';

describe('Wallet', () => {
it('should render correctly', () => {
const wrapper = shallow(<Wallet />);
expect(wrapper).toMatchSnapshot();
});
});
16 changes: 16 additions & 0 deletions app/components/WalletScreen/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, { Component } from 'react';
import Wallet from '../Wallet';
import Screen from '../Screen';

/**
* Main view component for the wallet screen
*/
export default class WalletScreen extends Component {
render() {
return (
<Screen>
<Wallet />
</Screen>
);
}
}
10 changes: 10 additions & 0 deletions app/components/WalletScreen/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { shallow } from 'enzyme';
import WalletScreen from './';

describe('WalletScreen', () => {
it('should render correctly', () => {
const wrapper = shallow(<WalletScreen />);
expect(wrapper).toMatchSnapshot();
});
});
Loading