diff --git a/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/di/ReferralModule.kt b/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/di/ReferralModule.kt index dc3fa9242..8e39b3d49 100644 --- a/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/di/ReferralModule.kt +++ b/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/di/ReferralModule.kt @@ -5,6 +5,7 @@ import com.gemwallet.android.application.referral.coordinators.CreateReferral import com.gemwallet.android.application.referral.coordinators.GetRewards import com.gemwallet.android.application.referral.coordinators.Redeem import com.gemwallet.android.application.referral.coordinators.UseReferralCode +import com.gemwallet.android.cases.device.GetDeviceId import com.gemwallet.android.data.coordinates.referral.CreateReferralImpl import com.gemwallet.android.data.coordinates.referral.GetRewardsImpl import com.gemwallet.android.data.coordinates.referral.RedeemImpl @@ -26,10 +27,12 @@ object ReferralModule { @Singleton fun provideCreateReferral( gemApiClient: GemApiClient, - getAuthPayload: GetAuthPayload + getDeviceId: GetDeviceId, + getAuthPayload: GetAuthPayload, ): CreateReferral { return CreateReferralImpl( gemApiClient = gemApiClient, + getDeviceId = getDeviceId, getAuthPayload = getAuthPayload ) } @@ -38,9 +41,11 @@ object ReferralModule { @Singleton fun provideGetRewards( gemApiClient: GemApiClient, + getDeviceId: GetDeviceId, ): GetRewards { return GetRewardsImpl( gemApiClient = gemApiClient, + getDeviceId = getDeviceId, ) } @@ -49,6 +54,7 @@ object ReferralModule { fun provideRedeem( sessionRepository: SessionRepository, gemApiClient: GemApiClient, + getDeviceId: GetDeviceId, getAuthPayload: GetAuthPayload, tokensRepository: TokensRepository, assetsRepository: AssetsRepository, @@ -56,6 +62,7 @@ object ReferralModule { return RedeemImpl( sessionRepository = sessionRepository, gemApiClient = gemApiClient, + getDeviceId = getDeviceId, getAuthPayload = getAuthPayload, tokensRepository = tokensRepository, assetsRepository = assetsRepository, @@ -66,10 +73,12 @@ object ReferralModule { @Singleton fun provideUseReferralCode( gemApiClient: GemApiClient, + getDeviceId: GetDeviceId, getAuthPayload: GetAuthPayload ): UseReferralCode { return UseReferralCodeImpl( gemApiClient = gemApiClient, + getDeviceId = getDeviceId, getAuthPayload = getAuthPayload ) } diff --git a/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/perpetuals/GetPerpetualBalancesImpl.kt b/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/perpetuals/GetPerpetualBalancesImpl.kt index 1cb4639f5..b240352db 100644 --- a/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/perpetuals/GetPerpetualBalancesImpl.kt +++ b/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/perpetuals/GetPerpetualBalancesImpl.kt @@ -8,6 +8,7 @@ import com.wallet.core.primitives.Currency import com.wallet.core.primitives.PerpetualBalance import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.map @@ -19,6 +20,7 @@ class GetPerpetualBalancesImpl( override fun getPerpetualBalance(): Flow { return sessionRepository.session().map { it?.wallet?.accounts?.map { it.address } ?: emptyList()} + .filter { it.isNotEmpty() } .flatMapLatest { perpetualRepository.getBalances(it) } .map { items -> items.fold( diff --git a/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/referral/CreateReferralImpl.kt b/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/referral/CreateReferralImpl.kt index 8edf7154c..ea336b0be 100644 --- a/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/referral/CreateReferralImpl.kt +++ b/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/referral/CreateReferralImpl.kt @@ -2,6 +2,7 @@ package com.gemwallet.android.data.coordinates.referral import com.gemwallet.android.application.GetAuthPayload import com.gemwallet.android.application.referral.coordinators.CreateReferral +import com.gemwallet.android.cases.device.GetDeviceId import com.gemwallet.android.data.services.gemapi.GemApiClient import com.gemwallet.android.data.services.gemapi.models.ResponseError import com.gemwallet.android.domains.referral.values.ReferralError @@ -17,6 +18,7 @@ import retrofit2.HttpException class CreateReferralImpl( private val gemApiClient: GemApiClient, + private val getDeviceId: GetDeviceId, private val getAuthPayload: GetAuthPayload ) : CreateReferral { @@ -26,7 +28,9 @@ class CreateReferralImpl( val authPayload = getAuthPayload.getAuthPayload(wallet, account.chain) return try { gemApiClient.createReferral( - AuthenticatedRequest( + deviceId = getDeviceId.getDeviceId(), + walletId = wallet.id, + body = AuthenticatedRequest( auth = authPayload, data = ReferralCode( code = code @@ -41,4 +45,4 @@ class CreateReferralImpl( throw err } } -} \ No newline at end of file +} diff --git a/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/referral/GetRewardsImpl.kt b/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/referral/GetRewardsImpl.kt index 7111b24c8..cc87f3cb6 100644 --- a/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/referral/GetRewardsImpl.kt +++ b/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/referral/GetRewardsImpl.kt @@ -1,18 +1,20 @@ package com.gemwallet.android.data.coordinates.referral import com.gemwallet.android.application.referral.coordinators.GetRewards +import com.gemwallet.android.cases.device.GetDeviceId import com.gemwallet.android.data.services.gemapi.GemApiClient import com.gemwallet.android.domains.referral.values.ReferralError import com.wallet.core.primitives.Rewards class GetRewardsImpl( private val gemApiClient: GemApiClient, + private val getDeviceId: GetDeviceId, ) : GetRewards { - override suspend fun getRewards(address: String): Rewards { - val response = gemApiClient.getRewards(address) + override suspend fun getRewards(walletId: String): Rewards { + val response = gemApiClient.getRewards(getDeviceId.getDeviceId(), walletId) if (response.code == null) { throw ReferralError.NotCreated } return response } -} \ No newline at end of file +} diff --git a/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/referral/RedeemImpl.kt b/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/referral/RedeemImpl.kt index 2bfd20435..09a363643 100644 --- a/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/referral/RedeemImpl.kt +++ b/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/referral/RedeemImpl.kt @@ -2,6 +2,7 @@ package com.gemwallet.android.data.coordinates.referral import com.gemwallet.android.application.GetAuthPayload import com.gemwallet.android.application.referral.coordinators.Redeem +import com.gemwallet.android.cases.device.GetDeviceId import com.gemwallet.android.data.repositoreis.assets.AssetsRepository import com.gemwallet.android.data.repositoreis.session.SessionRepository import com.gemwallet.android.data.repositoreis.tokens.TokensRepository @@ -24,6 +25,7 @@ import retrofit2.HttpException class RedeemImpl( private val sessionRepository: SessionRepository, private val gemApiClient: GemApiClient, + private val getDeviceId: GetDeviceId, private val getAuthPayload: GetAuthPayload, private val tokensRepository: TokensRepository, private val assetsRepository: AssetsRepository, @@ -37,7 +39,8 @@ class RedeemImpl( } return try { val result = gemApiClient.redeem( - address = account.address, + deviceId = getDeviceId.getDeviceId(), + walletId = wallet.id, request = AuthenticatedRequest( auth = authPayload, data = RedemptionRequest(option.id) @@ -59,4 +62,4 @@ class RedeemImpl( } } -} \ No newline at end of file +} diff --git a/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/referral/UseReferralCodeImpl.kt b/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/referral/UseReferralCodeImpl.kt index 1fb8d67d2..284aa957f 100644 --- a/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/referral/UseReferralCodeImpl.kt +++ b/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinates/referral/UseReferralCodeImpl.kt @@ -2,6 +2,7 @@ package com.gemwallet.android.data.coordinates.referral import com.gemwallet.android.application.GetAuthPayload import com.gemwallet.android.application.referral.coordinators.UseReferralCode +import com.gemwallet.android.cases.device.GetDeviceId import com.gemwallet.android.data.services.gemapi.GemApiClient import com.gemwallet.android.data.services.gemapi.models.ResponseError import com.gemwallet.android.domains.referral.values.ReferralError @@ -16,6 +17,7 @@ import retrofit2.HttpException class UseReferralCodeImpl( private val gemApiClient: GemApiClient, + private val getDeviceId: GetDeviceId, private val getAuthPayload: GetAuthPayload, ) : UseReferralCode { @@ -25,6 +27,8 @@ class UseReferralCodeImpl( val auth = getAuthPayload.getAuthPayload(wallet, account.chain) return try { gemApiClient.useReferralCode( + deviceId = getDeviceId.getDeviceId(), + walletId = wallet.id, body = AuthenticatedRequest( auth = auth, data = ReferralCode(code) @@ -39,4 +43,4 @@ class UseReferralCodeImpl( throw err } } -} \ No newline at end of file +} diff --git a/data/repositories/src/main/kotlin/com/gemwallet/android/data/repositoreis/assets/AssetsRepository.kt b/data/repositories/src/main/kotlin/com/gemwallet/android/data/repositoreis/assets/AssetsRepository.kt index 7290faf68..ebe5a26bc 100644 --- a/data/repositories/src/main/kotlin/com/gemwallet/android/data/repositoreis/assets/AssetsRepository.kt +++ b/data/repositories/src/main/kotlin/com/gemwallet/android/data/repositoreis/assets/AssetsRepository.kt @@ -310,7 +310,7 @@ class AssetsRepository @Inject constructor( } val availableAssetsId = try { - gemApi.getAssets(getDeviceId.getDeviceId(), wallet.index) + gemApi.getAssets(deviceId = getDeviceId.getDeviceId(), walletId = wallet.id) } catch (_: Throwable) { return@launch } diff --git a/data/repositories/src/main/kotlin/com/gemwallet/android/data/repositoreis/device/DeviceRepository.kt b/data/repositories/src/main/kotlin/com/gemwallet/android/data/repositoreis/device/DeviceRepository.kt index fff01ddc2..c4ac73982 100644 --- a/data/repositories/src/main/kotlin/com/gemwallet/android/data/repositoreis/device/DeviceRepository.kt +++ b/data/repositories/src/main/kotlin/com/gemwallet/android/data/repositoreis/device/DeviceRepository.kt @@ -24,7 +24,7 @@ import com.gemwallet.android.ext.model import com.gemwallet.android.ext.os import com.wallet.core.primitives.ChainAddress import com.wallet.core.primitives.Device -import com.wallet.core.primitives.NewSupportDevice +import com.wallet.core.primitives.SupportDeviceRequest import com.wallet.core.primitives.Platform import com.wallet.core.primitives.PlatformStore import com.wallet.core.primitives.Subscription @@ -107,18 +107,15 @@ class DeviceRepository( currency = getCurrentCurrencyCase.getCurrentCurrency().string, subscriptionsVersion = getSubscriptionVersion(), ) - val register: () -> Unit = { - CoroutineScope(Dispatchers.IO).launch { - callRegisterDevice(device.copy(token = getPushToken())) - } - } if (pushEnabled && pushToken.isEmpty()) { requestPushToken.requestToken { pushToken -> setPushToken(pushToken) - register() + CoroutineScope(Dispatchers.IO).launch { + handlePushToken(pushToken, device) + } } } else { - register() + handlePushToken(pushToken, device) } } @@ -207,36 +204,56 @@ class DeviceRepository( val supportId = UUID.randomUUID().toString().substring(0, 31) try { gemApiClient.registerSupport( - NewSupportDevice( + deviceId = getDeviceId.getDeviceId(), + request = SupportDeviceRequest( supportDeviceId = supportId, - deviceId = getDeviceId.getDeviceId(), ) ) context.dataStore.edit { it[Key.SupportId] = supportId } } catch (_: Throwable) { } } - private suspend fun callRegisterDevice(device: Device) { - val remoteDeviceInfo = try { - gemApiClient.getDevice(device.id) - } catch (_: Throwable) { - null + private suspend fun handlePushToken(pushToken: String, device: Device) { + val device = device.copy(token = pushToken) + + if (isDeviceRegistered(device.id)) { + updateDevice(device) + } else { + registerDevice(device) } + } + + private suspend fun isDeviceRegistered(deviceId: String): Boolean { + val local = context.dataStore.data.map { it[Key.DeviceRegistered] }.firstOrNull() == true + return local || gemApiClient.isDeviceRegistered(deviceId) + } + + private suspend fun registerDevice(device: Device) = try { + gemApiClient.registerDevice(device) + val isRegistered = (gemApiClient.isDeviceRegistered(device.id)) + setDeviceRegistered(isRegistered) + } catch (_: Throwable) {} + + private suspend fun updateDevice(device: Device) { try { - when { - remoteDeviceInfo == null -> gemApiClient.registerDevice(device) - remoteDeviceInfo.hasChanges(device) -> { - val subVersion = max(device.subscriptionsVersion, remoteDeviceInfo.subscriptionsVersion) + 1 - setSubscriptionVersion(subVersion) - gemApiClient.updateDevice( - device.id, - device.copy(subscriptionsVersion = subVersion) - ) - } + val remote = gemApiClient.getDevice(device.id) + + if (remote?.hasChanges(device) == true) { + val subscriptionsVersion = max(device.subscriptionsVersion, remote.subscriptionsVersion) + 1 + setSubscriptionVersion(subscriptionsVersion) + gemApiClient.updateDevice( + deviceId = device.id, + request = device.copy(subscriptionsVersion = subscriptionsVersion) + ) + setDeviceRegistered(true) } } catch (_: Throwable) { } } + private suspend fun setDeviceRegistered(isRegistered: Boolean = true) { + context.dataStore.edit { it[Key.DeviceRegistered] = isRegistered } + } + private suspend fun getRemoteSubscriptions(deviceId: String): List { return try { gemApiClient.getSubscriptions(deviceId) ?: throw Exception() @@ -356,6 +373,7 @@ class DeviceRepository( private object Key { val PushEnabled = booleanPreferencesKey("push_enabled") val SupportId = stringPreferencesKey("support-id") + val DeviceRegistered = booleanPreferencesKey("device_registered") } companion object { diff --git a/data/repositories/src/main/kotlin/com/gemwallet/android/data/repositoreis/nft/NftRepository.kt b/data/repositories/src/main/kotlin/com/gemwallet/android/data/repositoreis/nft/NftRepository.kt index df1d6806c..dcd1c6f75 100644 --- a/data/repositories/src/main/kotlin/com/gemwallet/android/data/repositoreis/nft/NftRepository.kt +++ b/data/repositories/src/main/kotlin/com/gemwallet/android/data/repositoreis/nft/NftRepository.kt @@ -34,7 +34,7 @@ class NftRepository( override suspend fun loadNFT(wallet: Wallet) { val deviceId = getDeviceId.getDeviceId() - val response = gemApiClient.getNFTs(deviceId, wallet.index) + val response = gemApiClient.getNFTs(deviceId = deviceId, walletId = wallet.id) val collections = response.map { DbNFTCollection( id = it.collection.id, diff --git a/data/repositories/src/main/kotlin/com/gemwallet/android/data/repositoreis/transactions/SyncTransactionsService.kt b/data/repositories/src/main/kotlin/com/gemwallet/android/data/repositoreis/transactions/SyncTransactionsService.kt index e9f6c057a..ebd529c6c 100644 --- a/data/repositories/src/main/kotlin/com/gemwallet/android/data/repositoreis/transactions/SyncTransactionsService.kt +++ b/data/repositories/src/main/kotlin/com/gemwallet/android/data/repositoreis/transactions/SyncTransactionsService.kt @@ -24,7 +24,7 @@ class SyncTransactionsService @Inject constructor( val lastSyncTime = getTransactionUpdateTime.getTransactionUpdateTime(wallet.id) / 1000L val response = runCatching { val result: List? = try { - gemApiClient.getTransactions(deviceId, wallet.index, lastSyncTime) + gemApiClient.getTransactions(deviceId, wallet.id, lastSyncTime) } catch (_: Throwable) { null } diff --git a/data/services/remote-gem/src/main/kotlin/com/gemwallet/android/data/services/gemapi/GemApiClient.kt b/data/services/remote-gem/src/main/kotlin/com/gemwallet/android/data/services/gemapi/GemApiClient.kt index 2120f4e7e..3be717d5b 100644 --- a/data/services/remote-gem/src/main/kotlin/com/gemwallet/android/data/services/gemapi/GemApiClient.kt +++ b/data/services/remote-gem/src/main/kotlin/com/gemwallet/android/data/services/gemapi/GemApiClient.kt @@ -18,7 +18,8 @@ import com.wallet.core.primitives.FiatQuoteUrlRequest import com.wallet.core.primitives.FiatQuotes import com.wallet.core.primitives.NFTData import com.wallet.core.primitives.NameRecord -import com.wallet.core.primitives.NewSupportDevice +import com.wallet.core.primitives.ReferralLeaderboard +import com.wallet.core.primitives.RewardRedemptionOption import com.wallet.core.primitives.PriceAlert import com.wallet.core.primitives.RedemptionRequest import com.wallet.core.primitives.RedemptionResult @@ -29,6 +30,7 @@ import com.wallet.core.primitives.ScanTransaction import com.wallet.core.primitives.ScanTransactionPayload import com.wallet.core.primitives.Subscription import com.wallet.core.primitives.SupportDevice +import com.wallet.core.primitives.SupportDeviceRequest import com.wallet.core.primitives.WalletSubscription import com.wallet.core.primitives.WalletSubscriptionChains import retrofit2.http.Body @@ -71,10 +73,10 @@ interface GemApiClient { @GET("/v1/fiat/off_ramp/assets") suspend fun getOffRampAssets(): FiatAssets - @GET("/v1/transactions/device/{device_id}") + @GET("/v1/devices/{device_id}/wallets/{wallet_id}/transactions") suspend fun getTransactions( @Path("device_id") deviceId: String, - @Query("wallet_index") walletIndex: Int, + @Path("wallet_id") walletId: String, @Query("from_timestamp") from: Long ): List @@ -87,8 +89,11 @@ interface GemApiClient { @GET("/v1/devices/{device_id}") suspend fun getDevice(@Path("device_id") deviceId: String): Device? - @POST("/v1/support/add_device") - suspend fun registerSupport(@Body request: NewSupportDevice): SupportDevice + @GET("/v1/devices/{device_id}/is_registered") + suspend fun isDeviceRegistered(@Path("device_id") deviceId: String): Boolean + + @POST("/v1/devices/{device_id}/support") + suspend fun registerSupport(@Path("device_id") deviceId: String, @Body request: SupportDeviceRequest): SupportDevice @PUT("/v1/devices/{device_id}") suspend fun updateDevice(@Path("device_id") deviceId: String, @Body request: Device): Device @@ -102,13 +107,13 @@ interface GemApiClient { @POST("/v1/subscriptions/{device_id}") suspend fun addOldSubscriptions(@Path("device_id") deviceId: String, @Body request: List): Int - @GET("/v2/subscriptions/{device_id}") + @GET("/v1/devices/{device_id}/subscriptions") suspend fun getSubscriptions(@Path("device_id") deviceId: String): List? - @HTTP(method = "DELETE", path = "/v2/subscriptions/{device_id}", hasBody = true) + @HTTP(method = "DELETE", path = "/v1/devices/{device_id}/subscriptions", hasBody = true) suspend fun deleteSubscriptions(@Path("device_id") deviceId: String, @Body request: List): Int - @POST("/v2/subscriptions/{device_id}") + @POST("/v1/devices/{device_id}/subscriptions") suspend fun addSubscriptions(@Path("device_id") deviceId: String, @Body request: List): Int @GET("/v1/charts/{asset_id}") @@ -130,20 +135,20 @@ interface GemApiClient { @Query("tags") tags: String, ): List - @GET("/v1/assets/device/{device_id}") - suspend fun getAssets(@Path("device_id") deviceId: String, @Query("wallet_index") walletIndex: Int, @Query("from_timestamp") fromTimestamp: Int = 0): List + @GET("/v1/devices/{device_id}/wallets/{wallet_id}/assets") + suspend fun getAssets(@Path("device_id") deviceId: String, @Path("wallet_id") walletId: String, @Query("from_timestamp") fromTimestamp: Int = 0): List - @POST("/v1/price_alerts/{device_id}") + @POST("/v1/devices/{device_id}/price_alerts") suspend fun includePriceAlert(@Path("device_id") deviceId: String, @Body alerts: List): String - @HTTP(method = "DELETE", path = "/v1/price_alerts/{device_id}", hasBody = true) + @HTTP(method = "DELETE", path = "/v1/devices/{device_id}/price_alerts", hasBody = true) suspend fun excludePriceAlert(@Path("device_id") deviceId: String, @Body assets: List): String - @GET("/v1/price_alerts/{device_id}") + @GET("/v1/devices/{device_id}/price_alerts") suspend fun getPriceAlerts(@Path("device_id") deviceId: String): List - @GET("/v2/nft/assets/device/{device_id}") - suspend fun getNFTs(@Path("device_id") deviceId: String, @Query("wallet_index") walletIndex: Int): List + @GET("/v1/devices/{device_id}/wallets/{wallet_id}/nft_assets") + suspend fun getNFTs(@Path("device_id") deviceId: String, @Path("wallet_id") walletId: String): List @POST("/v2/scan/transaction") suspend fun getScanTransaction(@Body payload: ScanTransactionPayload): ScanTransaction @@ -151,15 +156,24 @@ interface GemApiClient { @GET("/v1/devices/{device_id}/auth/nonce") suspend fun getAuthNonce(@Path("device_id")deviceId: String): AuthNonce - @GET("/v1/rewards/{address}") - suspend fun getRewards(@Path("address") address: String): Rewards + @GET("/v1/devices/{device_id}/wallets/{wallet_id}/rewards") + suspend fun getRewards(@Path("device_id") deviceId: String, @Path("wallet_id") walletId: String): Rewards + + @GET("/v1/devices/{device_id}/wallets/{wallet_id}/rewards/events") + suspend fun getRewardsEvents(@Path("device_id") deviceId: String, @Path("wallet_id") walletId: String): List + + @GET("/v1/devices/{device_id}/rewards/leaderboard") + suspend fun getRewardsLeaderboard(@Path("device_id") deviceId: String): ReferralLeaderboard + + @GET("/v1/devices/{device_id}/rewards/redemptions/{code}") + suspend fun getRedemptionOption(@Path("device_id") deviceId: String, @Path("code") code: String): RewardRedemptionOption - @POST("/v1/rewards/referrals/create") - suspend fun createReferral(@Body body: AuthenticatedRequest): Rewards + @POST("/v1/devices/{device_id}/wallets/{wallet_id}/rewards/referrals/create") + suspend fun createReferral(@Path("device_id") deviceId: String, @Path("wallet_id") walletId: String, @Body body: AuthenticatedRequest): Rewards - @POST("/v1/rewards/referrals/use") - suspend fun useReferralCode(@Body body: AuthenticatedRequest): List + @POST("/v1/devices/{device_id}/wallets/{wallet_id}/rewards/referrals/use") + suspend fun useReferralCode(@Path("device_id") deviceId: String, @Path("wallet_id") walletId: String, @Body body: AuthenticatedRequest): List - @POST("/v1/rewards/{address}/redeem") - suspend fun redeem(@Path("address") address: String, @Body request: AuthenticatedRequest): RedemptionResult + @POST("/v1/devices/{device_id}/wallets/{wallet_id}/rewards/redeem") + suspend fun redeem(@Path("device_id") deviceId: String, @Path("wallet_id") walletId: String, @Body request: AuthenticatedRequest): RedemptionResult } \ No newline at end of file diff --git a/features/referral/viewmodels/src/main/kotlin/com/gemwallet/features/referral/viewmodels/ReferralViewModel.kt b/features/referral/viewmodels/src/main/kotlin/com/gemwallet/features/referral/viewmodels/ReferralViewModel.kt index a867f0e40..912606078 100644 --- a/features/referral/viewmodels/src/main/kotlin/com/gemwallet/features/referral/viewmodels/ReferralViewModel.kt +++ b/features/referral/viewmodels/src/main/kotlin/com/gemwallet/features/referral/viewmodels/ReferralViewModel.kt @@ -9,10 +9,6 @@ import com.gemwallet.android.application.referral.coordinators.Redeem import com.gemwallet.android.application.referral.coordinators.UseReferralCode import com.gemwallet.android.data.repositoreis.session.SessionRepository import com.gemwallet.android.data.repositoreis.wallets.WalletsRepository -import com.gemwallet.android.ext.getAccount -import com.gemwallet.android.ext.referralChain -import com.wallet.core.primitives.Account -import com.wallet.core.primitives.Chain import com.wallet.core.primitives.RewardRedemptionOption import com.wallet.core.primitives.Rewards import com.wallet.core.primitives.Wallet @@ -35,8 +31,8 @@ import javax.inject.Inject @OptIn(ExperimentalCoroutinesApi::class) @HiltViewModel class ReferralViewModel @Inject constructor( - private val sessionRepository: SessionRepository, - private val walletsRepository: WalletsRepository, + sessionRepository: SessionRepository, + walletsRepository: WalletsRepository, private val getRewards: GetRewards, private val redeem: Redeem, private val useReferralCode: UseReferralCode, @@ -74,10 +70,7 @@ class ReferralViewModel @Inject constructor( } }.stateIn(viewModelScope, SharingStarted.Eagerly, null) - private val referralAccount = currentWallet.filterNotNull().mapLatest { wallet -> - wallet.getAccount(Chain.referralChain) ?: return@mapLatest null - } - .filterNotNull() + private val referralWallet = currentWallet.filterNotNull() .onEach { sync(it, SyncType.Init) } .stateIn(viewModelScope, SharingStarted.Eagerly, null) @@ -86,13 +79,13 @@ class ReferralViewModel @Inject constructor( } fun sync() { - sync(referralAccount.value ?: return, SyncType.Refresh) + sync(referralWallet.value ?: return, SyncType.Refresh) } - private fun sync(account: Account, type: SyncType) = viewModelScope.launch(Dispatchers.IO) { + private fun sync(wallet: Wallet, type: SyncType) = viewModelScope.launch(Dispatchers.IO) { inSync.update { type } val rewards = try { - getRewards.getRewards(account.address) + getRewards.getRewards(wallet.id) } catch (_: Exception) { null } finally { @@ -145,4 +138,4 @@ class ReferralViewModel @Inject constructor( fun cancelCode() { savedStateHandle["code"] = null } -} \ No newline at end of file +} diff --git a/gemcore/src/main/kotlin/com/gemwallet/android/application/referral/coordinators/CreateReferral.kt b/gemcore/src/main/kotlin/com/gemwallet/android/application/referral/coordinators/CreateReferral.kt index b7d4d9f86..a6e34e153 100644 --- a/gemcore/src/main/kotlin/com/gemwallet/android/application/referral/coordinators/CreateReferral.kt +++ b/gemcore/src/main/kotlin/com/gemwallet/android/application/referral/coordinators/CreateReferral.kt @@ -5,4 +5,4 @@ import com.wallet.core.primitives.Wallet interface CreateReferral { suspend fun createReferral(code: String, wallet: Wallet): Rewards -} \ No newline at end of file +} diff --git a/gemcore/src/main/kotlin/com/gemwallet/android/application/referral/coordinators/GetRewards.kt b/gemcore/src/main/kotlin/com/gemwallet/android/application/referral/coordinators/GetRewards.kt index 4e851cf4b..e42abb22f 100644 --- a/gemcore/src/main/kotlin/com/gemwallet/android/application/referral/coordinators/GetRewards.kt +++ b/gemcore/src/main/kotlin/com/gemwallet/android/application/referral/coordinators/GetRewards.kt @@ -3,5 +3,5 @@ package com.gemwallet.android.application.referral.coordinators import com.wallet.core.primitives.Rewards interface GetRewards { - suspend fun getRewards(address: String): Rewards -} \ No newline at end of file + suspend fun getRewards(walletId: String): Rewards +} diff --git a/gemcore/src/main/kotlin/com/gemwallet/android/application/referral/coordinators/Redeem.kt b/gemcore/src/main/kotlin/com/gemwallet/android/application/referral/coordinators/Redeem.kt index 7e190c9c8..33371154f 100644 --- a/gemcore/src/main/kotlin/com/gemwallet/android/application/referral/coordinators/Redeem.kt +++ b/gemcore/src/main/kotlin/com/gemwallet/android/application/referral/coordinators/Redeem.kt @@ -7,4 +7,4 @@ import com.wallet.core.primitives.Wallet interface Redeem { suspend fun redeem(wallet: Wallet, rewards: Rewards, option: RewardRedemptionOption): RedemptionResult -} \ No newline at end of file +} diff --git a/gemcore/src/main/kotlin/com/gemwallet/android/application/referral/coordinators/UseReferralCode.kt b/gemcore/src/main/kotlin/com/gemwallet/android/application/referral/coordinators/UseReferralCode.kt index 1f56223af..f76ed28e6 100644 --- a/gemcore/src/main/kotlin/com/gemwallet/android/application/referral/coordinators/UseReferralCode.kt +++ b/gemcore/src/main/kotlin/com/gemwallet/android/application/referral/coordinators/UseReferralCode.kt @@ -4,4 +4,4 @@ import com.wallet.core.primitives.Wallet interface UseReferralCode { suspend fun useReferralCode(code: String, wallet: Wallet): Boolean -} \ No newline at end of file +} diff --git a/gemcore/src/main/kotlin/com/wallet/core/primitives/Support.kt b/gemcore/src/main/kotlin/com/wallet/core/primitives/Support.kt index a7f852f63..44181ec9b 100644 --- a/gemcore/src/main/kotlin/com/wallet/core/primitives/Support.kt +++ b/gemcore/src/main/kotlin/com/wallet/core/primitives/Support.kt @@ -19,3 +19,8 @@ data class SupportDevice ( val unread: Int ) +@Serializable +data class SupportDeviceRequest ( + val supportDeviceId: String +) +