Skip to content

Commit 2b45a9e

Browse files
committed
Merge branch 'dev' of github.com:tonkeeper/android_private into dev
2 parents ec6e041 + d8aa65f commit 2b45a9e

File tree

106 files changed

+1198
-563
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+1198
-563
lines changed

.github/workflows/cd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ jobs:
3232

3333
- name: Decode signing certificate into a file
3434
env:
35-
CERTIFICATE_BASE64: ${{ secrets.ANDROID_DIST_SIGNING_KEY }}
35+
CERTIFICATE_BASE64: ${{ secrets.ANDROID_DIST_SIGNING_KEY }}
3636
run: |
37-
echo $CERTIFICATE_BASE64 | base64 --decode > google-release.keystore
37+
echo $CERTIFICATE_BASE64 | base64 --decode > google-release.keystore
3838
3939
- name: Build android beta
4040
run: bundle exec fastlane android beta

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,4 @@ RUBY VERSION
222222
ruby 3.3.0p0
223223

224224
BUNDLED WITH
225-
2.5.4
225+
2.5.4

apps/signer/build.gradle.kts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
13
plugins {
24
id("com.android.application")
35
id("org.jetbrains.kotlin.android")
@@ -43,15 +45,6 @@ android {
4345
}
4446
}
4547

46-
compileOptions {
47-
sourceCompatibility = JavaVersion.VERSION_1_8
48-
targetCompatibility = JavaVersion.VERSION_1_8
49-
}
50-
51-
kotlinOptions {
52-
jvmTarget = "1.8"
53-
}
54-
5548
packaging {
5649
resources.excludes.add("/META-INF/{AL2.0,LGPL2.1}")
5750
}

apps/wallet/api/build.gradle.kts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
13
plugins {
24
id("com.android.library")
35
id("org.jetbrains.kotlin.android")
@@ -14,14 +16,6 @@ android {
1416
minSdk = Build.minSdkVersion
1517
consumerProguardFiles("consumer-rules.pro")
1618
}
17-
18-
compileOptions {
19-
sourceCompatibility = JavaVersion.VERSION_1_8
20-
targetCompatibility = JavaVersion.VERSION_1_8
21-
}
22-
kotlinOptions {
23-
jvmTarget = "1.8"
24-
}
2519
}
2620

