Skip to content

Commit

Permalink
iap: add success toast & update balance (#79)
Browse files Browse the repository at this point in the history
* iap: add success toast & update balance

* add consumeProduct
  • Loading branch information
sorokin0andrey authored Oct 1, 2024
1 parent fa6b4cd commit d6efd32
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ class BillingManager(
billingClient.launchBillingFlow(activity, billingFlowParams)
}

suspend fun consumeProduct(purchase: Purchase) {
val params = ConsumeParams.newBuilder().setPurchaseToken(purchase.purchaseToken).build()
billingClient.consumePurchase(params)
}

suspend fun restorePurchases() {
val params = QueryPurchasesParams.newBuilder()
.setProductType(ProductType.INAPP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ class BatteryRefillViewModel(
)
try {
api.battery(wallet.testnet).androidBatteryPurchase(tonProofToken, request)
billingManager.consumeProduct(purchase)
batteryRepository.getBalance(tonProofToken, wallet.publicKey, wallet.testnet, ignoreCache = true)
context.showToast(Localization.battery_refilled)
} catch (e: Exception) {
purchaseInProgress.tryEmit(false)
context.showToast(Localization.error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,4 +493,5 @@
<string name="backup_alert_message">Ваш баланс составляет %1$s, и он защищен только фразой восстановления, которую вы еще не записали. Сделайте резервную копию фразы, чтобы избежать потери средств в случае проблем с устройством.</string>
<string name="battery_disclaimer">Один заряд покрывает среднюю комиссию за транзакцию. Некоторые транзакции могут стоить дороже.</string>
<string name="restore_purchases">Восстановить покупки</string>
<string name="battery_refilled">Батарейка заряжена</string>
</resources>
1 change: 1 addition & 0 deletions apps/wallet/localization/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -518,4 +518,5 @@
<string name="battery_small_pack">Small</string>
<string name="battery_disclaimer">One charge covers the average transaction fee. Some transactions may cost more.</string>
<string name="restore_purchases">Restore Purchases</string>
<string name="battery_refilled">Battery refilled</string>
</resources>

0 comments on commit d6efd32

Please sign in to comment.