33 <div class =" box" >
44 <b-loading is-full-page v-model =" isLoading" :can-cancel =" true" ></b-loading >
55 <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')" >
713 <b-select placeholder =" Select a collection" v-model =" selectedCollection" expanded >
814 <option v-for =" option in data" :value =" option" :key =" option.id" >
915 {{ option.name }} {{ option.id }}
1016 </option >
1117 </b-select >
1218 <Tooltip :label =" $i18n.t('Select collection where do you want mint your token')" />
1319 </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 >
1425 <b-field >
1526 <PasswordInput v-if =" canSubmit" v-model =" password" :account =" accountId" />
1627 </b-field >
2839 <b-field grouped >
2940 <b-field position =" is-left" expanded >
3041 <b-button
31- v-if =" selectedCollection"
42+ v-if =" accountId && ( selectedCollection || singleNFTValid) "
3243 type =" is-info"
3344 icon-left =" plus"
3445 @click =" handleAdd"
@@ -64,13 +75,13 @@ import {
6475 Collection ,
6576 NFT ,
6677 NFTMetadata ,
67- NFTWithMeta ,
68- getNftId
6978} from ' ../service/scheme' ;
7079import { pinFile , pinJson , unSanitizeIpfsUrl } from ' @/pinata' ;
7180import PasswordInput from ' @/components/shared/PasswordInput.vue' ;
7281import slugify from ' slugify'
7382import { fetchCollectionMetadata } from ' ../utils' ;
83+ import { generateId } from ' @/components/rmrk/service/Consolidator'
84+ import NFTUtils from ' ../service/NftUtils' ;
7485
7586const shouldUpdate = (val : string , oldVal : string ) => val && val !== oldVal ;
7687
@@ -97,6 +108,8 @@ export default class CreateToken extends Vue {
97108 private isLoading: boolean = false ;
98109 private password: string = ' ' ;
99110 private alreadyMinted = 0 ;
111+ private oneByOne: boolean = true ;
112+ private symbol: string = ' ' ;
100113
101114 @Watch (' accountId' )
102115 hasAccount(value : string , oldVal : string ) {
@@ -136,8 +149,13 @@ export default class CreateToken extends Vue {
136149 return this .added .length
137150 }
138151
152+ get singleNFTValid() {
153+ return this .oneByOne && this .symbol
154+ }
155+
139156 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 ;
141159 }
142160
143161 private handleUpdate(item : { view: NFTAndMeta ; index: number }) {
@@ -162,8 +180,6 @@ export default class CreateToken extends Vue {
162180 ... nftForMint ,
163181 metadata: metaHash ,
164182 currentOwner: this .accountId ,
165- // id,
166- // _id: id,
167183 transferable: Number (nftForMint .transferable ),
168184 instance: slugify (nftForMint .name , ' _' ).toUpperCase ()
169185 };
@@ -209,16 +225,21 @@ export default class CreateToken extends Vue {
209225 return unSanitizeIpfsUrl (metaHash );
210226 }
211227
212- private async submit() {
228+ protected async submit() {
213229 this .isLoading = true ;
214230 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 )] : []
220241
221- const batchMethods: any [] = remarks .map (this .toRemark )
242+ const batchMethods = [ ... collectionToMint . map ( this . toRemark ), ... remarks .map (this .toRemark )]
222243 console .log (' batchMethods' , batchMethods )
223244 const rmrkService = getInstance ();
224245
@@ -233,7 +254,7 @@ export default class CreateToken extends Vue {
233254 execResultValue (tx )
234255 const header = await api .rpc .chain .getHeader (result .status .asFinalized );
235256 const blockNumber = header .number .toString ();
236- remarks . forEach ( async ( rmrk , index ) => {
257+ for ( const [index, rmrk] of [ ... collectionToMint , ... remarks ]. entries ()) {
237258 this .isLoading = true ;
238259 try {
239260 const res = await rmrkService ?.resolve (rmrk , this .accountId , blockNumber )
@@ -243,7 +264,7 @@ export default class CreateToken extends Vue {
243264 console .warn (` Failed Indexing ${index } with err ${e } ` );
244265 }
245266 this .isLoading = false ;
246- })
267+ }
247268 }
248269 });
249270 console .warn (' TX IN' , tx );
@@ -259,7 +280,7 @@ export default class CreateToken extends Vue {
259280
260281 protected handleAdd() {
261282 const rmrk = emptyObject <NFTAndMeta >();
262- rmrk .collection = this .selectedCollection ?.id || ' ' ;
283+ rmrk .collection = this .oneByOne ? generateId ( this . accountId , this . symbol ) : this . selectedCollection ?.id || ' ' ;
263284 rmrk .sn = this .calculateSerialNumber (this .added .length );
264285 rmrk .meta = emptyObject <NFTMetadata >();
265286 rmrk .transferable = 1 ;
0 commit comments