@@ -744,7 +744,11 @@ pub mod pallet {
744744 . checked_sub ( amount)
745745 . ok_or ( ArithmeticError :: Underflow ) ?
746746 } ;
747- Self :: contribution_put ( vault. trie_index , who, & new_pending, true ) ;
747+ if new_pending. is_zero ( ) {
748+ Self :: contribution_kill ( vault. trie_index , who, true ) ;
749+ } else {
750+ Self :: contribution_put ( vault. trie_index , who, & new_pending, true ) ;
751+ }
748752 Ok ( ( ) )
749753 }
750754
@@ -754,25 +758,12 @@ pub mod pallet {
754758 vault : & mut Vault < T > ,
755759 amount : BalanceOf < T > ,
756760 ) -> DispatchResult {
757- vault. pending = vault
758- . pending
759- . checked_sub ( amount)
760- . ok_or ( ArithmeticError :: Underflow ) ?;
761+ Self :: do_update_pending ( who, vault, amount, false ) ?;
762+
761763 vault. contributed = vault
762764 . contributed
763765 . checked_add ( amount)
764766 . ok_or ( ArithmeticError :: Overflow ) ?;
765-
766- let ( pending, _) = Self :: contribution_get ( vault. trie_index , who, true ) ;
767- let new_pending = pending
768- . checked_sub ( amount)
769- . ok_or ( ArithmeticError :: Underflow ) ?;
770- if new_pending. is_zero ( ) {
771- Self :: contribution_kill ( vault. trie_index , who, true ) ;
772- } else {
773- Self :: contribution_put ( vault. trie_index , who, & new_pending, true ) ;
774- }
775-
776767 let ( contributed, _) = Self :: contribution_get ( vault. trie_index , who, false ) ;
777768 let new_contributed = contributed
778769 . checked_add ( amount)
0 commit comments