Browse Source

fix: buyProduct success

tongmengxiao 5 months ago
parent
commit
6d26d55b38

+ 7 - 1
user/src/main/java/com/swago/user/store/StoreBuyDialog.kt

@@ -110,7 +110,6 @@ class StoreBuyDialog : BaseXDFragment<DialogStoreDetailBinding>(){
                         return@let
                     }
                     storeVm.buyProduct(it.id)
-                    buySuccessFun?.invoke()
                     dismissAllowingStateLoss()
                 }
 
@@ -119,5 +118,12 @@ class StoreBuyDialog : BaseXDFragment<DialogStoreDetailBinding>(){
         binding.svgContent.setOnClickListener {
             dismissAllowingStateLoss()
         }
+
+        storeVm.buyProductSuccess.observe(this){
+            if (it){
+                buySuccessFun?.invoke()
+            }
+
+        }
     }
 }

+ 8 - 1
user/src/main/java/com/swago/user/vm/StoreVm.kt

@@ -30,17 +30,24 @@ class StoreVm(application: Application) : BaseViewModel(application){
         }
     }
 
+    val buyProductSuccess by lazy {
+        MutableLiveData<Boolean>()
+    }
+
     fun buyProduct(productId:Long){
         requestData2 {
             requestData {
                 ApiManager.userApi.buyProduct(productId)
+                buyProductSuccess.value = true
                 Toast.makeText(
                     AppContext.getContext(),
                     AppContext.getContext().resources.getString(R.string.purchase_successful),
                     Toast.LENGTH_SHORT
                 ).show()
             }
-
+            requestError {
+               buyProductSuccess.value = false
+            }
         }
     }