2721
dependencies {

apps/wallet/api/src/main/java/com/tonapps/wallet/api/API.kt

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@ import com.tonapps.wallet.api.entity.ConfigEntity
2828
import com.tonapps.wallet.api.entity.EthenaEntity
2929
import com.tonapps.wallet.api.entity.OnRampArgsEntity
3030
import com.tonapps.wallet.api.entity.OnRampMerchantEntity
31-
import com.tonapps.wallet.api.entity.SwapEntity
3231
import com.tonapps.wallet.api.entity.TokenEntity
3332
import com.tonapps.wallet.api.entity.value.Timestamp
3433
import com.tonapps.wallet.api.internal.ConfigRepository
3534
import com.tonapps.wallet.api.internal.InternalApi
3635
import com.tonapps.wallet.api.internal.SwapApi
3736
import com.tonapps.wallet.api.tron.TronApi
38-
import com.tonapps.wallet.api.tron.entity.TronEventEntity
3937
import io.Serializer
4038
import io.batteryapi.apis.DefaultApi
4139
import io.batteryapi.models.Balance
@@ -61,8 +59,6 @@ import kotlinx.coroutines.delay
6159
import kotlinx.coroutines.flow.Flow
6260
import kotlinx.coroutines.flow.emptyFlow
6361
import kotlinx.coroutines.flow.filter
64-
import kotlinx.coroutines.flow.filterNotNull
65-
import kotlinx.coroutines.flow.map
6662
import kotlinx.coroutines.withContext
6763
import okhttp3.MediaType.Companion.toMediaType
6864
import okhttp3.OkHttpClient
@@ -191,19 +187,19 @@ class API(
191187
return withRetry { battery(testnet).getRechargeMethods(false) }
192188
}
193189

194-
fun getOnRampData() = internalApi.getOnRampData()
190+
fun getOnRampData() = internalApi.getOnRampData(config.webSwapsUrl)
195191

196-
fun getOnRampPaymentMethods(currency: String) = internalApi.getOnRampPaymentMethods(currency)
192+
fun getOnRampPaymentMethods(currency: String) = internalApi.getOnRampPaymentMethods(config.webSwapsUrl, currency)
197193

198-
fun getOnRampMerchants() = internalApi.getOnRampMerchants()
194+
fun getOnRampMerchants() = internalApi.getOnRampMerchants(config.webSwapsUrl)
199195

200196
fun getSwapAssets(): JSONArray = runCatching {
201-
swapApi.getSwapAssets()?.let(::JSONArray)
197+
swapApi.getSwapAssets(config.webSwapsUrl)?.let(::JSONArray)
202198
}.getOrNull() ?: JSONArray()
203199

204200
@Throws
205201
suspend fun calculateOnRamp(args: OnRampArgsEntity): OnRampMerchantEntity.Data = withContext(Dispatchers.IO) {
206-
val data = internalApi.calculateOnRamp(args) ?: throw Exception("Empty response")
202+
val data = internalApi.calculateOnRamp(config.webSwapsUrl, args) ?: throw Exception("Empty response")
207203
val json = JSONObject(data)
208204
val items = json.getJSONArray("items").map { OnRampMerchantEntity(it) }
209205
val suggested = json.optJSONArray("suggested")?.map { OnRampMerchantEntity(it) } ?: emptyList()
@@ -261,7 +257,11 @@ class API(
261257
configRepository.refresh(testnet)
262258
}
263259

264-
fun swapStream(from: SwapAssetParam, to: SwapAssetParam, userAddress: String) = swapApi.stream(from, to, userAddress)
260+
fun swapStream(
261+
from: SwapAssetParam,
262+
to: SwapAssetParam,
263+
userAddress: String
264+
) = swapApi.stream(config.webSwapsUrl, from, to, userAddress)
265265

266266
suspend fun getPageTitle(url: String): String = withContext(Dispatchers.IO) {
267267
try {
@@ -537,6 +537,15 @@ class API(
537537
}
538538
}
539539

540+
fun getRates(from: String, to: String): Map<String, TokenRates>? {
541+
return withRetry {
542+
rates().getRates(
543+
tokens = listOf(from),
544+
currencies = listOf(to)
545+
).rates
546+
}
547+
}
548+
540549
fun getNft(address: String, testnet: Boolean): NftItem? {
541550
return withRetry { nft(testnet).getNftItemByAddress(address) }
542551
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.tonapps.wallet.api
2+
3+
internal object Constants {
4+
5+
const val SWAP_PREFIX = "https://swap.tonkeeper.com"
6+
}

apps/wallet/api/src/main/java/com/tonapps/wallet/api/cronet/CronetInterceptor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.Iterator;
99
import java.util.Map;
1010
import java.util.Map.Entry;
11+
import java.util.concurrent.CancellationException;
1112
import java.util.concurrent.ConcurrentHashMap;
1213
import java.util.concurrent.ScheduledExecutorService;
1314
import java.util.concurrent.ScheduledFuture;
@@ -77,7 +78,7 @@ private CronetInterceptor(RequestResponseConverter converter) {
7778
@Override
7879
public Response intercept(Chain chain) throws IOException {
7980
if (chain.call().isCanceled()) {
80-
throw new IOException("Canceled");
81+
throw new CancellationException();
8182
}
8283

8384
Request request = chain.request();

apps/wallet/api/src/main/java/com/tonapps/wallet/api/entity/ConfigEntity.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import kotlinx.parcelize.IgnoredOnParcel
99
import kotlinx.parcelize.Parcelize
1010
import org.json.JSONObject
1111
import androidx.core.net.toUri
12+
import com.tonapps.wallet.api.Constants
1213

1314
@Parcelize
1415
data class ConfigEntity(
@@ -62,7 +63,8 @@ data class ConfigEntity(
6263
val tronSwapTitle: String,
6364
val tronApiKey: String? = null,
6465
val privacyPolicyUrl: String,
65-
val termsOfUseUrl: String
66+
val termsOfUseUrl: String,
67+
val webSwapsUrl: String,
6668
): Parcelable {
6769

6870
@IgnoredOnParcel
@@ -140,9 +142,10 @@ data class ConfigEntity(
140142
tonkeeperApiUrl = json.optString("tonkeeper_api_url", "https://api.tonkeeper.com"),
141143
tronSwapUrl = json.optString("tron_swap_url", "https://widget.letsexchange.io/en?affiliate_id=ffzymmunvvyxyypo&coin_from=ton&coin_to=USDT-TRC20&is_iframe=true"),
142144
tronSwapTitle = json.optString("tron_swap_title", "LetsExchange"),
143-
tronApiKey = json.optString("tron_api_key"),
145+
// tronApiKey = json.optString("tron_api_key"),
144146
privacyPolicyUrl = json.getString("privacy_policy"),
145147
termsOfUseUrl = json.getString("terms_of_use"),
148+
webSwapsUrl = json.optString("web_swaps_url", Constants.SWAP_PREFIX)
146149
)
147150

148151
constructor() : this(
@@ -195,7 +198,8 @@ data class ConfigEntity(
195198
tronSwapUrl = "https://widget.letsexchange.io/en?affiliate_id=ffzymmunvvyxyypo&coin_from=ton&coin_to=USDT-TRC20&is_iframe=true",
196199
tronSwapTitle = "LetsExchange",
197200
privacyPolicyUrl = "https://tonkeeper.com/privacy",
198-
termsOfUseUrl = "https://tonkeeper.com/terms"
201+
termsOfUseUrl = "https://tonkeeper.com/terms",
202+
webSwapsUrl = Constants.SWAP_PREFIX
199203
)
200204

201205
fun formatTransactionExplorer(testnet: Boolean, tron: Boolean, hash: String): String {

apps/wallet/api/src/main/java/com/tonapps/wallet/api/entity/OnRampArgsEntity.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ data class OnRampArgsEntity(
1414
val paymentMethod: String?
1515
) {
1616

17+
val isSwap: Boolean
18+
get() = purchaseType == "swap"
19+
20+
val isSell: Boolean
21+
get() = purchaseType == "sell"
22+
23+
val withoutPaymentMethod: Boolean
24+
get() = isSwap || isSell
25+
1726
fun toJSON() = JSONObject().apply {
1827
put("from", from)
1928
put("to", to)

apps/wallet/api/src/main/java/com/tonapps/wallet/api/internal/InternalApi.kt

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.tonapps.wallet.api.internal
22

33
import android.content.Context
4+
import android.util.Log
45
import androidx.collection.ArrayMap
56
import androidx.core.net.toUri
67
import com.google.firebase.crashlytics.FirebaseCrashlytics
@@ -101,10 +102,8 @@ internal class InternalApi(
101102
return JSONObject(body)
102103
}
103104

104-
private fun swapEndpoint(path: String): String {
105-
// val host = "dev-swap.tonkeeper.com"
106-
val host = "swap.tonkeeper.com"
107-
val builder = "https://$host".toUri().buildUpon()
105+
private fun swapEndpoint(prefix: String, path: String): String {
106+
val builder = prefix.toUri().buildUpon()
108107
.appendEncodedPath(path)
109108
_deviceCountry?.let {
110109
builder.appendQueryParameter("device_country_code", _deviceCountry)
@@ -113,32 +112,27 @@ internal class InternalApi(
113112
_storeCountry?.let {
114113
builder.appendQueryParameter("store_country_code", _storeCountry)
115114
}
116-
117115
return builder.build().toString()
118116
}
119117

120-
fun getSwapAssets() = withRetry {
121-
okHttpClient.get(swapEndpoint("v2/swap/assets"))
122-
}
123-
124-
fun getOnRampData() = withRetry {
125-
okHttpClient.get(swapEndpoint("v2/onramp/currencies"))
118+
fun getOnRampData(prefix: String) = withRetry {
119+
okHttpClient.get(swapEndpoint(prefix, "v2/onramp/currencies"))
126120
}
127121

128-
fun getOnRampPaymentMethods(currency: String) = withRetry {
129-
okHttpClient.get(swapEndpoint("v2/onramp/payment_methods"))
122+
fun getOnRampPaymentMethods(prefix: String, currency: String) = withRetry {
123+
okHttpClient.get(swapEndpoint(prefix, "v2/onramp/payment_methods"))
130124
}
131125

132-
fun getOnRampMerchants() = withRetry {
133-
okHttpClient.get(swapEndpoint("v2/onramp/merchants"))
126+
fun getOnRampMerchants(prefix: String) = withRetry {
127+
okHttpClient.get(swapEndpoint(prefix, "v2/onramp/merchants"))
134128
}
135129

136-
fun calculateOnRamp(args: OnRampArgsEntity): String? {
130+
fun calculateOnRamp(prefix: String, args: OnRampArgsEntity): String? {
137131
val json = args.toJSON()
138132
_deviceCountry?.let { json.put("country", _deviceCountry) }
139133
return withRetry {
140134
okHttpClient.postJSON(
141-
swapEndpoint("v2/onramp/calculate"),
135+
swapEndpoint(prefix, "v2/onramp/calculate"),
142136
json.toString()
143137
).body.string()
144138
}

0 commit comments

Comments
 (0)