diff --git a/app/src/main/java/com/tangem/data/network/Server.java b/app/src/main/java/com/tangem/data/network/Server.java index 42b1a07512..97fb0ab7e3 100644 --- a/app/src/main/java/com/tangem/data/network/Server.java +++ b/app/src/main/java/com/tangem/data/network/Server.java @@ -28,7 +28,15 @@ public class Server { public static final String URL_INFURA = ServerURL.API_INFURA; public static class Method { - static final String MAIN = URL_INFURA + "v3/613a0b14833145968b1f656240c7d245"; + public static final String MAIN = "v3/613a0b14833145968b1f656240c7d245"; + } + } + + public static class ApiInfuraTestnet { + public static final String URL_INFURA_TESTNET = ServerURL.API_INFURA_TESTNET; + + public static class Method { + public static final String MAIN = "v3/613a0b14833145968b1f656240c7d245"; } } diff --git a/app/src/main/java/com/tangem/data/network/ServerApiInfura.java b/app/src/main/java/com/tangem/data/network/ServerApiInfura.java index bf53beb20d..e168293fa4 100644 --- a/app/src/main/java/com/tangem/data/network/ServerApiInfura.java +++ b/app/src/main/java/com/tangem/data/network/ServerApiInfura.java @@ -5,6 +5,7 @@ import android.util.Log; import androidx.annotation.NonNull; import com.tangem.App; +import com.tangem.data.Blockchain; import com.tangem.data.network.model.InfuraBody; import com.tangem.data.network.model.InfuraResponse; @@ -34,6 +35,16 @@ public class ServerApiInfura { private int requestsCount=0; + private InfuraApi infuraApi = App.Companion.getNetworkComponent().getRetrofitInfura().create(InfuraApi.class); + + public ServerApiInfura() {} + + public ServerApiInfura(Blockchain blockchain) { + if (blockchain == Blockchain.EthereumTestNet) { + infuraApi = App.Companion.getNetworkComponent().getRetrofitInfuraTestnet().create(InfuraApi.class); + } + } + public boolean isRequestsSequenceCompleted() { Log.i(TAG, String.format("isRequestsSequenceCompleted: %s (%d requests left)", String.valueOf(requestsCount <= 0), requestsCount)); return requestsCount <= 0; @@ -53,7 +64,7 @@ public class ServerApiInfura { public void requestData(String method, int id, String wallet, String contract, String tx) { requestsCount++; - InfuraApi infuraApi = App.Companion.getNetworkComponent().getRetrofitInfura().create(InfuraApi.class); + InfuraBody infuraBody; switch (method) { diff --git a/app/src/main/java/com/tangem/data/network/ServerURL.java b/app/src/main/java/com/tangem/data/network/ServerURL.java index 8147ae4d02..b30fc802ce 100644 --- a/app/src/main/java/com/tangem/data/network/ServerURL.java +++ b/app/src/main/java/com/tangem/data/network/ServerURL.java @@ -4,6 +4,7 @@ class ServerURL { static final String API_TANGEM = "https://verify.tangem.com/"; static final String API_COINMARKETCAP = "https://pro-api.coinmarketcap.com/"; static final String API_INFURA = "https://mainnet.infura.io/"; + static final String API_INFURA_TESTNET = "https://rinkeby.infura.io/"; static final String API_SOCHAIN_V2 = "https://chain.so/"; static final String API_ESTIMATEFEE = "https://estimatefee.com/"; static final String API_UPDATE_VERSION = "https://raw.githubusercontent.com/"; diff --git a/app/src/main/java/com/tangem/di/NetworkComponent.kt b/app/src/main/java/com/tangem/di/NetworkComponent.kt index 1a526e385b..b09c235aba 100644 --- a/app/src/main/java/com/tangem/di/NetworkComponent.kt +++ b/app/src/main/java/com/tangem/di/NetworkComponent.kt @@ -14,6 +14,9 @@ interface NetworkComponent { @get:Named(Server.ApiInfura.URL_INFURA) val retrofitInfura: Retrofit + @get:Named(Server.ApiInfuraTestnet.URL_INFURA_TESTNET) + val retrofitInfuraTestnet: Retrofit + @get:Named(Server.ApiMaticTesnet.URL_MATIC_TESTNET) val retrofitMaticTesnet: Retrofit diff --git a/app/src/main/java/com/tangem/di/NetworkModule.kt b/app/src/main/java/com/tangem/di/NetworkModule.kt index ea9331c1b8..0358c3bd9b 100644 --- a/app/src/main/java/com/tangem/di/NetworkModule.kt +++ b/app/src/main/java/com/tangem/di/NetworkModule.kt @@ -32,6 +32,18 @@ internal class NetworkModule { return builder.build() } + @Singleton + @Provides + @Named(Server.ApiInfuraTestnet.URL_INFURA_TESTNET) + fun provideRetrofitInfuraTestnet(): Retrofit { + val builder = Retrofit.Builder() + .baseUrl(Server.ApiInfuraTestnet.URL_INFURA_TESTNET) + .addConverterFactory(GsonConverterFactory.create()) + if (BuildConfig.DEBUG) + builder.client(createOkHttpClient()) + return builder.build() + } + @Singleton @Provides @Named(Server.ApiRootstock.URL_ROOTSTOCK) diff --git a/app/src/main/java/com/tangem/wallet/eth/EthEngine.java b/app/src/main/java/com/tangem/wallet/eth/EthEngine.java index aa70fccbe5..7175f68f73 100644 --- a/app/src/main/java/com/tangem/wallet/eth/EthEngine.java +++ b/app/src/main/java/com/tangem/wallet/eth/EthEngine.java @@ -466,7 +466,7 @@ public class EthEngine extends CoinEngine { @Override public void requestBalanceAndUnspentTransactions(BlockchainRequestsCallbacks blockchainRequestsCallbacks) { - final ServerApiInfura serverApiInfura = new ServerApiInfura(); + final ServerApiInfura serverApiInfura = new ServerApiInfura(ctx.getBlockchain()); final ServerApiBlockcypher serverApiBlockcypher = new ServerApiBlockcypher(); ServerApiInfura.ResponseListener responseListener = new ServerApiInfura.ResponseListener() { @@ -561,11 +561,21 @@ public class EthEngine extends CoinEngine { public void onSuccess(String method, BlockcypherFee blockcypherFee) { Log.e(TAG, "Wrong response type for requestBalanceAndUnspentTransactions"); + if (serverApiInfura.isRequestsSequenceCompleted()&& serverApiBlockcypher.isRequestsSequenceCompleted()) { + blockchainRequestsCallbacks.onComplete(!ctx.hasError()); + } else { + blockchainRequestsCallbacks.onProgress(); + } } @Override public void onFail(String method, String message) { Log.i(TAG, "onFail: " + method + " " + message); + if (serverApiInfura.isRequestsSequenceCompleted()&& serverApiBlockcypher.isRequestsSequenceCompleted()) { + blockchainRequestsCallbacks.onComplete(!ctx.hasError()); + } else { + blockchainRequestsCallbacks.onProgress(); + } } }; serverApiBlockcypher.setResponseListener(blockcypherListener); @@ -579,7 +589,7 @@ public class EthEngine extends CoinEngine { @Override public void requestFee(BlockchainRequestsCallbacks blockchainRequestsCallbacks, String targetAddress, Amount amount) { - ServerApiInfura serverApiInfura = new ServerApiInfura(); + ServerApiInfura serverApiInfura = new ServerApiInfura(ctx.getBlockchain()); // request requestData eth gasPrice listener ServerApiInfura.ResponseListener responseListener = new ServerApiInfura.ResponseListener() { @Override @@ -629,7 +639,7 @@ public class EthEngine extends CoinEngine { String txStr = String.format("0x%s", BTCUtils.toHex(txForSend)); - ServerApiInfura serverApiInfura = new ServerApiInfura(); + ServerApiInfura serverApiInfura = new ServerApiInfura(ctx.getBlockchain()); // request requestData eth gasPrice listener ServerApiInfura.ResponseListener responseListener = new ServerApiInfura.ResponseListener() { @Override