* Wallet flow * Prepopulate fields of complementary protocol * Remove TODO about one mutation for save We need to save protocols in separate mutations so we can use the wallet id returned by the first protocol save for the following protocol saves and save them all to the same wallet. * Fix badges not updated on wallet delete * Fix useProtocol call * Fix lightning address save via prompt * Don't pass share as attribute to DOM * Fix useCallback dependency * Progress numbers as SVGs * Fix progress line margins * Remove unused saveWallet arguments * Update cache with settings response * Fix line does not connect with number 1 * Don't reuse page nav arrows in form nav * Fix missing SVG hover style * Fix missing space in wallet save log message * Reuse CSS from nav.module.css * align buttons and their icons/text * center form progress line * increase top padding of form on smaller screens * provide margin above button bar on settings form --------- Co-authored-by: k00b <k00b@stacker.news>
76 lines
1.7 KiB
JavaScript
76 lines
1.7 KiB
JavaScript
import Nostr from '@/lib/nostr'
|
|
import { NDKNWCWallet } from '@nostr-dev-kit/ndk-wallet'
|
|
import { nwcUrlValidator, parseNwcUrl } from '@/wallets/lib/validate'
|
|
|
|
// Nostr Wallet Connect (NIP-47)
|
|
// https://github.com/nostr-protocol/nips/blob/master/47.md
|
|
|
|
export default [
|
|
{
|
|
name: 'NWC',
|
|
send: true,
|
|
displayName: 'Nostr Wallet Connect',
|
|
logName: 'NWC',
|
|
fields: [
|
|
{
|
|
name: 'url',
|
|
label: 'url',
|
|
placeholder: 'nostr+walletconnect://',
|
|
type: 'password',
|
|
required: true,
|
|
validate: nwcUrlValidator(),
|
|
encrypt: true
|
|
}
|
|
],
|
|
relationName: 'walletSendNWC'
|
|
},
|
|
{
|
|
name: 'NWC',
|
|
send: false,
|
|
displayName: 'Nostr Wallet Connect',
|
|
logName: 'NWC',
|
|
fields: [
|
|
{
|
|
name: 'url',
|
|
label: 'url',
|
|
placeholder: 'nostr+walletconnect://',
|
|
type: 'password',
|
|
required: true,
|
|
validate: nwcUrlValidator()
|
|
}
|
|
],
|
|
relationName: 'walletRecvNWC'
|
|
}
|
|
]
|
|
|
|
export async function nwcTryRun (fun, { url }, { signal }) {
|
|
const nostr = new Nostr()
|
|
try {
|
|
const nwc = await getNwc(nostr, url, { signal })
|
|
const res = await fun(nwc)
|
|
if (res.error) throw new Error(res.error)
|
|
return res
|
|
} catch (e) {
|
|
if (e.error) throw new Error(e.error.message || e.error.code)
|
|
throw e
|
|
} finally {
|
|
nostr.close()
|
|
}
|
|
}
|
|
|
|
export async function getNwc (nostr, url, { signal }) {
|
|
const ndk = nostr.ndk
|
|
const { walletPubkey, secret, relayUrls } = parseNwcUrl(url)
|
|
const nwc = new NDKNWCWallet(ndk, {
|
|
pubkey: walletPubkey,
|
|
relayUrls,
|
|
secret
|
|
})
|
|
return nwc
|
|
}
|
|
|
|
export async function supportedMethods (url, { signal }) {
|
|
const result = await nwcTryRun(nwc => nwc.getInfo(), { url }, { signal })
|
|
return result.methods
|
|
}
|