Browse Source

refactoring

localNotifications
Overtorment 7 years ago
parent
commit
8afa275306
  1. 19
      App.js
  2. 137
      SecondaryBottomTabs.js
  3. 3
      class/app-storage.js
  4. 2
      class/constants.js
  5. 12
      class/index.js
  6. 14
      class/legacy-wallet.js
  7. 4
      class/segwit-bech-wallet.js
  8. 8
      class/segwit-p2sh-wallet.js
  9. 4
      package.json
  10. 19
      screen/selftest.js
  11. 12
      screen/send/details.js
  12. 8
      screen/send/scanQrAddress.js
  13. 8
      screen/settings.js

19
App.js

@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import { Text, ScrollView, StyleSheet } from 'react-native'; import { Text, ScrollView, StyleSheet } from 'react-native';
import { DrawerNavigator, SafeAreaView } from 'react-navigation'; import { DrawerNavigator, SafeAreaView } from 'react-navigation';
import MainBottomTabs from './MainBottomTabs'; import MainBottomTabs from './MainBottomTabs';
import Selftest from './screen/selftest';
require('./BlueApp'); require('./BlueApp');
@ -66,22 +67,10 @@ const TabsInDrawer = DrawerNavigator(
}, },
}, },
/* SecondaryBottomTabs: { Selftest: {
screen: SecondaryBottomTabs, screen: Selftest,
path: 'chat/aaa', navigationOptions: {},
navigationOptions: {
drawer: () => ({
label: 'SecondaryBottomTabs',
icon: ({ tintColor }) => (
<MaterialIcons
name="filter-2"
size={24}
style={{ color: tintColor }}
/>
),
}),
}, },
}, */
}, },
{ {
contentComponent: CustomDrawerContentComponent, contentComponent: CustomDrawerContentComponent,

137
SecondaryBottomTabs.js

@ -1,137 +0,0 @@
/**
* @flow
*/
import React from 'react';
import { Button, ScrollView } from 'react-native';
import { SafeAreaView, StackNavigator, TabNavigator } from 'react-navigation';
import PropTypes from 'prop-types';
import Ionicons from 'react-native-vector-icons/Ionicons';
const MyNavScreen = ({ navigation, banner }) => (
<ScrollView>
<SafeAreaView forceInset={{ horizontal: 'always' }}>
<Button
onPress={() => navigation.navigate('Profile', { name: 'Jordan' })}
title="Open profile screen"
/>
<Button
onPress={() => navigation.navigate('NotifSettings')}
title="Open notifications screen"
/>
<Button
onPress={() => navigation.navigate('SettingsTab')}
title="Go to settings tab"
/>
<Button onPress={() => navigation.goBack(null)} title="Go back" />
</SafeAreaView>
</ScrollView>
);
MyNavScreen.propTypes = {
banner: PropTypes.string,
navigation: PropTypes.shape({
navigate: PropTypes.func,
}),
};
const MyHomeScreen = ({ navigation }) => (
<MyNavScreen banner="Home Screen" navigation={navigation} />
);
MyHomeScreen.propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func,
}),
};
const MyNotificationsSettingsScreen = ({ navigation }) => (
<MyNavScreen banner="Notifications Screen" navigation={navigation} />
);
MyNotificationsSettingsScreen.propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func,
}),
};
const MySettingsScreen = ({ navigation }) => (
<MyNavScreen banner="Settings Screen" navigation={navigation} />
);
MySettingsScreen.propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func,
}),
};
var bitcoin = require('bitcoinjs-lib');
var myString = bitcoin.ECPair.makeRandom().toWIF();
const tabBarIconMainTab = ({ tintColor, focused }) => (
<Ionicons
name={focused ? 'ios-home' : 'ios-home-outline'}
size={26}
style={{ color: tintColor }}
/>
);
tabBarIconMainTab.propTypes = {
tintColor: PropTypes.string,
focused: PropTypes.boolean,
};
const tabBarIconSettingsTab = ({ tintColor, focused }) => (
<Ionicons
name={focused ? 'ios-settings' : 'ios-settings-outline'}
size={26}
style={{ color: tintColor }}
/>
);
tabBarIconSettingsTab.propTypes = {
tintColor: PropTypes.string,
focused: PropTypes.boolean,
};
const TabNav = TabNavigator(
{
MainTab: {
screen: MyHomeScreen,
path: '/',
navigationOptions: {
title: 'Welcome1 ' + myString,
tabBarLabel: 'Transactions',
tabBarIcon: tabBarIconMainTab,
},
},
SettingsTab: {
screen: MySettingsScreen,
path: '/settings',
navigationOptions: {
title: 'Settings',
tabBarIcon: tabBarIconSettingsTab,
},
},
},
{
tabBarPosition: 'bottom',
animationEnabled: false,
swipeEnabled: false,
},
);
const SecondaryBottomTabs = StackNavigator({
Root: {
screen: TabNav,
},
NotifSettings: {
screen: MyNotificationsSettingsScreen,
navigationOptions: {
title: 'Notifications',
},
},
});
export default SecondaryBottomTabs;

