/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, { useState } from "react"
import { SafeAreaView, ScrollView, StatusBar, Text, TouchableOpacity, View } from "react-native"
import { Network, getInfo, connect } from "@breeztech/react-native-breez-liquid-sdk"
import { generateMnemonic } from "@dreson4/react-native-quick-bip39"
import { getSecureItem, setSecureItem } from "./utils/storage"
const MNEMONIC_STORE = "MNEMONIC_SECURE_STORE"
const DebugLine = ({ title, text }) => {
return (
{title}
{text && text.length > 0 ? {text} : <>>}
)
}
const App = () => {
const [lines, setLines] = useState([])
const addLine = (title, text) => {
setLines((lines) => [{ at: new Date().getTime(), title, text }, ...lines])
console.log(`${title}${text && text.length > 0 ? ": " + text : ""}`)
}
React.useEffect(() => {
const asyncFn = async () => {
try {
let mnemonic = await getSecureItem(MNEMONIC_STORE)
if (mnemonic == null) {
mnemonic = generateMnemonic(256)
setSecureItem(MNEMONIC_STORE, mnemonic)
}
await connect(mnemonic, undefined, Network.LIQUID)
addLine("connect", null)
let walletInfo = await getInfo(false)
addLine("getInfo", JSON.stringify(walletInfo))
} catch (e) {
addLine("error", e.toString())
console.log(`Error: ${JSON.stringify(e)}`)
}
}
asyncFn()
}, [])
return (
{lines.map((line) => (
))}
)
}
export default App