diff --git a/next.config.js b/next.config.js
index 2516072..f56648b 100644
--- a/next.config.js
+++ b/next.config.js
@@ -1,4 +1,3 @@
-// next.config.js
const removeImports = require("next-remove-imports")();
module.exports = removeImports({
@@ -9,4 +8,12 @@ module.exports = removeImports({
webpack(config, options) {
return config;
},
+ async rewrites() {
+ return [
+ {
+ source: '/api/cron',
+ destination: '/api/cron',
+ },
+ ];
+ },
});
\ No newline at end of file
diff --git a/prisma/migrations/20240830221442_init/migration.sql b/prisma/migrations/20240901171426_init/migration.sql
similarity index 98%
rename from prisma/migrations/20240830221442_init/migration.sql
rename to prisma/migrations/20240901171426_init/migration.sql
index c039192..e8ee247 100644
--- a/prisma/migrations/20240830221442_init/migration.sql
+++ b/prisma/migrations/20240901171426_init/migration.sql
@@ -15,8 +15,10 @@ CREATE TABLE "Role" (
"id" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"subscribed" BOOLEAN NOT NULL DEFAULT false,
+ "admin" BOOLEAN NOT NULL DEFAULT false,
"subscriptionStartDate" TIMESTAMP(3),
"lastPaymentAt" TIMESTAMP(3),
+ "subscriptionExpiredAt" TIMESTAMP(3),
"nwc" TEXT,
CONSTRAINT "Role_pkey" PRIMARY KEY ("id")
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 9c5f944..6b524fe 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -26,9 +26,11 @@ model Role {
id String @id @default(uuid())
user User @relation(fields: [userId], references: [id])
userId String @unique
- subscribed Boolean @default(false)
+ subscribed Boolean @default(false)
+ admin Boolean @default(false)
subscriptionStartDate DateTime?
lastPaymentAt DateTime?
+ subscriptionExpiredAt DateTime?
nwc String?
}
diff --git a/src/components/bitcoinConnect/SubscriptionPaymentButton.js b/src/components/bitcoinConnect/SubscriptionPaymentButton.js
index 54ca7b8..701f2b1 100644
--- a/src/components/bitcoinConnect/SubscriptionPaymentButton.js
+++ b/src/components/bitcoinConnect/SubscriptionPaymentButton.js
@@ -104,6 +104,26 @@ const SubscriptionPaymentButtons = ({ onSuccess, onError, onRecurringSubscriptio
const newNWCUrl = newNwc.getNostrWalletConnectUrl();
if (newNWCUrl) {
+ const nwc = new webln.NostrWebLNProvider({
+ nostrWalletConnectUrl: newNWCUrl,
+ });
+
+ await nwc.enable();
+
+ const invoice = await fetchInvoice();
+
+ if (!invoice || !invoice.paymentRequest) {
+ showToast('error', 'NWC', `Failed to fetch invoice from ${lnAddress}`);
+ return;
+ }
+
+ const paymentResponse = await nwc.sendPayment(invoice.paymentRequest);
+
+ if (!paymentResponse || !paymentResponse?.preimage) {
+ showToast('error', 'NWC', 'Payment failed');
+ return;
+ }
+
const subscriptionResponse = await axios.put('/api/users/subscription', {
userId: session.user.id,
isSubscribed: true,
@@ -218,22 +238,22 @@ const SubscriptionPaymentButtons = ({ onSuccess, onError, onRecurringSubscriptio
<>
Manually enter NWC URL
- *make sure you set a budget of at least 25000 sats and set budget renewal to monthly - setNwcInput(e.target.value)} - placeholder="Enter NWC URL" - className="w-full p-2 mb-4 border rounded" - /> - +Manually enter NWC URL
+ *make sure you set a budget of at least 25000 sats and set budget renewal to monthly + setNwcInput(e.target.value)} + placeholder="Enter NWC URL" + className="w-full p-2 mb-4 border rounded" + /> +Thank you for your support 🎉
Pay-as-you-go subscription will renew on {subscribedUntil.toLocaleDateString()}
> - ) : ( + )} + {(!subscribed && !subscriptionExpiredAt) && ( <>