mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-03-19 14:21:46 +01:00
add webln example on noogle
This commit is contained in:
parent
af2ad2e990
commit
ed56ba7357
@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Vite App</title>
|
||||
<title>Nooooooooogle</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
@ -2,19 +2,19 @@
|
||||
import Search from './components/Search.vue'
|
||||
import Nip07 from './components/Nip07.vue'
|
||||
import ResultsTable from "@/components/ResultTable.vue";
|
||||
import Donate from "@/components/Donate.vue";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
|
||||
<main>
|
||||
|
||||
<Search/>
|
||||
<br>
|
||||
<ResultsTable></ResultsTable>
|
||||
<Nip07>
|
||||
</Nip07>
|
||||
|
||||
<Donate/>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
|
63
tests/gui/vuejs/noogle/src/components/Donate.vue
Normal file
63
tests/gui/vuejs/noogle/src/components/Donate.vue
Normal file
@ -0,0 +1,63 @@
|
||||
<script>
|
||||
import { requestProvider } from "webln";
|
||||
export default {
|
||||
|
||||
methods: {
|
||||
async zap() {
|
||||
let webln;
|
||||
try {
|
||||
webln = await requestProvider();
|
||||
} catch (err) {
|
||||
// Handle users without WebLN
|
||||
}
|
||||
|
||||
if (webln) {
|
||||
let invoice = await this.createBolt11Lud16("hype@bitcoinfixesthis.org", 1000)
|
||||
console.log(invoice)
|
||||
let response = await webln.sendPayment(invoice)
|
||||
console.log(response)
|
||||
}
|
||||
},
|
||||
|
||||
async createBolt11Lud16(lud16, amount) {
|
||||
let url;
|
||||
if (lud16.includes('@')) { // LNaddress
|
||||
const parts = lud16.split('@');
|
||||
url = `https://${parts[1]}/.well-known/lnurlp/${parts[0]}`;
|
||||
} else { // No lud16 set or format invalid
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log(url);
|
||||
const response = await fetch(url);
|
||||
const ob = await response.json();
|
||||
const callback = ob.callback;
|
||||
const amountInSats = parseInt(amount) * 1000;
|
||||
const callbackResponse = await fetch(`${callback}?amount=${amountInSats}`);
|
||||
const obCallback = await callbackResponse.json();
|
||||
return obCallback.pr;
|
||||
} catch (e) {
|
||||
console.log(`LUD16: ${e}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
<button class="c-Button" @click="zap()">Donate</button>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.c-Button {
|
||||
height: 20px;
|
||||
color: white;
|
||||
background: #000000;
|
||||
}
|
||||
</style>
|
Loading…
x
Reference in New Issue
Block a user