Skip to content

Commit

Permalink
nice
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Aug 14, 2024
1 parent 649cf78 commit 22a6126
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 113 deletions.
284 changes: 179 additions & 105 deletions src/components/SettingsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -238,115 +238,29 @@
</q-list>
</div>

<!-- nostr -->
<div class="q-py-sm q-px-xs text-left" on-left>
<q-list padding>
<q-item>
<q-item-section>
<q-item-label overline>Nostr</q-item-label>
<q-item-label caption>Your nostr account.</q-item-label>
</q-item-section>
</q-item>
<!-- initWalletSeedPrivateKeySigner -->
<q-item>
<q-btn
class="q-ml-sm q-px-md"
:color="signerType === 'SEED' ? 'primary' : 'grey'"
rounded
outline
@click="handleSeedClick"
>Seed</q-btn
>
<!-- Nip07Signer -->
<q-btn
class="q-ml-sm q-px-md"
:color="signerType === 'NIP07' ? 'primary' : 'grey'"
rounded
outline
:disabled="!nip07SignerAvailable"
@click="handleExtensionClick"
>Extension</q-btn
>
<!-- Nip46Signer -->
<!-- input field for nip46Token -->
<q-input
v-if="false"
outlined
rounded
dense
v-model="nip46Token"
label="Nip46 token"
type="textarea"
autogrow
></q-input>

<q-btn
class="q-ml-sm q-px-md"
:color="signerType === 'NIP46' ? 'primary' : 'grey'"
rounded
outline
@click="handleBunkerClick"
>Bunker</q-btn
>
<!-- reset bunker button if bunker is selected -->
<q-btn
v-if="signerType === 'NIP46'"
class="q-ml-sm q-px-md"
color="warning"
rounded
outline
@click="resetNip46Signer"
>Reset</q-btn
>
<!-- PrivateKeySigner -->
<!-- input for nostrPrivateKey -->
<q-input
v-if="false"
outlined
rounded
dense
v-model="nostrPrivateKey"
label="Private key"
type="textarea"
autogrow
></q-input>

<q-btn
class="q-ml-sm q-px-md"
:color="signerType === 'PRIVATEKEY' ? 'primary' : 'grey'"
rounded
outline
@click="handleNsecClick"
>nsec</q-btn
>
<!-- reset nsec button if nsec is selected -->
<q-btn
v-if="signerType === 'PRIVATEKEY'"
class="q-ml-sm q-px-md"
color="warning"
rounded
outline
@click="resetPrivateKeySigner"
>Reset</q-btn
>
</q-item>
</q-list>
</div>
<!-- ln address -->
<div class="q-py-sm q-px-xs text-left" on-left>
<q-list padding>
<q-item>
<q-item-section>
<q-item-label overline>Lightning address</q-item-label>
<q-item-label caption
>This is your lightning address. Enable it to check for incoming
payments at startup.</q-item-label
>Your Lightning address is generated from your nostr
keys.</q-item-label
>
</q-item-section>
</q-item>
<q-item>
<q-item-section class="q-mx-none q-pl-none">
<!-- toggle to turn Lightning address on and off in new row -->
<div class="row q-pt-md">
<q-toggle
v-model="npcEnabled"
label="Enable Lightning address"
color="primary"
/>
</div>
<div class="row q-pt-md" v-if="npcEnabled">
<div class="col-12">
<q-input outlined v-model="npcAddress" dense rounded readonly>
<template v-slot:append>
Expand All @@ -362,18 +276,171 @@
</template>
</q-input>
</div>
</div>
<!-- toggle to turn Lightning address on and off in new row -->
<div class="row q-pt-md">
<q-toggle
v-model="npcEnabled"
label="Enable Lightning address"
color="primary"
/>
<div class="row q-pt-md">
<q-toggle v-model="automaticClaim" color="primary" />
<q-item-section>
<q-item-label overline>Claim automatically</q-item-label>
<q-item-label caption
>Receive incoming payments automatically when the wallet is
started.
</q-item-label>
</q-item-section>
</div>
</div>
</q-item-section>
</q-item>

