Skip to content

Commit

Permalink
Electron
Browse files Browse the repository at this point in the history
  • Loading branch information
hsjoberg authored Jan 28, 2023
1 parent a34be99 commit 026fd02
Show file tree
Hide file tree
Showing 34 changed files with 2,716 additions and 1,218 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ macos/Lndmobile.xcframework

# Web
dist
.webpack

# service-image
contrib/service-image/webp
Expand Down
21 changes: 2 additions & 19 deletions index.web.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'setimmediate'

import { AppRegistry, LogBox, Platform, UIManager } from "react-native";
import 'setimmediate';
import { AppRegistry } from "react-native";
import App from "./src/App";
import AppConfig from "./app.json";
import Long from "long";
Expand All @@ -11,22 +10,6 @@ protobuf.util.Long = Long;
protobuf.configure();
enableES5();

// YellowBox.ignoreWarnings([
// // Workaround until native-base fixes their old
// "Warning: component",
// // We are putting functions in navigation route props
// "Non-serializable values were found in the navigation state",
// // Native-base doesn't have useNativeDriver for every animation
// "Animated: `useNativeDriver` was not specified"
// ]);

if (
Platform.OS === "android" &&
UIManager.setLayoutAnimationEnabledExperimental
) {
UIManager.setLayoutAnimationEnabledExperimental(true);
}

AppRegistry.registerComponent(AppConfig.name, () => App);

AppRegistry.runApplication(AppConfig.name, {
Expand Down
24 changes: 20 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "BlixtWallet",
"version": "0.0.1",
"version": "0.6.0",
"private": true,
"main": ".webpack/main",
"scripts": {
"start": "react-native run-android --variant chaintestnetNormalDebug --appIdSuffix testnet.debug",
"start-metro": "NODE_OPTIONS=--openssl-legacy-provider react-native start",
Expand Down Expand Up @@ -42,11 +43,16 @@
"macos:mainnet": "react-native-macos run-macos --scheme BlixtWallet --configuration Release",
"macos:mainnet-fakelnd-debug": "react-native-macos run-macos --scheme BlixtWalletFakelnd --configuration DebugFakelnd",
"macos:mainnet-fakelnd": "react-native-macos run-macos --scheme BlixtWalletFakelnd --configuration ReleaseFakelnd",
"web": "webpack serve",
"web:bundle": "rm -r dist || true && NODE_ENV=production webpack"
"web": "CHAIN=mainnet FLAVOR=fakelnd APPLICATION_ID=com.blixtwallet.webdemo webpack serve --config ./web/webpack.config.js",
"web:bundle": "rm -r web/dist || true && NODE_ENV=production CHAIN=mainnet FLAVOR=fakelnd APPLICATION_ID=com.blixtwallet.webdemo webpack --config ./web/webpack.config.js",
"electron:start": "CHAIN=mainnet FLAVOR=fakelnd APPLICATION_ID=com.blixtwallet.debug electron-forge start",
"electron:make": "NODE_ENV=production CHAIN=mainnet FLAVOR=fakelnd APPLICATION_ID=com.blixtwallet.webdemo electron-forge make",
"electron:package": "NODE_ENV=production CHAIN=mainnet FLAVOR=fakelnd APPLICATION_ID=com.blixtwallet.webdemo electron-forge package"
},
"dependencies": {
"@babel/core": "^7.20.12",
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
"@babel/preset-react": "^7.16.7",
"@babel/preset-typescript": "^7.18.6",
"@babel/runtime": "^7.20.13",
"@react-native-community/async-storage": "1.12.1",
Expand Down Expand Up @@ -85,6 +91,7 @@
"long": "^5.2.1",
"metro-react-native-babel-preset": "^0.74.1",
"native-base": "git+https://github.com/hsjoberg/NativeBase.git#55959e0b5cc36b539da85cb25c24463899de0dc6",
"node-abi": "^3.31.0",
"node-polyfill-webpack-plugin": "^2.0.1",
"protobufjs": "git+https://github.com/AndiDog/protobuf.js.git#fa4999b5d5de16a7484ee503eafddde23c06492b",
"react": "^18.2.0",
Expand All @@ -99,6 +106,7 @@
"react-native-dialogs": "1.1.1",
"react-native-document-picker": "^8.1.3",
"react-native-easy-grid": "0.2.2",
"react-native-electron": "^0.18.0",
"react-native-enhanced-popup-menu": "^0.7.0",
"react-native-fingerprint-scanner": "git+https://github.com/hsjoberg/react-native-fingerprint-scanner.git#b568a440472a04ae8ec2c409c53ce80cbcb9bf00",
"react-native-fs": "^2.19.0",
Expand Down Expand Up @@ -152,7 +160,10 @@
"webpack-dev-server": "^4.10.1"
},
"devDependencies": {
"@testing-library/react-native": "^11.5.0",
"@electron-forge/cli": "^6.0.4",
"@electron-forge/maker-zip": "^6.0.4",
"@electron-forge/plugin-webpack": "^6.0.4",
"@testing-library/react-native": "11.5.0",
"@types/aes-js": "^3.1.1",
"@types/base64-js": "1.3.0",
"@types/bech32": "^1.1.4",
Expand All @@ -172,13 +183,18 @@
"@types/sql.js": "^1.4.4",
"babel-jest": "^29.4.1",
"bolt11": "^1.4.0",
"electron": "^22.1.0",
"jest": "^29.4.1",
"jest-date-mock": "1.0.8",
"jest-fetch-mock": "3.0.3",
"node-loader": "^2.0.0",
"react-test-renderer": "^18.2.0",
"tslint": "6.1.3",
"tslint-config-airbnb": "^5.11.2",
"tslint-react": "5.0.0",
"tslint-react-native": "0.0.7"
},
"config": {
"forge": "./web/electron/forge.config.js"
}
}
4 changes: 4 additions & 0 deletions src/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Container from "./components/Container";
import useStackNavigationOptions from "./hooks/useStackNavigationOptions";
import { navigator } from "./utils/navigation";
import { PLATFORM } from "./utils/constants";
import Prompt, { IPromptNavigationProps } from "./windows/HelperWindows/Prompt";

const RootStack = createStackNavigator();

Expand Down Expand Up @@ -67,6 +68,8 @@ export type RootStackParamList = {
} | undefined;
WebInfo: undefined;

Prompt: IPromptNavigationProps;

DEV_CommandsX: undefined;
}

