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 { DrawerNavigator, SafeAreaView } from 'react-navigation';
import MainBottomTabs from './MainBottomTabs';
import Selftest from './screen/selftest';
require('./BlueApp');
@ -66,22 +67,10 @@ const TabsInDrawer = DrawerNavigator(
},
},
/* SecondaryBottomTabs: {
screen: SecondaryBottomTabs,
path: 'chat/aaa',
navigationOptions: {
drawer: () => ({
label: 'SecondaryBottomTabs',
icon: ({ tintColor }) => (
<MaterialIcons
name="filter-2"
size={24}
style={{ color: tintColor }}
/>
),
}),
Selftest: {
screen: Selftest,
navigationOptions: {},
},
}, */
},
{
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 {
constructor() {

2
class/constants.js

@ -2,4 +2,4 @@
* 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 './app-storage'
export * from './constants'
export * from './legacy-wallet'
export * from './segwit-bech-wallet'
export * from './segwit-p2sh-wallet'
export * from './abstract-wallet';
export * from './app-storage';
export * from './constants';
export * from './legacy-wallet';
export * from './segwit-bech-wallet';
export * from './segwit-p2sh-wallet';

14
class/legacy-wallet.js

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

4
class/segwit-bech-wallet.js

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

8
class/segwit-p2sh-wallet.js

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

4
package.json

@ -29,8 +29,8 @@
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"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",
"lint": "./node_modules/.bin/eslint *.js screen/**/*.js screen/ --fix",
"test": "npm run test-only && node node_modules/jest/bin/jest.js && npm run lint",
"lint": "./node_modules/.bin/eslint *.js screen/**/*.js screen/ class/ --fix",
"test-only": "./node_modules/.bin/mocha tests/**/*.js"
},
"jest": {

19
screen/selftest.js

@ -7,8 +7,10 @@ import {
SafeBlueArea,
BlueCard,
BlueText,
BlueButton,
BlueHeader,
} from '../BlueComponents';
import PropTypes from 'prop-types';
import { SegwitP2SHWallet, LegacyWallet } from '../class';
let BlueApp = require('../BlueApp');
let BigNumber = require('bignumber.js');
@ -38,7 +40,7 @@ export default class Selftest extends Component {
let uniqs = {};
let w = new SegwitP2SHWallet();
for (let c = 0; c < 10000; c++) {
for (let c = 0; c < 1000; c++) {
w.generate();
if (uniqs[w.getSecret()]) {
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>
</BlueCard>
</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,
} from '../../BlueComponents';
import PropTypes from 'prop-types';
const bip21 = require('bip21')
const bip21 = require('bip21');
let EV = require('../../events');
let BigNumber = require('bignumber.js');
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 {
static navigationOptions = {
@ -67,16 +67,16 @@ export default class SendDetails extends Component {
if (btcAddressRx.test(data)) {
this.setState({
address: data,
})
});
} else {
const { address, options } = bip21.decode(data)
const { address, options } = bip21.decode(data);
if (btcAddressRx.test(address)) {
this.setState({
address,
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) {
if (this.ignoreRead) return
this.ignoreRead = true
if (this.ignoreRead) return;
this.ignoreRead = true;
setTimeout(() => {
this.ignoreRead = false
}, 2000)
this.ignoreRead = false;
}, 2000);
this.props.navigation.goBack();
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 },
}}
/>
<BlueCard>
<ScrollView maxHeight={450}>
<BlueText h1>About</BlueText>
@ -97,6 +98,13 @@ export default class Settings extends Component {
<BlueText h4>
* Design by https://dribbble.com/chrometaphore
</BlueText>
<BlueButton
onPress={() => {
this.props.navigation.navigate('Selftest');
}}
title="Run self test"
/>
</ScrollView>
</BlueCard>
</SafeBlueArea>

Loading…
Cancel
Save