3
class/app-storage.js

@ -1,4 +1,5 @@
import { AsyncStorage } from 'react-native' import { AsyncStorage } from 'react-native';
import { LegacyWallet, SegwitP2SHWallet, SegwitBech32Wallet } from './';
export class AppStorage { export class AppStorage {
constructor() { constructor() {

2
class/constants.js

@ -2,4 +2,4 @@
* Let's keep config vars, constants and definitions here * Let's keep config vars, constants and definitions here
*/ */
export const useBlockcypherTokens = false export const useBlockcypherTokens = false;

12
class/index.js

@ -1,6 +1,6 @@
export * from './abstract-wallet' export * from './abstract-wallet';
export * from './app-storage' export * from './app-storage';
export * from './constants' export * from './constants';
export * from './legacy-wallet' export * from './legacy-wallet';
export * from './segwit-bech-wallet' export * from './segwit-bech-wallet';
export * from './segwit-p2sh-wallet' export * from './segwit-p2sh-wallet';

14
class/legacy-wallet.js

@ -1,9 +1,10 @@
import { AbstractWallet } from './abstract-wallet' /* global fetch */
import { useBlockcypherTokens } from './constants' import { AbstractWallet } from './abstract-wallet';
import Frisbee from 'frisbee' import { useBlockcypherTokens } from './constants';
const isaac = require('isaac') import Frisbee from 'frisbee';
const BigNumber = require('bignumber.js') const isaac = require('isaac');
const bitcoin = require('bitcoinjs-lib') const BigNumber = require('bignumber.js');
const bitcoin = require('bitcoinjs-lib');
/** /**
* Has private key and address signle like "1ABCD....." * Has private key and address signle like "1ABCD....."
@ -256,6 +257,5 @@ export class LegacyWallet extends AbstractWallet {
let res = await api.get('/broadcast/' + txhex); let res = await api.get('/broadcast/' + txhex);
console.log('response', res.body); console.log('response', res.body);
return res.body; return res.body;
} }
} }

4
class/segwit-bech-wallet.js

@ -1,5 +1,5 @@
import { LegacyWallet } from './legacy-wallet' import { LegacyWallet } from './legacy-wallet';
const bitcoin = require('bitcoinjs-lib') const bitcoin = require('bitcoinjs-lib');
export class SegwitBech32Wallet extends LegacyWallet { export class SegwitBech32Wallet extends LegacyWallet {
constructor() { constructor() {

8
class/segwit-p2sh-wallet.js

@ -1,7 +1,7 @@
import { LegacyWallet } from './legacy-wallet' import { LegacyWallet } from './legacy-wallet';
const bitcoin = require('bitcoinjs-lib') const bitcoin = require('bitcoinjs-lib');
const signer = require('../models/signer') const signer = require('../models/signer');
const BigNumber = require('bignumber.js') const BigNumber = require('bignumber.js');
export class SegwitP2SHWallet extends LegacyWallet { export class SegwitP2SHWallet extends LegacyWallet {
constructor() { constructor() {

4
package.json

@ -29,8 +29,8 @@
"android": "react-native-scripts android", "android": "react-native-scripts android",
"ios": "react-native-scripts ios", "ios": "react-native-scripts ios",
"postinstall": "./node_modules/.bin/rn-nodeify --install buffer,events,process,stream,util,inherits,fs,path --hack", "postinstall": "./node_modules/.bin/rn-nodeify --install buffer,events,process,stream,util,inherits,fs,path --hack",
"test": "nodejs ./node_modules/.bin/mocha tests/* && node node_modules/jest/bin/jest.js && npm run lint", "test": "npm run test-only && node node_modules/jest/bin/jest.js && npm run lint",
"lint": "./node_modules/.bin/eslint *.js screen/**/*.js screen/ --fix", "lint": "./node_modules/.bin/eslint *.js screen/**/*.js screen/ class/ --fix",
"test-only": "./node_modules/.bin/mocha tests/**/*.js" "test-only": "./node_modules/.bin/mocha tests/**/*.js"
}, },
"jest": { "jest": {

19
screen/selftest.js

@ -7,8 +7,10 @@ import {
SafeBlueArea, SafeBlueArea,
BlueCard, BlueCard,
BlueText, BlueText,
BlueButton,
BlueHeader, BlueHeader,
} from '../BlueComponents'; } from '../BlueComponents';
import PropTypes from 'prop-types';
import { SegwitP2SHWallet, LegacyWallet } from '../class'; import { SegwitP2SHWallet, LegacyWallet } from '../class';
let BlueApp = require('../BlueApp'); let BlueApp = require('../BlueApp');
let BigNumber = require('bignumber.js'); let BigNumber = require('bignumber.js');
@ -38,7 +40,7 @@ export default class Selftest extends Component {
let uniqs = {}; let uniqs = {};
let w = new SegwitP2SHWallet(); let w = new SegwitP2SHWallet();
for (let c = 0; c < 10000; c++) { for (let c = 0; c < 1000; c++) {
w.generate(); w.generate();
if (uniqs[w.getSecret()]) { if (uniqs[w.getSecret()]) {
errorMessage += 'failed to generate unique private key; '; errorMessage += 'failed to generate unique private key; ';
@ -161,6 +163,14 @@ export default class Selftest extends Component {
); );
} }
})()} })()}
<BlueButton
icon={{ name: 'arrow-left', type: 'octicon' }}
title="Go Back"
onPress={() => {
this.props.navigation.goBack();
}}
/>
</ScrollView> </ScrollView>
</BlueCard> </BlueCard>
</SafeBlueArea> </SafeBlueArea>
@ -168,4 +178,9 @@ export default class Selftest extends Component {
} }
} }
Selftest.propTypes = {}; Selftest.propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func,
goBack: PropTypes.func,
}),
};

