3
3
<div class =" box" >
4
4
<b-loading is-full-page v-model =" isLoading" :can-cancel =" true" ></b-loading >
5
5
<AccountSelect :label =" $i18n.t('Account')" v-model =" accountId" />
6
- <b-field grouped v-if =" accountId" :label =" $i18n.t('Collection')" >
6
+ <template v-if =" accountId " >
7
+ <b-switch v-model =" oneByOne"
8
+ passive-type =" is-dark"
9
+ :rounded =" false" >
10
+ {{ oneByOne ? 'Single NFT' : 'NFT(s) in collection' }}
11
+ </b-switch >
12
+ <b-field grouped v-if =" !oneByOne" :label =" $i18n.t('Collection')" >
7
13
<b-select placeholder =" Select a collection" v-model =" selectedCollection" expanded >
8
14
<option v-for =" option in data" :value =" option" :key =" option.id" >
9
15
{{ option.name }} {{ option.id }}
10
16
</option >
11
17
</b-select >
12
18
<Tooltip :label =" $i18n.t('Select collection where do you want mint your token')" />
13
19
</b-field >
20
+ <b-field v-else grouped :label =" $i18n.t('Symbol')" >
21
+ <b-input v-model =" symbol" expanded ></b-input >
22
+ <Tooltip :label =" $i18n.t('Symbol you want to trade it under')" />
23
+ </b-field >
24
+ </template >
14
25
<b-field >
15
26
<PasswordInput v-if =" canSubmit" v-model =" password" :account =" accountId" />
16
27
</b-field >
28
39
<b-field grouped >
29
40
<b-field position =" is-left" expanded >
30
41
<b-button
31
- v-if =" selectedCollection"
42
+ v-if =" accountId && ( selectedCollection || singleNFTValid) "
32
43
type =" is-info"
33
44
icon-left =" plus"
34
45
@click =" handleAdd"
@@ -64,13 +75,13 @@ import {
64
75
Collection ,
65
76
NFT ,
66
77
NFTMetadata ,
67
- NFTWithMeta ,
68
- getNftId
69
78
} from ' ../service/scheme' ;
70
79
import { pinFile , pinJson , unSanitizeIpfsUrl } from ' @/pinata' ;
71
80
import PasswordInput from ' @/components/shared/PasswordInput.vue' ;
72
81
import slugify from ' slugify'
73
82
import { fetchCollectionMetadata } from ' ../utils' ;
83
+ import { generateId } from ' @/components/rmrk/service/Consolidator'
84
+ import NFTUtils from ' ../service/NftUtils' ;
74
85
75
86
const shouldUpdate = (val : string , oldVal : string ) => val && val !== oldVal ;
76
87
@@ -97,6 +108,8 @@ export default class CreateToken extends Vue {
97
108
private isLoading: boolean = false ;
98
109
private password: string = ' ' ;
99
110
private alreadyMinted = 0 ;
111
+ private oneByOne: boolean = true ;
112
+ private symbol: string = ' ' ;
100
113
101
114
@Watch (' accountId' )
102
115
hasAccount(value : string , oldVal : string ) {
@@ -136,8 +149,13 @@ export default class CreateToken extends Vue {
136
149
return this .added .length
137
150
}
138
151
152
+ get singleNFTValid() {
153
+ return this .oneByOne && this .symbol
154
+ }
155
+
139
156
get disabled() {
140
- return this .selectedCollection ?.max === this .added .length + this .alreadyMinted ;
157
+ const max = this .oneByOne ? 1 : this .selectedCollection ?.max
158
+ return max === this .added .length + this .alreadyMinted ;
141
159
}
142
160
143
161
private handleUpdate(item : { view: NFTAndMeta ; index: number }) {
@@ -162,8 +180,6 @@ export default class CreateToken extends Vue {
162
180
... nftForMint ,
163
181
metadata: metaHash ,
164
182
currentOwner: this .accountId ,
165
- // id,
166
- // _id: id,
167
183
transferable: Number (nftForMint .transferable ),
168
184
instance: slugify (nftForMint .name , ' _' ).toUpperCase ()
169
185
};
@@ -209,16 +225,21 @@ export default class CreateToken extends Vue {
209
225
return unSanitizeIpfsUrl (metaHash );
210
226
}
211
227
212
- private async submit() {
228
+ protected async submit() {
213
229
this .isLoading = true ;
214
230
const { api } = Connector .getInstance ();
215
- const remarks: string [] = await Promise .all (this .added
216
- .map (this .makeItSexy )
217
- .map (async mint => this .toMintFormat (await mint )
218
- ));
219
- console .log (' remarks' , remarks );
231
+ const nfts: NFT [] = await Promise .all (this .added .map (this .makeItSexy ));
232
+
233
+ const remarks: string [] = nfts .map (this .toMintFormat )
234
+
235
+ if (! remarks .length ) {
236
+ throw new RangeError (' Unable to process empty NFTs!' )
237
+ }
238
+
239
+ const firstNFT = nfts [0 ];
240
+ const collectionToMint: string [] = this .oneByOne ? [NFTUtils .encodeCollection (NFTUtils .collectionFromNFT (this .symbol , firstNFT , this .version ), this .version )] : []
220
241
221
- const batchMethods: any [] = remarks .map (this .toRemark )
242
+ const batchMethods = [ ... collectionToMint . map ( this . toRemark ), ... remarks .map (this .toRemark )]
222
243
console .log (' batchMethods' , batchMethods )
223
244
const rmrkService = getInstance ();
224
245
@@ -233,7 +254,7 @@ export default class CreateToken extends Vue {
233
254
execResultValue (tx )
234
255
const header = await api .rpc .chain .getHeader (result .status .asFinalized );
235
256
const blockNumber = header .number .toString ();
236
- remarks . forEach ( async ( rmrk , index ) => {
257
+ for ( const [index, rmrk] of [ ... collectionToMint , ... remarks ]. entries ()) {
237
258
this .isLoading = true ;
238
259
try {
239
260
const res = await rmrkService ?.resolve (rmrk , this .accountId , blockNumber )
@@ -243,7 +264,7 @@ export default class CreateToken extends Vue {
243
264
console .warn (` Failed Indexing ${index } with err ${e } ` );
244
265
}
245
266
this .isLoading = false ;
246
- })
267
+ }
247
268
}
248
269
});
249
270
console .warn (' TX IN' , tx );
@@ -259,7 +280,7 @@ export default class CreateToken extends Vue {
259
280
260
281
protected handleAdd() {
261
282
const rmrk = emptyObject <NFTAndMeta >();
262
- rmrk .collection = this .selectedCollection ?.id || ' ' ;
283
+ rmrk .collection = this .oneByOne ? generateId ( this . accountId , this . symbol ) : this . selectedCollection ?.id || ' ' ;
263
284
rmrk .sn = this .calculateSerialNumber (this .added .length );
264
285
rmrk .meta = emptyObject <NFTMetadata >();
265
286
rmrk .transferable = 1 ;
0 commit comments