-
Notifications
You must be signed in to change notification settings - Fork 7
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
Expo Plugin #563
Open
larcho
wants to merge
7
commits into
breez:main
Choose a base branch
from
larcho:expo-plugin-ios
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Expo Plugin #563
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
99dd9af
Expo Plugin for adding Notification Extension Target. Still very draft.
larcho c89e9e0
Added Entitlements Helper
larcho 39424f5
Some fixes for the iOS Plugin, also added basic Expo example
larcho a23d938
Expanded Expo Example quite a bit, also made some minor fixes
larcho 9d99f2c
Added .gitignore to the example project
larcho 95fee34
Fixed Example Project
larcho d7f5ebb
Lint and Prettier fixes
larcho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("./plugin/build") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
EXPO_PUBLIC_API_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files | ||
|
||
# dependencies | ||
node_modules/ | ||
|
||
# Expo | ||
.expo/ | ||
dist/ | ||
web-build/ | ||
expo-env.d.ts | ||
|
||
# Native | ||
*.orig.* | ||
*.jks | ||
*.p8 | ||
*.p12 | ||
*.key | ||
*.mobileprovision | ||
|
||
# Metro | ||
.metro-health-check* | ||
|
||
# debug | ||
npm-debug.* | ||
yarn-debug.* | ||
yarn-error.* | ||
|
||
# macOS | ||
.DS_Store | ||
*.pem | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
|
||
# Build | ||
ios/ | ||
android/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import { useState, useEffect, useRef } from "react" | ||
import { StatusBar } from "expo-status-bar" | ||
import { StyleSheet, Text, View, ScrollView, TouchableOpacity, SafeAreaView } from "react-native" | ||
import { getItemAsync, setItemAsync } from "expo-secure-store" | ||
import { Mnemonic } from "./mnemonic" | ||
import { | ||
addEventListener, | ||
connect, | ||
defaultConfig, | ||
getInfo, | ||
LiquidNetwork, | ||
listPayments, | ||
removeEventListener, | ||
prepareReceivePayment, | ||
prepareSendPayment, | ||
receivePayment, | ||
sendPayment, | ||
PaymentMethod | ||
} from "@breeztech/react-native-breez-sdk-liquid" | ||
import type { SdkEvent } from "@breeztech/react-native-breez-sdk-liquid" | ||
|
||
const MNEMONIC_STORE = "mnemonic" | ||
|
||
const DebugLine = ({ title, text }: { title: string; text?: string }) => { | ||
return ( | ||
<TouchableOpacity style={{ flex: 1 }}> | ||
<View style={{ margin: 5 }}> | ||
<Text style={{ fontWeight: "bold" }}>{title}</Text> | ||
{text && text.length > 0 ? <Text>{text}</Text> : <></>} | ||
</View> | ||
</TouchableOpacity> | ||
) | ||
} | ||
|
||
const mnemonicGenerator = new Mnemonic() | ||
|
||
export default function App() { | ||
const [lines, setLines] = useState<Array<{ at: number; title: string; text?: string }>>([]) | ||
const listenerIdRef = useRef<string>() | ||
|
||
useEffect(() => { | ||
const addLine = (title: string, text?: string): void => { | ||
setLines((lines) => [{ at: new Date().getTime(), title, text }, ...lines]) | ||
console.log(`${title}${text && text.length > 0 ? ": " + text : ""}`) | ||
} | ||
|
||
const eventHandler = (event: SdkEvent) => { | ||
addLine("SDK Event", JSON.stringify(event)) | ||
} | ||
|
||
const bolt11Invoice: string = "" | ||
|
||
const asyncFn = async () => { | ||
try { | ||
let mnemonic = await getItemAsync(MNEMONIC_STORE) | ||
if (!mnemonic) { | ||
mnemonic = await mnemonicGenerator.generateMnemonic(256) | ||
await setItemAsync(MNEMONIC_STORE, mnemonic) | ||
} | ||
|
||
// Get API Key | ||
const apiKey = process.env.EXPO_PUBLIC_API_KEY | ||
|
||
if (!apiKey) { | ||
throw new Error("No API Key set") | ||
} | ||
|
||
// Connect using the config | ||
const config = await defaultConfig(LiquidNetwork.MAINNET, apiKey) | ||
addLine("defaultConfig", JSON.stringify(config)) | ||
|
||
await connect({ config, mnemonic }) | ||
addLine("connect") | ||
|
||
// Get wallet info | ||
const getInfoRes = await getInfo() | ||
addLine("getInfo", JSON.stringify(getInfoRes)) | ||
|
||
// Historical payments list | ||
await listPayments({}) | ||
|
||
// Register for events | ||
const listenerId = await addEventListener(eventHandler) | ||
listenerIdRef.current = listenerId | ||
addLine("addEventListener", listenerId) | ||
|
||
/* Receive lightning payment */ | ||
|
||
const prepareReceiveRes = await prepareReceivePayment({ payerAmountSat: 1000, paymentMethod: PaymentMethod.LIGHTNING }) | ||
addLine("prepareReceivePayment", JSON.stringify(prepareReceiveRes)) | ||
// Get the fees required for this payment | ||
addLine("Payment fees", `${prepareReceiveRes.feesSat}`) | ||
|
||
const receivePaymentRes = await receivePayment({ prepareResponse: prepareReceiveRes }) | ||
addLine("receivePayment", JSON.stringify(receivePaymentRes)) | ||
// Wait for payer to pay.... once successfully paid an event of `paymentSucceeded` will be emitted. | ||
addLine("Bolt11 invoice", `${receivePaymentRes.destination}`) | ||
|
||
/* Send lightning payment */ | ||
|
||
// Set the `bolt11Invoice` to enable sending in the example app | ||
if (bolt11Invoice) { | ||
let prepareSendRes = await prepareSendPayment({ destination: bolt11Invoice }) | ||
addLine("prepareSendPayment", JSON.stringify(prepareSendRes)) | ||
// Get the fees required for this payment | ||
addLine("Payment fees", `${prepareSendRes.feesSat}`) | ||
|
||
let sendPaymentRes = await sendPayment({ prepareResponse: prepareSendRes }) | ||
addLine("sendPayment", JSON.stringify(sendPaymentRes)) | ||
// Once successfully paid an event of `paymentSucceeded` will be emitted. | ||
addLine("Payment", JSON.stringify(sendPaymentRes.payment)) | ||
} | ||
} catch (error: unknown) { | ||
if (error instanceof Error) { | ||
addLine("error", error.message) | ||
} | ||
console.log(`Error: ${JSON.stringify(error)}`) | ||
} | ||
} | ||
|
||
asyncFn() | ||
|
||
return () => { | ||
const listenerId = listenerIdRef.current | ||
if (listenerId) { | ||
removeEventListener(listenerId) | ||
listenerIdRef.current = undefined | ||
} | ||
} | ||
}, [setLines]) | ||
|
||
return ( | ||
<SafeAreaView style={styles.container}> | ||
<ScrollView style={{ margin: 5 }}> | ||
{lines.map((line) => ( | ||
<DebugLine key={`${line.at}-${line.title}`} title={line.title} text={line.text} /> | ||
))} | ||
</ScrollView> | ||
<StatusBar style="auto" /> | ||
</SafeAreaView> | ||
) | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: "#fff", | ||
alignItems: "center", | ||
justifyContent: "center" | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import type { ConfigContext, ExpoConfig } from "expo/config" | ||
export default function defineConfig({ config }: ConfigContext): ExpoConfig { | ||
const apiKey = process.env.EXPO_PUBLIC_API_KEY ?? "" | ||
return { | ||
...config, | ||
name: "expo-breez-sdk-liquid-example", | ||
slug: "expo-breez-sdk-liquid-example", | ||
version: "1.0.0", | ||
orientation: "portrait", | ||
icon: "./assets/icon.png", | ||
userInterfaceStyle: "light", | ||
newArchEnabled: true, | ||
splash: { | ||
image: "./assets/splash-icon.png", | ||
resizeMode: "contain", | ||
backgroundColor: "#ffffff" | ||
}, | ||
ios: { | ||
supportsTablet: true, | ||
bundleIdentifier: "com.breeztech.expo-breez-sdk-liquid-example" | ||
}, | ||
android: { | ||
adaptiveIcon: { | ||
foregroundImage: "./assets/adaptive-icon.png", | ||
backgroundColor: "#ffffff" | ||
} | ||
}, | ||
web: { | ||
favicon: "./assets/favicon.png" | ||
}, | ||
extra: { | ||
eas: { | ||
build: { | ||
experimental: { | ||
ios: { | ||
appExtensions: [ | ||
{ | ||
targetName: "BreezNotificationService", | ||
bundleIdentifier: "com.breeztech.expo-breez-sdk-liquid-example.notificationextension", | ||
entitlements: { | ||
"com.apple.security.application-groups": ["group.com.breeztech.expo-breez-sdk-liquid-example"], | ||
"keychain-access-groups": ["$(AppIdentifierPrefix)sharedkey"] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
plugins: [["@breeztech/react-native-breez-sdk-liquid", { apiKey }]] | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { registerRootComponent } from "expo" | ||
|
||
import App from "./App" | ||
|
||
// registerRootComponent calls AppRegistry.registerComponent('main', () => App); | ||
// It also ensures that whether you load the app in Expo Go or in a native build, | ||
// the environment is set up appropriately | ||
registerRootComponent(App) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rename this to
BREEZ_API_KEY
. I wasn't sure if I needed an Expo API key at firstThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, looks confusing. By the way, anything that starts with
EXPO_PUBLIC
in Expo will be also exposed during runtime. I'll rename it to EXPO_PUBLIC_BREEZ_API_KEY.