1212 </option >
1313 </b-select >
1414 </b-field >
15- <b-field v-if =" showMeta" label =" Meta" >
16- <b-input v-model =" meta" ></b-input >
17- </b-field >
15+ <component v-if =" showMeta" :is =" showMeta" @input =" updateMeta" />
1816 <b-button
1917 v-if =" showSubmit"
2018 type =" is-primary"
@@ -32,24 +30,34 @@ import Connector from '@vue-polkadot/vue-api';
3230import exec , { execResultValue } from ' @/utils/transactionExecutor' ;
3331import { notificationTypes , showNotification } from ' @/utils/notification' ;
3432import { getInstance , RmrkType } from ' ../service/RmrkService' ;
33+ import { unpin } from ' @/pinata' ;
34+ import Consolidator from ' ../service/Consolidator' ;
3535import RmrkVersionMixin from ' @/utils/mixins/rmrkVersionMixin' ;
3636
3737const ownerActions = [' SEND' , ' CONSUME' , ' LIST' ];
3838const buyActions = [' BUY' ];
3939
40- const needMeta: Record <string , boolean > = {
41- SEND: true ,
42- LIST: true
40+ const needMeta: Record <string , string > = {
41+ SEND: ' AddressInput ' ,
42+ LIST: ' BalanceInput '
4343};
4444
45- @Component ({})
45+ const components = {
46+ BalanceInput : () => import (' @/components/shared/BalanceInput.vue' ),
47+ AddressInput : () => import (' @/components/shared/AddressInput.vue' )
48+ }
49+
50+ @Component ({ components })
4651export default class AvailableActions extends Mixins (RmrkVersionMixin ) {
4752 @Prop () public currentOwnerId! : string ;
4853 @Prop () public accountId! : string ;
4954 @Prop () public price! : string ;
5055 @Prop () public nftId! : string ;
56+ @Prop () public imageHash! : string ;
57+ @Prop () public metadataHash! : string ;
58+ @Prop () public animationHash! : string ;
5159 private selectedAction: string = ' ' ;
52- private meta: string = ' ' ;
60+ private meta: string | number = ' ' ;
5361 private isLoading: boolean = false ;
5462
5563 get actions() {
@@ -90,20 +98,27 @@ export default class AvailableActions extends Mixins(RmrkVersionMixin) {
9098 } ` ;
9199 }
92100
93- private async submit() {
101+ protected updateMeta(value : string | number ) {
102+ this .meta = value ;
103+ }
104+
105+ protected async submit() {
94106 const { api } = Connector .getInstance ();
95107 const rmrkService = getInstance ();
96108 const rmrk = this .constructRmrk ();
97109 try {
98110 showNotification (rmrk )
99111 console .log (' submit' , rmrk );
100- const isSend = this .selectedAction === ' SEND ' ;
101- const cb = isSend ? api .tx .utility .batch : api .tx .system .remark
102- const arg = isSend ? [api .tx .system .remark (rmrk ), api .tx .balances .transfer (this .currentOwnerId , this .price )] : rmrk
112+ const isBuy = this .selectedAction === ' BUY ' ;
113+ const cb = isBuy ? api .tx .utility .batch : api .tx .system .remark
114+ const arg = isBuy ? [api .tx .system .remark (rmrk ), api .tx .balances .transfer (this .currentOwnerId , this .price )] : rmrk
103115 const tx = await exec (this .accountId , ' ' , cb , [arg ]);
104116 showNotification (execResultValue (tx ), notificationTypes .success )
105117 console .warn (' TX IN' , tx );
106118 const persisted = await rmrkService ?.resolve (rmrk , this .accountId );
119+ if (this .selectedAction === ' CONSUME' ) {
120+ this .unpinNFT ()
121+ }
107122 console .log (persisted )
108123 console .log (' SAVED' , persisted ?._id );
109124 showNotification (` [TEXTILE] ${persisted ?._id } ` , notificationTypes .success )
@@ -112,5 +127,34 @@ export default class AvailableActions extends Mixins(RmrkVersionMixin) {
112127 console .error (e );
113128 }
114129 }
130+
131+ protected unpinNFT() {
132+ [this .imageHash , this .metadataHash , this .animationHash ]
133+ .forEach (async hash => {
134+ if (hash ) {
135+ try {
136+ await unpin (hash )
137+ } catch (e ) {
138+ console .warn (` [ACTIONS] Cannot Unpin ${hash } because: ${e } ` )
139+ }
140+ }
141+ })
142+
143+ }
144+
145+ protected async consolidate(): Promise <boolean > {
146+ const rmrkService = getInstance ();
147+ await rmrkService ?.checkExpiredOrElseRefresh ()
148+
149+ if (! rmrkService ) {
150+ console .warn (' NO RMRK SERVICE, Live your life on the edge' )
151+ return true ;
152+ }
153+
154+ const nft = await rmrkService ?.getNFT (this .nftId )
155+ return Consolidator .consolidate (this .selectedAction , nft , this .currentOwnerId , this .accountId )
156+ }
157+
158+
115159}
116160 </script >
0 commit comments