@@ -188,7 +188,6 @@ where
188188 Resources :: <T >:: contains_key( ( collection_id, nft_id, resource_id) ) ,
189189 Error :: <T >:: ResourceDoesntExist
190190 ) ;
191-
192191 if pending_resource {
193192 Resources :: < T > :: try_mutate_exists (
194193 ( collection_id, nft_id, resource_id) ,
@@ -200,7 +199,17 @@ where
200199 } ,
201200 ) ?;
202201 } else {
203- Resources :: < T > :: remove ( ( collection_id, nft_id, resource_id) ) ;
202+ match Resources :: < T > :: get ( ( collection_id, nft_id, & resource_id) ) {
203+ None => ( ) ,
204+ Some ( res) => {
205+ Self :: do_remove_resource_from_bases_and_equippable_slots (
206+ res,
207+ collection_id,
208+ nft_id,
209+ resource_id,
210+ ) ;
211+ } ,
212+ }
204213 }
205214
206215 Self :: deposit_event ( Event :: ResourceRemoval { nft_id, resource_id, collection_id } ) ;
@@ -218,17 +227,18 @@ where
218227 Resources :: <T >:: contains_key( ( collection_id, nft_id, & resource_id) ) ,
219228 Error :: <T >:: ResourceDoesntExist
220229 ) ;
221-
222- Resources :: < T > :: try_mutate_exists (
223- ( collection_id, nft_id, resource_id) ,
224- |resource| -> DispatchResult {
225- if let Some ( res) = resource {
226- ensure ! ( res. pending_removal, Error :: <T >:: ResourceNotPending ) ;
227- * resource = None ;
228- }
229- Ok ( ( ) )
230+ match Resources :: < T > :: get ( ( collection_id, nft_id, & resource_id) ) {
231+ None => ( ) ,
232+ Some ( res) => {
233+ ensure ! ( res. pending_removal, Error :: <T >:: ResourceNotPending ) ;
234+ Self :: do_remove_resource_from_bases_and_equippable_slots (
235+ res,
236+ collection_id,
237+ nft_id,
238+ resource_id,
239+ ) ;
230240 } ,
231- ) ? ;
241+ }
232242
233243 Self :: deposit_event ( Event :: ResourceRemovalAccepted { nft_id, resource_id, collection_id } ) ;
234244
@@ -969,4 +979,28 @@ where
969979 ensure ! ( !nft. equipped, Error :: <T >:: CannotSendEquippedItem ) ;
970980 Ok ( ( ) )
971981 }
982+
983+ pub fn do_remove_resource_from_bases_and_equippable_slots (
984+ res : ResourceInfoOf < T > ,
985+ collection_id : CollectionId ,
986+ nft_id : NftId ,
987+ resource_id : ResourceId ,
988+ ) -> ( ) {
989+ match res. resource {
990+ ResourceTypes :: Basic ( _r) => {
991+ Resources :: < T > :: remove ( ( collection_id, nft_id, resource_id) ) ;
992+ } ,
993+ ResourceTypes :: Slot ( r) => {
994+ EquippableSlots :: < T > :: remove ( ( collection_id, nft_id, resource_id, r. base , r. slot ) ) ;
995+ Resources :: < T > :: remove ( ( collection_id, nft_id, resource_id) ) ;
996+ } ,
997+ ResourceTypes :: Composable ( r) => {
998+ EquippableBases :: < T > :: remove ( ( collection_id, nft_id, r. base ) ) ;
999+ if let Some ( ( base, slot) ) = r. slot {
1000+ EquippableSlots :: < T > :: remove ( ( collection_id, nft_id, resource_id, base, slot) ) ;
1001+ } ;
1002+ Resources :: < T > :: remove ( ( collection_id, nft_id, resource_id) ) ;
1003+ } ,
1004+ }
1005+ }
9721006}
0 commit comments