Expand Down Expand Up @@ -234,6 +237,7 @@ export default function Main() {
<RootStack.Screen name="GoogleDriveTestbed" component={GoogleDriveTestbed} options={animationDisabled} />
<RootStack.Screen name="KeysendTest" component={KeysendTest} options={animationDisabled} />
<RootStack.Screen name="KeysendExperiment" component={KeysendExperiment} options={horizontalTransition} />
<RootStack.Screen name="Prompt" component={Prompt} options={animationDisabled} />
<RootStack.Screen name="DEV_CommandsX" component={DEV_Commands} options={animationDisabled} />
</RootStack.Navigator>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ const style = StyleSheet.create({
flexDirection: "row",
alignItems: "center",
backgroundColor: blixtTheme.gray,
paddingVertical: 10,
paddingVertical: 9,
paddingHorizontal: 13,
marginLeft: 18,
marginRight: PLATFORM !== "macos" ? 18 : 4,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { Input } from "native-base";
import { Input, NativeBase } from "native-base";

export default function BlixtInput(props: any) {
export default function BlixtInput(props: NativeBase.Input) {
return (
<Input
enableFocusRing={false} // macOS prop
Expand Down
2 changes: 1 addition & 1 deletion src/native-base-theme/components/ListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export default (variables /* : * */ = variable) => {
fontSize: variables.iconFontSize - 2
},
paddingRight: variables.listItemPadding + 5,
flex: 0,
flex: platform === "web" ? "none" : 0,
// height: 44,
minHeight: 44,
justifyContent: 'center',
Expand Down
28 changes: 25 additions & 3 deletions src/utils/alert.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// https://github.com/necolas/react-native-web/issues/1026#issuecomment-687572134
import { AlertButton, AlertStatic, AlertType, Alert as RealAlert } from "react-native";
import { AlertButton, AlertStatic, AlertType, Alert as RealAlert, Platform } from "react-native";
import DialogAndroid from "react-native-dialogs";
import { PLATFORM } from "./constants";
import { navigate } from "./navigation";
import { IPromptNavigationProps } from "../windows/HelperWindows/Prompt";

class WebAlert implements AlertStatic {
public alert(title: string, message?: string, buttons?: AlertButton[]): void {
Expand Down Expand Up @@ -50,13 +52,34 @@ class WebAlert implements AlertStatic {
defaultValue?: string,
keyboardType?: string,
) {
if (PLATFORM === "web") {
if (Platform.isElectron) {
navigate<IPromptNavigationProps>("Prompt", {
title,
message,
defaultValue,
onOk: (result) => {
if (typeof callbackOrButtons === "object") {
const ok = callbackOrButtons.find(({ style }) => style !== "cancel");
ok?.onPress?.(result);
} else {
callbackOrButtons?.(result);
}
},
onCancel: () => {
if (typeof callbackOrButtons === "object") {
const cancel = callbackOrButtons.find(({ style }) => style === "cancel");
cancel?.onPress?.();
}
}
});
} else if (PLATFORM === "web") {
const result = window.prompt(message, defaultValue);
if (result === null) {
if (typeof callbackOrButtons === "object") {
const cancel = callbackOrButtons.find(({ style }) => style === "cancel");
cancel?.onPress?.();
}
// TODO callbackOrOptions?
} else {
if (typeof callbackOrButtons === "object") {
const ok = callbackOrButtons.find(({ style }) => style !== "cancel");
Expand All @@ -65,7 +88,6 @@ class WebAlert implements AlertStatic {
callbackOrButtons?.(result);
}
}

} else if (PLATFORM === "android") {
const positiveText = typeof callbackOrButtons === "object" ? callbackOrButtons.find(
(button) => button.style === "default"
Expand Down
128 changes: 128 additions & 0 deletions src/windows/HelperWindows/Prompt.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import React, { useLayoutEffect, useState } from "react";
import { Button, Card, CardItem, Header, Icon, Item, ListItem, Text } from "native-base";
import Container from "../../components/Container";
import { AlertButton, FlatList, StyleSheet, View } from "react-native";
import { blixtTheme } from "../../native-base-theme/variables/commonColor";
import { StackNavigationProp } from "@react-navigation/stack";
import { RouteProp } from "@react-navigation/native";
import Input from "../../components/Input";
import BlurModal from "../../components/BlurModal";
import style2 from "../LNURL/PayRequest/style";

export interface IPromptNavigationProps {
title: string;
message?: string;
defaultValue?: string;
callbackOrButtons?: ((text: string) => void) | AlertButton[];
onOk: (input: string) => void;
onCancel: () => void;
}

type IFakeStack = {
Prompt: IPromptNavigationProps;
}

export interface ISelectListProps {
navigation: StackNavigationProp<IFakeStack, "Prompt">;
route: RouteProp<IFakeStack, "Prompt">;
}

export default function({ navigation, route }: ISelectListProps) {
const { title, message, onOk, onCancel, defaultValue } = route.params;
const [inputText, setInputText] = useState(defaultValue ?? "");

function onPressOk() {
onOk(inputText);
navigation.pop();
}

function onPressCancel() {
onCancel();
navigation.pop();
}

return (
<BlurModal goBackByClickingOutside={false}>
<Card>
<CardItem>
<View style={style.container}>
<Text style={style.title}>{title}</Text>
<Text style={style.message}>{message}</Text>
<View style={style.inputContainer}>
<Input
style={style2.input}
value={inputText}
onChangeText={setInputText}
onKeyPress={(event) => {
if (["Enter", "\u2028"].includes(event.nativeEvent.key)) {
onPressOk();
}
}}
autoFocus
/>
</View>
<View style={style.buttons}>
<Button
small
success
style={style.button}
onPress={onPressOk}
>
<Text>Okay</Text>
</Button>
<Button
small
style={style.button}
onPress={onPressCancel}
>
<Text>Cancel</Text>
</Button>
</View>
</View>
</CardItem>
</Card>
</BlurModal>
)
}

const style = StyleSheet.create({
container: {
flex: 1,
flexDirection: "column",
},
title: {
fontFamily: blixtTheme.fontMedium,
fontSize: 21,
marginBottom: 13,
},
message: {
marginBottom: 20,
},
inputContainer: {
flexDirection: "row",
marginBottom: 20,
},
buttons: {
flexDirection: "row-reverse",
},
button: {
marginLeft: 10,
},
buttonOk: {
},
buttonCancel: {

},
description: {
marginTop: 35,
marginHorizontal: 10,
marginBottom: 35,
},
searchHeader: {
backgroundColor: blixtTheme.primary,
paddingTop: 0,
borderBottomWidth: 0,
marginHorizontal: 8,
elevation: 0,
}
});
10 changes: 10 additions & 0 deletions src/windows/InitProcess/DEV_Commands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,16 @@ export default function DEV_Commands({ navigation, continueCallback }: IProps) {
console.log(await NativeModules.LndMobileTools.tailLog(10));
}}><Text style={styles.buttonText}>LndMobileTools.tailLog</Text></Button>

<Text style={{ width: "100%"}}>Electron:</Text>
<Button small onPress={async () => {
console.log("ReactNativeElectron", ReactNativeElectron);
console.log("ReactNativeElectron.getInitialURL()", await ReactNativeElectron.getInitialURL());
}}><Text style={styles.buttonText}>ReactNativeElectron.getInitialURL()</Text></Button>
<Button small onPress={async () => {
console.log("lndmobile", lndmobile);
console.log("lndmobile.hello()", await lndmobile.hello((t) => console.log(t)));
}}><Text style={styles.buttonText}>lndmobile.hello()</Text></Button>

<Text style={{ width: "100%"}}>iOS LndMobile:</Text>
<Button small onPress={async () => {
console.log(NativeModules.LndMobileTools);
Expand Down
Loading

0 comments on commit 026fd02

Please sign in to comment.