Skip to content

Commit

Permalink
Merge pull request #1664 from bithyve/dev
Browse files Browse the repository at this point in the history
build 103
  • Loading branch information
cakesoft-shashank authored Jan 4, 2023
2 parents c91c0a3 + 0e0cdb3 commit 4523f0a
Show file tree
Hide file tree
Showing 19 changed files with 311 additions and 249 deletions.
12 changes: 11 additions & 1 deletion App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Sentry from '@sentry/react-native';

import { LogBox, Platform, StatusBar, UIManager } from 'react-native';
import { LogBox, Platform, StatusBar, UIManager, BackHandler } from 'react-native';
import React, { useEffect } from 'react';

import { AppContextProvider } from 'src/common/content/AppContext';
Expand Down Expand Up @@ -32,8 +32,18 @@ if (Platform.OS === 'android') {
function App() {
useEffect(() => {
Sentry.init(sentryConfig);
const backHandler = BackHandler.addEventListener(
'hardwareBackPress',
handleBackPress
);

return () => backHandler.remove();
}, []);

const handleBackPress = () => {
// do nothing on back button press
return true;
}
// linear-gradient configs for NativeBase
const config = {
dependencies: {
Expand Down
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ android {
applicationId "io.hexawallet.keeper"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 102
versionCode 103
versionName "0.0.97"
missingDimensionStrategy 'react-native-camera', 'general'
missingDimensionStrategy 'store', 'play'
Expand Down
8 changes: 4 additions & 4 deletions ios/hexa_keeper.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = hexa_keeper/hexa_keeper.entitlements;
CURRENT_PROJECT_VERSION = 102;
CURRENT_PROJECT_VERSION = 103;
DEVELOPMENT_TEAM = Y5TCB759QL;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = hexa_keeper/Info.plist;
Expand Down Expand Up @@ -740,7 +740,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = hexa_keeper/hexa_keeper.entitlements;
CURRENT_PROJECT_VERSION = 102;
CURRENT_PROJECT_VERSION = 103;
DEVELOPMENT_TEAM = Y5TCB759QL;
INFOPLIST_FILE = hexa_keeper/Info.plist;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.finance";
Expand Down Expand Up @@ -892,7 +892,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = "dev-AppIcon";
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = hexa_keeper_dev.entitlements;
CURRENT_PROJECT_VERSION = 100;
CURRENT_PROJECT_VERSION = 103;
DEVELOPMENT_TEAM = Y5TCB759QL;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = "hexa_keeper_dev-Info.plist";
Expand Down Expand Up @@ -923,7 +923,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = "dev-AppIcon";
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = hexa_keeper_dev.entitlements;
CURRENT_PROJECT_VERSION = 100;
CURRENT_PROJECT_VERSION = 103;
DEVELOPMENT_TEAM = Y5TCB759QL;
INFOPLIST_FILE = "hexa_keeper_dev-Info.plist";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.finance";
Expand Down
27 changes: 16 additions & 11 deletions src/common/constants/Bitcoin.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import config from 'src/core/config'
import { NetworkType } from 'src/core/wallets/enums'
import config from 'src/core/config';
import { NetworkType } from 'src/core/wallets/enums';

export const SATOSHIS_IN_BTC = 1e8
export const SATOSHIS_IN_BTC = 1e8;

export const getAmount = (amountInSats: number) => {
if (config.NETWORK_TYPE === NetworkType.MAINNET) {
return (amountInSats / SATOSHIS_IN_BTC).toFixed(4);
}
return amountInSats;

}
}
return amountInSats;
};
export const getUnit = () => {
if (config.NETWORK_TYPE === NetworkType.MAINNET) {
return '';
}
return 'sats';

}
}
return 'sats';
};

export const isTestnet = () => {
if (config.NETWORK_TYPE === NetworkType.TESTNET) {
return true;
}
return false;
};
35 changes: 35 additions & 0 deletions src/components/TestnetIndicator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import { Box } from 'native-base';

import Text from 'src/components/KeeperText';
import { StyleSheet } from 'react-native';

function TestnetIndicator() {
return (
<Box
backgroundColor={'light.white'}
style={styles.container}
>
<Text
color="light.primaryGreen"
bold
style={styles.text}>
TESTNET
</Text>
</Box>
);
}

const styles = StyleSheet.create({
container: {
borderRadius: 99,
paddingHorizontal: 8,
height: 20
},
text: {
fontSize: 12,
letterSpacing: 0.9
}
})

export default TestnetIndicator;
12 changes: 6 additions & 6 deletions src/components/ToastMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ function HexaToastMessages({
title,
Image,
error,
width
width,
}: {
title: string;
width: number | string;
Image?: any;
error?: boolean;
width?: number | string
}) {
return (
<Box backgroundColor={error ? 'error.500' : 'light.accent'}
style={styles.toast}>
<Box backgroundColor={error ? 'error.500' : 'light.accent'} style={styles.toast}>
{Image && <Box>{Image}</Box>}
<Text marginLeft={Image ? 3 : 0} color={error ? 'error.200' : null}
style={{ width: width }}
<Text
color={error ? 'error.200' : null}
style={{ marginLeft: Image ? 3 : 0, width }}
numberOfLines={2}
>
{title}
Expand Down
111 changes: 52 additions & 59 deletions src/core/services/electrum/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
/* eslint-disable no-console */

import config from 'src/core/config';
import { NetworkType } from 'src/core/wallets/enums';
import ElectrumCli from 'electrum-client';
import reverse from 'buffer-reverse';
import * as bitcoinJS from 'bitcoinjs-lib';
import { ElectrumTransaction, ElectrumUTXO } from './interface';
import { NodeDetail } from 'src/core/wallets/interfaces';
import { isTestnet } from 'src/common/constants/Bitcoin';
import { ElectrumTransaction, ElectrumUTXO } from './interface';

const ELECTRUM_CLIENT_CONFIG = {
predefinedTestnetPeers: [{ host: '35.177.46.45', ssl: '50002' }],
Expand All @@ -24,14 +24,13 @@ const ELECTRUM_CLIENT = {
isClientConnected: false,
currentPeerIndex: Math.floor(Math.random() * ELECTRUM_CLIENT_CONFIG.predefinedPeers.length),
connectionAttempt: 0,
activePeer: null
activePeer: null,
};

export default class ElectrumClient {
public static async connect() {
try {
if(!ELECTRUM_CLIENT.activePeer)
{
if (!ELECTRUM_CLIENT.activePeer) {
console.log('No active peer is available');
return;
}
Expand Down Expand Up @@ -60,15 +59,15 @@ export default class ElectrumClient {
});
console.log('Connection to electrum server is established', { ver });
if (ver && ver[0]) {
ELECTRUM_CLIENT.isClientConnected = true;
ELECTRUM_CLIENT.isClientConnected = true;
}
} catch (error) {
ELECTRUM_CLIENT.isClientConnected = false;
console.log('Bad connection:', JSON.stringify(ELECTRUM_CLIENT.activePeer), error);
}

if (ELECTRUM_CLIENT.isClientConnected) return ELECTRUM_CLIENT.isClientConnected;
return await ElectrumClient.reconnect();
return await ElectrumClient.reconnect();
}

public static async reconnect() {
Expand All @@ -89,23 +88,20 @@ export default class ElectrumClient {
return await ElectrumClient.connect();
}

public static getActivePrivateNodeToUse (peers : NodeDetail[]) {
public static getActivePrivateNodeToUse(peers: NodeDetail[]) {
const node = peers?.filter((node) => node.isConnected)[0];
let peer = null;
let useKeeperNode = false;

if(node)
{
if (node) {
useKeeperNode = node?.useKeeperNode || false;
if(node.useSSL)
peer = { host : node.host, ssl: node.port, tcp: null};
else
peer = { host : node.host, tcp: node.port, ssl: null};
if (node.useSSL) peer = { host: node.host, ssl: node.port, tcp: null };
else peer = { host: node.host, tcp: node.port, ssl: null };
}
return {peer, useKeeperNode};
return { peer, useKeeperNode };
}

public static async ping () {
public static async ping() {
try {
await ELECTRUM_CLIENT.electrumClient?.server_ping();
} catch (_) {
Expand All @@ -114,27 +110,26 @@ export default class ElectrumClient {
return true;
}

public static getActivePeer () {
public static getActivePeer() {
return ELECTRUM_CLIENT.activePeer;
}

// if current peer to use is not provided, it will try to get the active peer from the saved list of private nodes
// if saved private node is not available, and use keeper node is true, it will use the keeper node
// if current peer to use is provided, it will use that peer
public static setActivePeer (savedPrivateNodes: NodeDetail[], currentPeerToUse = null) {
const {peer: privatePeer, useKeeperNode} = ElectrumClient.getActivePrivateNodeToUse(currentPeerToUse != null ? [currentPeerToUse] : savedPrivateNodes);
public static setActivePeer(savedPrivateNodes: NodeDetail[], currentPeerToUse = null) {
const { peer: privatePeer, useKeeperNode } = ElectrumClient.getActivePrivateNodeToUse(
currentPeerToUse != null ? [currentPeerToUse] : savedPrivateNodes
);
let peer = null;
if(privatePeer != null)
{
if (privatePeer != null) {
peer = privatePeer;
if(ElectrumClient.testConnection(peer?.host, peer?.tcp, peer?.ssl))
{
if (ElectrumClient.testConnection(peer?.host, peer?.tcp, peer?.ssl)) {
ELECTRUM_CLIENT.activePeer = peer;
return;
}

if(useKeeperNode)
{
if (useKeeperNode) {
peer = ElectrumClient.getNextPeer();
ELECTRUM_CLIENT.activePeer = peer;
return;
Expand All @@ -148,18 +143,16 @@ export default class ElectrumClient {
}

public static getPredefinedCurrentPeer() {
const isTestnet = config.NETWORK_TYPE === NetworkType.TESTNET;
return isTestnet
return isTestnet()
? ELECTRUM_CLIENT_CONFIG.predefinedTestnetPeers[ELECTRUM_CLIENT.currentPeerIndex]
: ELECTRUM_CLIENT_CONFIG.predefinedPeers[ELECTRUM_CLIENT.currentPeerIndex];
}

public static getNextPeer() {
const isTestnet = config.NETWORK_TYPE === NetworkType.TESTNET;
ELECTRUM_CLIENT.currentPeerIndex += 1;
if (
ELECTRUM_CLIENT.currentPeerIndex >
(isTestnet
(isTestnet()
? ELECTRUM_CLIENT_CONFIG.predefinedTestnetPeers.length - 1
: ELECTRUM_CLIENT_CONFIG.predefinedPeers.length - 1)
)
Expand Down Expand Up @@ -327,35 +320,35 @@ export default class ElectrumClient {
}

public static async testConnection(host, tcpPort, sslPort) {
console.log('testConnection', host, tcpPort, sslPort)
const client = new ElectrumCli(
global.net,
global.tls,
sslPort || tcpPort,
host,
sslPort ? 'tls' : 'tcp',
);
client.onError = () => {}; // mute
let timeoutId = null;
try {
const rez = await Promise.race([
new Promise(resolve => {
timeoutId = setTimeout(() => resolve('timeout'), 5000);
}),
client.connect(),
]);
if (rez === 'timeout') return false;
await client.server_version('2.7.11', '1.4');
await client.server_ping();
return true;
} catch (_) {
} finally {
if (timeoutId) clearTimeout(timeoutId);
client.close();
}
return false;
console.log('testConnection', host, tcpPort, sslPort);
const client = new ElectrumCli(
global.net,
global.tls,
sslPort || tcpPort,
host,
sslPort ? 'tls' : 'tcp'
);

client.onError = () => {}; // mute
let timeoutId = null;
try {
const rez = await Promise.race([
new Promise((resolve) => {
timeoutId = setTimeout(() => resolve('timeout'), 5000);
}),
client.connect(),
]);
if (rez === 'timeout') return false;

await client.server_version('2.7.11', '1.4');
await client.server_ping();
return true;
} catch (_) {
} finally {
if (timeoutId) clearTimeout(timeoutId);
client.close();
}

return false;
}
}
2 changes: 1 addition & 1 deletion src/hooks/useToastMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useToast } from 'native-base';
const useToastMessage = () => {
const Toast = useToast();

function showToast(title, image?, duration = 1000, error = false) {
function showToast(title, image?, duration = 1000, error = false, width = '100%') {
Toast.show({
render: () => <HexaToastMessages title={title} Image={image} error={error} width={width} />,
duration,
Expand Down
Loading

0 comments on commit 4523f0a

Please sign in to comment.