Skip to content
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

Add Alby test component #94

Merged
merged 4 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions app/alby.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<View style={styles.container}>
<Text style={styles.title}>alby test</Text>
<Stack.Screen options={{ title: 'Alby Test' }} />
</View>
)
}

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,
},
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
59 changes: 59 additions & 0 deletions src/views/nwc/NwcTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { webln } from 'alby-js-sdk'
import React, { useEffect, useState } from 'react'

const NWCComponent = () => {
const [nwc, setNWC] = useState<any>(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 (
<div>
{!isConnected && (
<button onClick={connect}>Connect to Nostr Wallet Connect</button>
)}
{isConnected && (
<div>
<h2>Connected to Nostr Wallet Connect</h2>
<button onClick={() => sendPayment('your_invoice_here')}>
Send Payment
</button>
{response && (
<div>
<h3>Payment Response:</h3>
<pre>{JSON.stringify(response, null, 2)}</pre>
</div>
)}
</div>
)}
</div>
)
}

export default NWCComponent
16 changes: 15 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down