<!-- nostr -->
<div class="q-py-sm q-px-md text-left" on-left v-if="npcEnabled">
<q-list padding>
<q-item>
<q-item-section>
<q-item-label overline>Your nostr keys</q-item-label>
<q-item-label caption
>Link your wallet to a nostr account to generate your
Lightning address.</q-item-label
>
</q-item-section>
</q-item>
<!-- initWalletSeedPrivateKeySigner -->
<q-item
:active="signerType === 'SEED'"
active-class="text-weight-bold text-primary"
clickable
>
<q-item-section avatar>
<q-icon
:color="signerType === 'SEED' ? 'primary' : 'grey'"
:name="
signerType === 'SEED'
? 'check_circle'
: 'radio_button_unchecked'
"
@click="handleSeedClick"
class="cursor-pointer"
/>
</q-item-section>
<q-item-section
lines="1"
class="cursor-pointer"
style="word-break: break-word"
>
<q-item-label title>Wallet seed phrase</q-item-label>
<q-item-label caption
>Generate nostr key pair from seed
</q-item-label>
</q-item-section>
</q-item>
<!-- Nip46Signer -->
<q-item
:active="signerType === 'NIP46'"
active-class="text-weight-bold text-primary"
clickable
v-if="false"
>
<q-item-section avatar>
<q-icon
:color="signerType === 'NIP46' ? 'primary' : 'grey'"
:name="
signerType === 'NIP46'
? 'check_circle'
: 'radio_button_unchecked'
"
@click="handleBunkerClick"
class="cursor-pointer"
/>
</q-item-section>
<q-item-section
lines="1"
class="cursor-pointer"
style="word-break: break-word"
>
<q-item-label title>Nsec Bunker</q-item-label>
<q-item-label caption>Use a NIP-46 bunker </q-item-label>
</q-item-section>
<q-item-section side v-if="signerType === 'NIP46'">
<q-icon
name="delete_outline"
@click="resetNip46Signer"
class="cursor-pointer"
><q-tooltip>Delete connection</q-tooltip>
</q-icon>
</q-item-section>
</q-item>
<q-item
:active="signerType === 'PRIVATEKEY'"
active-class="text-weight-bold text-primary"
clickable
>
<q-item-section avatar>
<q-icon
:color="signerType === 'PRIVATEKEY' ? 'primary' : 'grey'"
:name="
signerType === 'PRIVATEKEY'
? 'check_circle'
: 'radio_button_unchecked'
"
@click="handleNsecClick"
class="cursor-pointer"
/>
</q-item-section>
<q-item-section
lines="1"
class="cursor-pointer"
style="word-break: break-word"
>
<q-item-label title>Use your nsec</q-item-label>
<q-item-label caption
>Enter your nostr private key
</q-item-label>
</q-item-section>
<q-item-section side v-if="signerType === 'PRIVATEKEY'">
<q-icon
name="delete_outline"
@click="resetPrivateKeySigner"
class="cursor-pointer"
><q-tooltip>Delete nsec</q-tooltip></q-icon
>
</q-item-section>
</q-item>
<!-- Nip07Signer -->
<q-item
:active="signerType === 'NIP07'"
active-class="text-weight-bold text-primary"
clickable
v-if="nip07SignerAvailable"
>
<q-item-section avatar>
<q-icon
:color="signerType === 'NIP07' ? 'primary' : 'grey'"
:name="
signerType === 'NIP07'
? 'check_circle'
: 'radio_button_unchecked'
"
@click="handleExtensionClick"
class="cursor-pointer"
/>
</q-item-section>
<q-item-section
lines="1"
class="cursor-pointer"
style="word-break: break-word"
>
<q-item-label title>Signing extension</q-item-label>
<q-item-label caption v-if="nip07SignerAvailable"
>Use a NIP-07 signing extension
</q-item-label>
<q-item-label caption v-else
>No NIP-07 signing extension found
</q-item-label>
</q-item-section>
</q-item>
</q-list>
</div>

