Skip to content

Commit

Permalink
make onchain donation address dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
secondl1ght committed Dec 23, 2023
1 parent e5221ca commit dbfc624
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 14 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ BTCMAP_KEY=
GITHUB_API_KEY=
LNBITS_API_KEY=
LNBITS_URL=
LNBITS_WALLET_ID=
OPENCAGE_API_KEY=
SERVER_CRYPTO_KEY=
SERVER_INIT_VECTOR=
6 changes: 2 additions & 4 deletions src/components/DonationOption.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
class="mx-auto flex w-full items-center justify-between rounded-xl bg-lightBlue px-4 py-4 text-body dark:bg-white/[0.15] dark:text-white md:w-[475px] md:justify-center md:space-x-4 md:px-0 md:py-3"
>
<!-- value -->
<span class="hidden lowercase md:block"
>{text === 'Lightning' ? `${value.slice(0, 41)}...` : value}</span
>
<span class="hidden lowercase md:block">{value.slice(0, 41)}...</span>
<span class="block uppercase md:hidden"
>{text}
<img
src={text === 'Lightning' ? '/icons/ln-highlight.svg' : '/icons/btc-highlight.svg'}
alt="protocol"
class="mb-1 inline"
class="mb-1 inline dark:rounded-full dark:bg-white dark:p-0.5"
/>
</span>

Expand Down
25 changes: 25 additions & 0 deletions src/routes/support-us/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { LNBITS_API_KEY, LNBITS_URL, LNBITS_WALLET_ID } from '$env/static/private';
import axios from 'axios';
import axiosRetry from 'axios-retry';
import type { PageServerLoad } from './$types';

axiosRetry(axios, { retries: 3, retryDelay: axiosRetry.exponentialDelay });

export const load: PageServerLoad = async () => {
const headers = {
'X-API-Key': `${LNBITS_API_KEY}`,
'Content-type': 'application/json'
};

try {
const address = await axios.get(
`https://${LNBITS_URL}/watchonly/api/v1/address/${LNBITS_WALLET_ID}`,
{ headers }
);

return { address: address.data.address };
} catch (error) {
console.log(error);
return { address: 'bc1qqmy5c03clt6a72aq0ys5jzm2sjnws3qr05nvmz' };
}
};
32 changes: 24 additions & 8 deletions src/routes/support-us/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
} from '$lib/comp';
import { theme } from '$lib/store';
import type { DonationType } from '$lib/types';
import { detectTheme } from '$lib/utils';
import { detectTheme, warningToast } from '$lib/utils';
import QRCode from 'qrcode';
import type { Action } from 'svelte/action';
import type { PageData } from './$types';
let onchain = 'bc1qqmy5c03clt6a72aq0ys5jzm2sjnws3qr05nvmz';
export let data: PageData;
let onchain = data.address;
const lnurlp = 'LNURL1DP68GURN8GHJ7CM0WFJJUCN5VDKKZUPWDAEXWTMVDE6HYMRS9ARKXVN4W5EQPSYZ34';
let showQr = false;
Expand All @@ -22,6 +27,20 @@
showQr = true;
};
const renderQr: Action<HTMLCanvasElement> = (node) => {
QRCode.toCanvas(
node,
network === 'Lightning' ? 'lightning:' + lnurlp : 'bitcoin:' + onchain,
{ width: window.innerWidth > 640 ? 256 : 200 },
function (error: any) {
if (error) {
warningToast('Could not generate QR, please try again or contact BTC Map.');
console.error(error);
}
}
);
};
const company = [
{ url: 'https://coinos.io/', title: 'coinos', logo: 'coinos.svg', logoDark: 'coinos-dark.svg' },
{ url: 'https://www.walletofsatoshi.com/', title: 'Wallet of Satoshi', logo: 'wos.svg' },
Expand Down Expand Up @@ -83,12 +102,9 @@

<!-- qr -->
<a href={network === 'Lightning' ? `lightning:${lnurlp}` : `bitcoin:${onchain}`}>
<img
src={network === 'Lightning'
? '/images/lightning-qr.svg'
: '/images/onchain-qr.svg'}
alt="qr"
class="mx-auto h-[256px] w-[256px] rounded-xl border-4 border-link transition-colors hover:border-hover"
<canvas
use:renderQr
class="mx-auto h-[200px] w-[200px] rounded-xl border-4 border-link transition-colors hover:border-hover sm:h-[256px] sm:w-[256px]"
/>
</a>

Expand Down
1 change: 0 additions & 1 deletion static/images/lightning-qr.svg

This file was deleted.

1 change: 0 additions & 1 deletion static/images/onchain-qr.svg

This file was deleted.

0 comments on commit dbfc624

Please sign in to comment.