diff --git a/app/alby.tsx b/app/alby.tsx new file mode 100644 index 00000000..2a91e1b1 --- /dev/null +++ b/app/alby.tsx @@ -0,0 +1,61 @@ +import { webln } from 'alby-js-sdk' +import { Stack } from 'expo-router' +import { useEffect } from 'react' +import { StyleSheet, Text, View } from 'react-native' + +export default function Alby() { + async function connectToAlby() { + // if (!window.webln) { + try { + const nostrWalletConnectUrl = 'https://arcade.chat/nwc-test' // Replace this with your own NWC url loading mechanism + console.log('so') + const nwc = new webln.NostrWebLNProvider({ nostrWalletConnectUrl }) + console.log(nwc) + await nwc.enable() + console.log('?') + window.webln = nwc + } catch (error) { + console.error('Error connecting to Alby wallet:', error) + // Handle errors and inform the user about the connection issue + } + // } else { + // console.log('got webln', window.webln) + // } + } + useEffect(() => { + console.log(webln) + connectToAlby() + }, []) + return ( + + alby test + + + ) +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + height: '100%', + width: '100%', + backgroundColor: 'transparent', + justifyContent: 'center', + alignItems: 'center', + }, + title: { + color: '#fff', + fontFamily: 'Protomolecule', + fontSize: 60, + textShadowColor: 'cyan', + textShadowRadius: 14, + }, + subtitle: { + color: '#fff', + fontFamily: 'Protomolecule', + fontSize: 20, + textShadowColor: 'cyan', + textShadowRadius: 14, + marginTop: 20, + }, +}) diff --git a/package.json b/package.json index 98e98fa0..cecf733a 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "@tamagui/shorthands": "1.11.2", "@tamagui/theme-base": "1.11.2", "@tamagui/themes": "1.11.2", + "alby-js-sdk": "1.6.0", "axios": "^1.4.0", "babel-plugin-transform-inline-environment-variables": "0.4.4", "bech32": "1.1.4", diff --git a/src/views/nwc/NwcTest.tsx b/src/views/nwc/NwcTest.tsx new file mode 100644 index 00000000..24ec3aca --- /dev/null +++ b/src/views/nwc/NwcTest.tsx @@ -0,0 +1,59 @@ +import { webln } from 'alby-js-sdk' +import React, { useEffect, useState } from 'react' + +const NWCComponent = () => { + const [nwc, setNWC] = useState(null) + const [isConnected, setIsConnected] = useState(false) + const [response, setResponse] = useState(null) + + useEffect(() => { + if (!nwc) { + const newNWC = new webln.NWC({ nostrWalletConnectUrl: loadNWCUrl }) + setNWC(newNWC) + } + }, [nwc]) + + const connect = async () => { + if (!nwc) return + try { + await nwc.enable() + setIsConnected(true) + } catch (error) { + console.error('Error connecting:', error) + } + } + + const sendPayment = async (invoice) => { + if (!nwc) return + try { + const paymentResponse = await nwc.sendPayment(invoice) + setResponse(paymentResponse) + } catch (error) { + console.error('Error sending payment:', error) + } + } + + return ( +
+ {!isConnected && ( + + )} + {isConnected && ( +
+

Connected to Nostr Wallet Connect

+ + {response && ( +
+

Payment Response:

+
{JSON.stringify(response, null, 2)}
+
+ )} +
+ )} +
+ ) +} + +export default NWCComponent diff --git a/yarn.lock b/yarn.lock index 9300ee6f..0162aa24 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3680,6 +3680,15 @@ aggregate-error@^3.0.0: clean-stack "^2.0.0" indent-string "^4.0.0" +alby-js-sdk@1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/alby-js-sdk/-/alby-js-sdk-1.6.0.tgz#e4a8c54b3a3f841bfb372452839bc2dace2a649b" + integrity sha512-utKiIVBYU+d94gvFY/j3rM6X2jw2nZ6tDFheLEbxBbWtsLIkTLSiG8EDlT5NY20gqs43GpQlrRsOZLhlZ+byFQ== + dependencies: + cross-fetch "^3.1.5" + crypto-js "^4.1.1" + nostr-tools "^1.10.0" + anser@^1.4.9: version "1.4.10" resolved "https://registry.yarnpkg.com/anser/-/anser-1.4.10.tgz#befa3eddf282684bd03b63dcda3927aef8c2e35b" @@ -4746,6 +4755,11 @@ crypt@0.0.2, crypt@~0.0.1: resolved "https://registry.yarnpkg.com/crypt/-/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b" integrity sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow== +crypto-js@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.1.1.tgz#9e485bcf03521041bd85844786b83fb7619736cf" + integrity sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw== + crypto-random-string@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e" @@ -8064,7 +8078,7 @@ nostr-tools@1.8.1: "@scure/bip39" "^1.1.1" prettier "^2.8.4" -nostr-tools@^1.1.0: +nostr-tools@^1.1.0, nostr-tools@^1.10.0: version "1.10.1" resolved "https://registry.yarnpkg.com/nostr-tools/-/nostr-tools-1.10.1.tgz#b52043b3031f4314478d0a3bfaa8ffb9cc4f98a0" integrity sha512-zgTYJeuZQ3CDASsmBEcB5i6V6l0IaA6cjnll6OVik3FoZcvbCaL7yP8I40hYnOIi3KlJykV7jEF9fn8h1NzMnA==