/
nft-burn.component.ts
155 lines (144 loc) · 4.89 KB
/
nft-burn.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import { Component, OnInit, Input, Output, EventEmitter } from "@angular/core";
import { GlobalVarsService } from "../global-vars.service";
import { BackendApiService, NFTEntryResponse, PostEntryResponse } from "../backend-api.service";
import * as _ from "lodash";
import { Router } from "@angular/router";
import { isNumber } from "lodash";
import { ToastrService } from "ngx-toastr";
import { BsModalService } from "ngx-bootstrap/modal";
import { Location } from "@angular/common";
import { SwalHelper } from "../../lib/helpers/swal-helper";
@Component({
selector: "nft-burn",
templateUrl: "./nft-burn.component.html",
})
export class NftBurnComponent implements OnInit {
static PAGE_SIZE = 50;
static BUFFER_SIZE = 10;
static WINDOW_VIEWPORT = false;
static PADDING = 0.5;
@Input() postHashHex: string;
@Input() post: PostEntryResponse;
@Input() burnNFTEntryResponses: NFTEntryResponse[];
@Output() closeModal = new EventEmitter<any>();
@Output() changeTitle = new EventEmitter<string>();
bidAmountDeSo: number;
bidAmountUSD: number;
selectedSerialNumber: NFTEntryResponse = null;
availableCount: number;
availableSerialNumbers: NFTEntryResponse[];
filteredSerialNumbers: NFTEntryResponse[];
highBid: number = null;
lowBid: number = null;
loading = true;
isSelectingSerialNumber = true;
saveSelectionDisabled = false;
showSelectedSerialNumbers = false;
burningNft: boolean = false;
errors: string[] = [];
minBidCurrency: string = "USD";
minBidInput: number = 0;
transferringUser: string;
constructor(
public globalVars: GlobalVarsService,
private backendApi: BackendApiService,
private modalService: BsModalService,
private router: Router,
private toastr: ToastrService,
private location: Location
) {}
ngOnInit(): void {
this.backendApi
.GetNFTCollectionSummary(
this.globalVars.localNode,
this.globalVars.loggedInUser.PublicKeyBase58Check,
this.post.PostHashHex
)
.subscribe((res) => {
this.availableSerialNumbers = _.values(res.SerialNumberToNFTEntryResponse);
this.availableCount = res.NFTCollectionResponse.PostEntryResponse.NumNFTCopiesForSale;
this.filteredSerialNumbers = this.burnNFTEntryResponses;
})
.add(() => (this.loading = false));
}
burnNft() {
this.saveSelectionDisabled = true;
this.burningNft = true;
SwalHelper.fire({
target: this.globalVars.getTargetComponentSelector(),
title: "Burn NFT",
html: `You are about to burn this NFT - this cannot be undone. Are you sure?`,
showConfirmButton: true,
showCancelButton: true,
reverseButtons: true,
customClass: {
confirmButton: "btn btn-light",
cancelButton: "btn btn-light no",
},
confirmButtonText: "Ok",
cancelButtonText: "Cancel",
}).then((res) => {
if (res.isConfirmed) {
this.backendApi
.BurnNFT(
this.globalVars.localNode,
this.globalVars.loggedInUser.PublicKeyBase58Check,
this.post.PostHashHex,
this.selectedSerialNumber.SerialNumber,
this.globalVars.defaultFeeRateNanosPerKB
)
.subscribe(
(res) => {
if (!this.globalVars.isMobile()) {
// Hide this modal and open the next one.
this.closeModal.emit("nft burned");
} else {
this.location.back();
}
this.toastr.show("Your nft was burned", null, {
toastClass: "info-toast",
positionClass: "toast-bottom-center",
});
},
(err) => {
console.error(err);
}
)
.add(() => {
this.burningNft = false;
this.saveSelectionDisabled = false;
});
} else {
this.burningNft = false;
this.saveSelectionDisabled = false;
}
});
}
saveSelection(): void {
if (!this.saveSelectionDisabled) {
this.isSelectingSerialNumber = false;
this.showSelectedSerialNumbers = true;
this.changeTitle.emit("Confirm Transfer");
this.highBid = this.selectedSerialNumber.HighestBidAmountNanos;
this.lowBid = this.selectedSerialNumber.LowestBidAmountNanos;
}
}
goBackToSerialSelection(): void {
this.isSelectingSerialNumber = true;
this.showSelectedSerialNumbers = false;
this.changeTitle.emit("Choose an edition");
this.highBid = null;
this.lowBid = null;
this.selectedSerialNumber = null;
}
selectSerialNumber(serialNumber: NFTEntryResponse) {
this.selectedSerialNumber = serialNumber;
this.saveSelection();
}
bidAmountUSDFormatted() {
return isNumber(this.bidAmountUSD) ? `~${this.globalVars.formatUSD(this.bidAmountUSD, 0)}` : "";
}
bidAmountDeSoFormatted() {
return isNumber(this.bidAmountDeSo) ? `~${this.bidAmountDeSo.toFixed(2)} $DESO` : "";
}
}