12
screen/send/details.js

@ -12,12 +12,12 @@ import {
BlueSpacing, BlueSpacing,
} from '../../BlueComponents'; } from '../../BlueComponents';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
const bip21 = require('bip21') const bip21 = require('bip21');
let EV = require('../../events'); let EV = require('../../events');
let BigNumber = require('bignumber.js'); let BigNumber = require('bignumber.js');
let BlueApp = require('../../BlueApp'); let BlueApp = require('../../BlueApp');
const btcAddressRx = /^[a-zA-Z0-9]{26,35}$/ const btcAddressRx = /^[a-zA-Z0-9]{26,35}$/;
export default class SendDetails extends Component { export default class SendDetails extends Component {
static navigationOptions = { static navigationOptions = {
@ -67,16 +67,16 @@ export default class SendDetails extends Component {
if (btcAddressRx.test(data)) { if (btcAddressRx.test(data)) {
this.setState({ this.setState({
address: data, address: data,
}) });
} else { } else {
const { address, options } = bip21.decode(data) const { address, options } = bip21.decode(data);
if (btcAddressRx.test(address)) { if (btcAddressRx.test(address)) {
this.setState({ this.setState({
address, address,
amount: options.amount, amount: options.amount,
memo: options.label memo: options.label,
}) });
} }
} }
}); });

8
screen/send/scanQrAddress.js

@ -19,11 +19,11 @@ export default class CameraExample extends React.Component {
}; };
async onBarCodeRead(ret) { async onBarCodeRead(ret) {
if (this.ignoreRead) return if (this.ignoreRead) return;
this.ignoreRead = true this.ignoreRead = true;
setTimeout(() => { setTimeout(() => {
this.ignoreRead = false this.ignoreRead = false;
}, 2000) }, 2000);
this.props.navigation.goBack(); this.props.navigation.goBack();
EV(EV.enum.CREATE_TRANSACTION_NEW_DESTINATION_ADDRESS, ret.data); EV(EV.enum.CREATE_TRANSACTION_NEW_DESTINATION_ADDRESS, ret.data);

8
screen/settings.js

@ -60,6 +60,7 @@ export default class Settings extends Component {
style: { color: '#fff', fontSize: 25 }, style: { color: '#fff', fontSize: 25 },
}} }}
/> />
<BlueCard> <BlueCard>
<ScrollView maxHeight={450}> <ScrollView maxHeight={450}>
<BlueText h1>About</BlueText> <BlueText h1>About</BlueText>
@ -97,6 +98,13 @@ export default class Settings extends Component {
<BlueText h4> <BlueText h4>
* Design by https://dribbble.com/chrometaphore * Design by https://dribbble.com/chrometaphore
</BlueText> </BlueText>
<BlueButton
onPress={() => {
this.props.navigation.navigate('Selftest');
}}
title="Run self test"
/>
</ScrollView> </ScrollView>
</BlueCard> </BlueCard>
</SafeBlueArea> </SafeBlueArea>

Loading…
Cancel
Save