<!-- NWC -->

<q-item>
<q-item-section>
<q-item-label overline>Link wallet</q-item-label>
Expand Down Expand Up @@ -783,7 +850,7 @@ export default defineComponent({
...mapState(useNPCStore, ["npcAddress"]),
...mapState(useNostrStore, ["pubkey", "mintRecommendations", "signerType"]),
...mapState(useWalletStore, ["mnemonic"]),
...mapWritableState(useNPCStore, ["npcEnabled"]),
...mapWritableState(useNPCStore, ["npcEnabled", "automaticClaim"]),
...mapWritableState(useWalletStore, ["keysetCounters"]),
...mapWritableState(useMintsStore, [
"addMintData",
Expand Down Expand Up @@ -818,6 +885,13 @@ export default defineComponent({
this.unsubscribeNWC();
}
},
npcEnabled: function () {
if (this.npcEnabled) {
this.generateNPCConnection();
} else {
this.npcAddress = "";
}
},
},
methods: {
...mapActions(useNostrStore, [
Expand Down
2 changes: 1 addition & 1 deletion src/stores/nostr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const useNostrStore = defineStore("nostr", {
},
resetNip46Signer: async function () {
this.nip46Token = "";
await this.initNip46Signer();
await this.initWalletSeedPrivateKeySigner();
},
initPrivateKeySigner: async function (nsec?: string) {
if (!nsec && !this.privateKeySignerPrivateKey.length) {
Expand Down
25 changes: 18 additions & 7 deletions src/stores/npubcash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const NIP98Kind = 27235;
export const useNPCStore = defineStore("npc", {
state: () => ({
npcEnabled: useLocalStorage<boolean>("cashu.npc.enabled", false),
automaticClaim: useLocalStorage<boolean>("cashu.npc.automaticClaim", false),
// npcConnections: useLocalStorage<NPCConnection[]>("cashu.npc.connections", []),
npcAddress: useLocalStorage<string>("cashu.npc.address", ""),
npcDomain: useLocalStorage<string>("cashu.npc.domain", "npub.cash"),
Expand All @@ -79,14 +80,19 @@ export const useNPCStore = defineStore("npc", {
// add token to history first
this.addPendingTokenToHistory(token)
receiveStore.receiveData.tokensBase64 = token;
try {
// redeem token automatically
const walletStore = useWalletStore()
await walletStore.redeem()
} catch {
// if it doesn't work, show the receive window
if (this.automaticClaim) {
try {
// redeem token automatically
const walletStore = useWalletStore()
await walletStore.redeem()
} catch {
// if it doesn't work, show the receive window
receiveStore.showReceiveTokens = true;
}
} else {
receiveStore.showReceiveTokens = true;
}

// this.storeUnclaimedProofs(token)
// const proofsToClaim = this.getUnclaimedProofs(token)
// const proofsStore = useProofsStore()
Expand Down Expand Up @@ -156,11 +162,16 @@ export const useNPCStore = defineStore("npc", {
},
generateNPCConnection: async function () {
const nostrStore = useNostrStore()
// await nostrStore.initSigner()
if (!nostrStore.pubkey) {
return
}
const walletPublicKeyHex = nostrStore.pubkey
console.log('Lightning address for wallet:', nip19.npubEncode(walletPublicKeyHex) + '@' + this.npcDomain)
console.log('npub:', nip19.npubEncode(walletPublicKeyHex))
this.baseURL = `https://${this.npcDomain}`
if (!this.npcEnabled) {
return
}
// get info
const info = await this.getInfo()
if (info.error) {
Expand Down

0 comments on commit 22a6126

Please sign in to comment.