mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-11-18 18:46:27 +01:00
add webln example on noogle
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<link rel="icon" href="/favicon.ico">
|
<link rel="icon" href="/favicon.ico">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Vite App</title>
|
<title>Nooooooooogle</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
|||||||
@@ -2,19 +2,19 @@
|
|||||||
import Search from './components/Search.vue'
|
import Search from './components/Search.vue'
|
||||||
import Nip07 from './components/Nip07.vue'
|
import Nip07 from './components/Nip07.vue'
|
||||||
import ResultsTable from "@/components/ResultTable.vue";
|
import ResultsTable from "@/components/ResultTable.vue";
|
||||||
|
import Donate from "@/components/Donate.vue";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
|
|
||||||
<Search/>
|
<Search/>
|
||||||
<br>
|
<br>
|
||||||
<ResultsTable></ResultsTable>
|
<ResultsTable></ResultsTable>
|
||||||
<Nip07>
|
<Nip07>
|
||||||
</Nip07>
|
</Nip07>
|
||||||
|
<Donate/>
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</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>
|
||||||
Reference in New Issue
Block a user