Skip to content

Commit e6e70b8

Browse files
committed
add qr scan to nfts
1 parent 199922d commit e6e70b8

File tree

3 files changed

+63
-9
lines changed

3 files changed

+63
-9
lines changed

src/components/tokenItems/nftChild.vue

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// @ts-ignore
88
import { createIcon } from '@download/blockies';
99
import alertDialog from 'src/components/alertDialog.vue'
10+
import QrCodeDialog from '../qr/qrCodeScanDialog.vue';
1011
import type { BcmrTokenMetadata, TokenBurnRequestParams, TokenSendRequestParams } from "src/interfaces/interfaces"
1112
import { useStore } from 'src/stores/store'
1213
import { useSettingsStore } from 'src/stores/settingsStore'
@@ -34,6 +35,7 @@
3435
const mintCommitment = ref("");
3536
const mintAmountNfts = ref(undefined as string | undefined);
3637
const startingNumberNFTs = ref(undefined as string | undefined);
38+
const showQrCodeDialog = ref(false);
3739
3840
const nftMetadata = computed(() => {
3941
const commitment = nftData.value?.token?.commitment;
@@ -75,6 +77,16 @@
7577
iconDiv?.appendChild(icon);
7678
})
7779
80+
const qrDecode = (content: string) => {
81+
destinationAddr.value = content;
82+
}
83+
const qrFilter = (content: string) => {
84+
const decoded = decodeCashAddress(content);
85+
if (typeof decoded === "string" || decoded.prefix !== store.wallet?.networkPrefix) {
86+
return "Not a cashaddress on current network";
87+
}
88+
return true;
89+
}
7890
async function sendNft(){
7991
try{
8092
if(!store.wallet) return;
@@ -310,10 +322,15 @@
310322
</div>
311323
<div v-if="displaySendNft" style="margin-top: 10px;">
312324
Send this NFT to
313-
<p class="grouped">
314-
<input v-model="destinationAddr" name="tokenAddress" placeholder="token address">
325+
<div class="inputGroup">
326+
<div class="addressInputNftSend">
327+
<input v-model="destinationAddr" name="tokenAddress" placeholder="token address">
328+
<button v-if="settingsStore.qrScan" @click="() => showQrCodeDialog = true" style="padding: 12px">
329+
<img src="images/qrscan.svg" />
330+
</button>
331+
</div>
315332
<input @click="sendNft()" type="button" class="primaryButton" value="Send NFT">
316-
</p>
333+
</div>
317334
</div>
318335
<div v-if="displayMintNfts" style="margin-top: 10px;">
319336
Mint a number of (unique) NFTs to a specific address
@@ -350,4 +367,7 @@
350367
<dialogNftIcon :srcNftImage="nftMetadata?.uris?.image ? nftMetadata.uris.image : nftMetadata.uris.icon as string" :nftName="nftMetadata.name" @close-dialog="() => showNftImage = false"/>
351368
</div>
352369
</div>
370+
<div v-if="showQrCodeDialog">
371+
<QrCodeDialog @hide="() => showQrCodeDialog = false" @decode="qrDecode" :filter="qrFilter"/>
372+
</div>
353373
</template>

src/components/tokenItems/tokenItemNFT.vue

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// @ts-ignore
88
import { createIcon } from '@download/blockies';
99
import alertDialog from 'src/components/alertDialog.vue'
10+
import QrCodeDialog from '../qr/qrCodeScanDialog.vue';
1011
import type { TokenDataNFT, BcmrTokenMetadata, TokenSendRequestParams, TokenMintRequestParams, TokenBurnRequestParams } from "src/interfaces/interfaces"
1112
import { querySupplyNFTs, queryActiveMinting } from "src/queryChainGraph"
1213
import { copyToClipboard } from 'src/utils/utils';
@@ -43,6 +44,7 @@
4344
const startingNumberNFTs = ref(undefined as string | undefined);
4445
const totalNumberNFTs = ref(undefined as number | undefined);
4546
const hasMintingNFT = ref(undefined as boolean | undefined);
47+
const showQrCodeDialog = ref(false);
4648
4749
let fetchedMetadataChildren = false
4850
@@ -106,6 +108,16 @@
106108
displayChildNfts.value = !displayChildNfts.value;
107109
}
108110
111+
const qrDecode = (content: string) => {
112+
destinationAddr.value = content;
113+
}
114+
const qrFilter = (content: string) => {
115+
const decoded = decodeCashAddress(content);
116+
if (typeof decoded === "string" || decoded.prefix !== store.wallet?.networkPrefix) {
117+
return "Not a cashaddress on current network";
118+
}
119+
return true;
120+
}
109121
// NFT Group specific functionality
110122
async function sendAllNfts(){
111123
try{
@@ -497,17 +509,27 @@
497509

498510
<div v-if="displaySendNft" style="margin-top: 10px;">
499511
Send this NFT to
500-
<p class="grouped">
501-
<input v-model="destinationAddr" name="tokenAddress" placeholder="token address">
512+
<div class="inputGroup">
513+
<div class="addressInputNftSend">
514+
<input v-model="destinationAddr" name="tokenAddress" placeholder="token address">
515+
<button v-if="settingsStore.qrScan" @click="() => showQrCodeDialog = true" style="padding: 12px">
516+
<img src="images/qrscan.svg" />
517+
</button>
518+
</div>
502519
<input @click="sendNft()" type="button" class="primaryButton" value="Send NFT">
503-
</p>
520+
</div>
504521
</div>
505522
<div v-if="displaySendAllNfts" style="margin-top: 10px;">
506523
Send all {{ tokenData.nfts?.length }} NFTs of this category to
507-
<p class="grouped">
508-
<input v-model="destinationAddr" name="tokenAddress" placeholder="token address">
524+
<div class="inputGroup">
525+
<div class="addressInputNftSend">
526+
<input v-model="destinationAddr" name="tokenAddress" placeholder="token address">
527+
<button v-if="settingsStore.qrScan" @click="() => showQrCodeDialog = true" style="padding: 12px">
528+
<img src="images/qrscan.svg" />
529+
</button>
530+
</div>
509531
<input @click="sendAllNfts()" type="button" class="primaryButton" value="Transfer NFTs">
510-
</p>
532+
</div>
511533
</div>
512534
<div v-if="displayMintNfts" style="margin-top: 10px;">
513535
Mint a number of (unique) NFTs to a specific address
@@ -559,4 +581,7 @@
559581
</div>
560582
</div>
561583
</div>
584+
<div v-if="showQrCodeDialog">
585+
<QrCodeDialog @hide="() => showQrCodeDialog = false" @decode="qrDecode" :filter="qrFilter"/>
586+
</div>
562587
</template>

src/css/app.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ input[type='number'] {
155155
width: 50%;
156156
display: flex;
157157
}
158+
.addressInputNftSend {
159+
margin-right: 14px;
160+
display: flex;
161+
width: 100%;
162+
gap: 0.5rem;
163+
}
158164
.actionBar {
159165
margin-top: 15px;
160166
margin-bottom: 5px;
@@ -246,6 +252,9 @@ select, summary {
246252
width: 100%;
247253
gap: 0.5rem;
248254
}
255+
.addressInputNftSend {
256+
margin-bottom: 10px;
257+
}
249258
.sendTokenAmount {
250259
margin-top: 4px;
251260
width: 100%;

0 commit comments

Comments
 (0)