-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Add redeem button for cashu tokens
Showing
10 changed files
with
163 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"nostrudel": minor | ||
--- | ||
|
||
Add redeem button for cashu tokens |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { lazy } from "react"; | ||
import { EmbedableContent, embedJSX } from "../../helpers/embeds"; | ||
import { getMatchCashu } from "../../helpers/regexp"; | ||
|
||
const InlineCachuCard = lazy(() => import("../inline-cashu-card")); | ||
|
||
export function embedCashuTokens(content: EmbedableContent) { | ||
return embedJSX(content, { | ||
regexp: getMatchCashu(), | ||
render: (match) => { | ||
return <InlineCachuCard token={match[0]} />; | ||
}, | ||
name: "emoji", | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { useEffect, useState } from "react"; | ||
import { Box, Button, ButtonGroup, Card, Heading, IconButton, Link } from "@chakra-ui/react"; | ||
import { getDecodedToken, Token } from "@cashu/cashu-ts"; | ||
|
||
import { CopyIconButton } from "./copy-icon-button"; | ||
import { useUserMetadata } from "../hooks/use-user-metadata"; | ||
import { useCurrentAccount } from "../hooks/use-current-account"; | ||
import { ECashIcon, WalletIcon } from "./icons"; | ||
|
||
function RedeemButton({ token }: { token: string }) { | ||
const account = useCurrentAccount()!; | ||
const metadata = useUserMetadata(account.pubkey); | ||
|
||
const lnurl = metadata?.lud16 ?? ""; | ||
const url = `https://redeem.cashu.me?token=${encodeURIComponent(token)}&lightning=${encodeURIComponent( | ||
lnurl, | ||
)}&autopay=yes`; | ||
return ( | ||
<Button as={Link} href={url} isExternal colorScheme="primary"> | ||
Redeem | ||
</Button> | ||
); | ||
} | ||
|
||
export default function InlineCachuCard({ token }: { token: string }) { | ||
const account = useCurrentAccount(); | ||
|
||
const [cashu, setCashu] = useState<Token>(); | ||
|
||
useEffect(() => { | ||
if (!token.startsWith("cashuA") || token.length < 10) return; | ||
try { | ||
const cashu = getDecodedToken(token); | ||
setCashu(cashu); | ||
} catch (e) {} | ||
}, [token]); | ||
|
||
if (!cashu) return null; | ||
|
||
const amount = cashu?.token[0].proofs.reduce((acc, v) => acc + v.amount, 0); | ||
return ( | ||
<Card p="4" flexDirection="row" borderColor="green.500" alignItems="center" gap="4"> | ||
<ECashIcon boxSize={10} color="green.500" /> | ||
<Box> | ||
<Heading size="md">{amount} Cashu sats</Heading> | ||
{cashu && <small>Mint: {new URL(cashu.token[0].mint).hostname}</small>} | ||
</Box> | ||
{cashu.memo && <Box>Memo: {cashu.memo}</Box>} | ||
<ButtonGroup ml="auto"> | ||
<CopyIconButton text={token} title="Copy Token" aria-label="Copy Token" /> | ||
<IconButton | ||
as={Link} | ||
icon={<WalletIcon />} | ||
title="Open Wallet" | ||
aria-label="Open Wallet" | ||
href={`cashu://` + token} | ||
/> | ||
{account && <RedeemButton token={token} />} | ||
</ButtonGroup> | ||
</Card> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -975,6 +975,17 @@ | |
"@babel/helper-validator-identifier" "^7.22.19" | ||
to-fast-properties "^2.0.0" | ||
|
||
"@cashu/cashu-ts@^0.8.2-rc.7": | ||
version "0.8.2-rc.7" | ||
resolved "https://registry.yarnpkg.com/@cashu/cashu-ts/-/cashu-ts-0.8.2-rc.7.tgz#810109fc5aca8f210cb6865de1b3ab7e245e0771" | ||
integrity sha512-Csvs8BQGdCAqMuoDPYVMAH1h1Z+3qXZfc8V2bxIaMaFWq4O9y/kMIx6uvB1D82+hrjHywpVihMPp9TYCCs3Vjw== | ||
dependencies: | ||
"@gandlaf21/bolt11-decode" "^3.0.6" | ||
"@noble/curves" "^1.0.0" | ||
"@scure/bip32" "^1.3.2" | ||
"@scure/bip39" "^1.2.1" | ||
buffer "^6.0.3" | ||
|
||
"@chakra-ui/[email protected]": | ||
version "2.3.1" | ||
resolved "https://registry.yarnpkg.com/@chakra-ui/accordion/-/accordion-2.3.1.tgz#a326509e286a5c4e8478de9bc2b4b05017039e6b" | ||
|
@@ -2254,6 +2265,15 @@ | |
resolved "https://registry.yarnpkg.com/@esbuild/win32-x64/-/win32-x64-0.18.20.tgz#786c5f41f043b07afb1af37683d7c33668858f6d" | ||
integrity sha512-kTdfRcSiDfQca/y9QIkng02avJ+NCaQvrMejlsB3RRv5sE9rRoeBPISaZpKxHELzRxZyLvNts1P27W3wV+8geQ== | ||
|
||
"@gandlaf21/bolt11-decode@^3.0.6": | ||
version "3.0.6" | ||
resolved "https://registry.yarnpkg.com/@gandlaf21/bolt11-decode/-/bolt11-decode-3.0.6.tgz#ab514fdcee596ccffbfef7b33bc9cc93afe386ee" | ||
integrity sha512-KUcAK2b9or8J47hzNTM2A+xdU0jCGIL4oC4TDyUlRYMfS5dBVOh4ywg9r3TZD8C/eVx7r14Hp4F79CSDjyCWTQ== | ||
dependencies: | ||
bech32 "^1.1.2" | ||
bn.js "^4.11.8" | ||
buffer "^6.0.3" | ||
|
||
"@getalby/bitcoin-connect-react@^1.1.0": | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/@getalby/bitcoin-connect-react/-/bitcoin-connect-react-1.1.0.tgz#d6b97b793b5ae128783e1adafaf7a87f983a6d78" | ||
|
@@ -2365,12 +2385,19 @@ | |
dependencies: | ||
"@noble/hashes" "1.3.1" | ||
|
||
"@noble/curves@^1.0.0", "@noble/curves@~1.2.0": | ||
version "1.2.0" | ||
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.2.0.tgz#92d7e12e4e49b23105a2555c6984d41733d65c35" | ||
integrity sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw== | ||
dependencies: | ||
"@noble/hashes" "1.3.2" | ||
|
||
"@noble/[email protected]": | ||
version "1.3.1" | ||
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.1.tgz#8831ef002114670c603c458ab8b11328406953a9" | ||
integrity sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA== | ||
|
||
"@noble/hashes@~1.3.0", "@noble/hashes@~1.3.1": | ||
"@noble/hashes@1.3.2", "@noble/hashes@~1.3.0", "@noble/hashes@~1.3.1", "@noble/hashes@~1.3.2": | ||
version "1.3.2" | ||
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39" | ||
integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ== | ||
|
@@ -2463,7 +2490,7 @@ | |
resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.1.tgz#ebb651ee52ff84f420097055f4bf46cfba403938" | ||
integrity sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA== | ||
|
||
"@scure/base@~1.1.0": | ||
"@scure/base@~1.1.0", "@scure/base@~1.1.2": | ||
version "1.1.3" | ||
resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.3.tgz#8584115565228290a6c6c4961973e0903bb3df2f" | ||
integrity sha512-/+SgoRjLq7Xlf0CWuLHq2LUZeL/w65kfzAPG5NH9pcmBhs+nunQTn4gvdwgMTIXnt9b2C/1SeL2XiysZEyIC9Q== | ||
|
@@ -2477,7 +2504,16 @@ | |
"@noble/hashes" "~1.3.1" | ||
"@scure/base" "~1.1.0" | ||
|
||
"@scure/[email protected]": | ||
"@scure/bip32@^1.3.2": | ||
version "1.3.2" | ||
resolved "https://registry.yarnpkg.com/@scure/bip32/-/bip32-1.3.2.tgz#90e78c027d5e30f0b22c1f8d50ff12f3fb7559f8" | ||
integrity sha512-N1ZhksgwD3OBlwTv3R6KFEcPojl/W4ElJOeCZdi+vuI5QmTFwLq3OFf2zd2ROpKvxFdgZ6hUpb0dx9bVNEwYCA== | ||
dependencies: | ||
"@noble/curves" "~1.2.0" | ||
"@noble/hashes" "~1.3.2" | ||
"@scure/base" "~1.1.2" | ||
|
||
"@scure/[email protected]", "@scure/bip39@^1.2.1": | ||
version "1.2.1" | ||
resolved "https://registry.yarnpkg.com/@scure/bip39/-/bip39-1.2.1.tgz#5cee8978656b272a917b7871c981e0541ad6ac2a" | ||
integrity sha512-Z3/Fsz1yr904dduJD0NpiyRHhRYHdcnyh73FZWiV+/qhWi83wNJ3NWolYqCEN+ZWsUz2TWwajJggcRE9r1zUYg== | ||
|
@@ -3027,6 +3063,11 @@ bcrypt-pbkdf@^1.0.0: | |
dependencies: | ||
tweetnacl "^0.14.3" | ||
|
||
bech32@^1.1.2: | ||
version "1.1.4" | ||
resolved "https://registry.yarnpkg.com/bech32/-/bech32-1.1.4.tgz#e38c9f37bf179b8eb16ae3a772b40c356d4832e9" | ||
integrity sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ== | ||
|
||
bech32@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/bech32/-/bech32-2.0.0.tgz#078d3686535075c8c79709f054b1b226a133b355" | ||
|
@@ -3054,6 +3095,11 @@ bluebird@^3.7.2: | |
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f" | ||
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg== | ||
|
||
bn.js@^4.11.8: | ||
version "4.12.0" | ||
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88" | ||
integrity sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA== | ||
|
||
boolbase@^1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e" | ||
|
@@ -3116,6 +3162,14 @@ buffer@^5.6.0: | |
base64-js "^1.3.1" | ||
ieee754 "^1.1.13" | ||
|
||
buffer@^6.0.3: | ||
version "6.0.3" | ||
resolved "https://registry.yarnpkg.com/buffer/-/buffer-6.0.3.tgz#2ace578459cc8fbe2a70aaa8f52ee63b6a74c6c6" | ||
integrity sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA== | ||
dependencies: | ||
base64-js "^1.3.1" | ||
ieee754 "^1.2.1" | ||
|
||
builtin-modules@^3.1.0: | ||
version "3.3.0" | ||
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.3.0.tgz#cae62812b89801e9656336e46223e030386be7b6" | ||
|
@@ -4605,7 +4659,7 @@ identicon.js@^2.3.3: | |
resolved "https://registry.yarnpkg.com/identicon.js/-/identicon.js-2.3.3.tgz#c505b8d60ecc6ea13bbd991a33964c44c1ad60a1" | ||
integrity sha512-/qgOkXKZ7YbeCYbawJ9uQQ3XJ3uBg9VDpvHjabCAPp6aRMhjLaFAxG90+1TxzrhKaj6AYpVGrx6UXQfQA41UEA== | ||
|
||
ieee754@^1.1.13: | ||
ieee754@^1.1.13, ieee754@^1.2.1: | ||
version "1.2.1" | ||
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352" | ||
integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA== | ||
|