Updated on 2026-08-14
This commit is contained in:
parent
aaf75f5e10
commit
8c7491ba93
7 changed files with 269 additions and 35 deletions
|
|
@ -4,14 +4,12 @@ import com.tangem.data.network.model.PayIdResponse;
|
|||
|
||||
import io.reactivex.Single;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Header;
|
||||
import retrofit2.http.Headers;
|
||||
import retrofit2.http.Path;
|
||||
|
||||
public interface PayIdApi {
|
||||
@Headers({
|
||||
"Accept: application/xrpl-mainnet+json",
|
||||
"PayID-Version: 1.0"
|
||||
})
|
||||
@Headers("PayID-Version: 1.0")
|
||||
@GET("{user}")
|
||||
Single<PayIdResponse> getAddress(@Path("user") String user);
|
||||
Single<PayIdResponse> getAddress(@Path("user") String user, @Header("Accept") String acceptHeader);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
import com.tangem.App;
|
||||
import com.tangem.data.Blockchain;
|
||||
import com.tangem.data.network.model.PayIdResponse;
|
||||
import com.tangem.tangem_card.util.Log;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.SingleObserver;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
|
|
@ -17,12 +19,21 @@ public class ServerApiPayId {
|
|||
|
||||
private int requestsCount = 0;
|
||||
|
||||
public String getAcceptHeader(Blockchain blockchain) throws InvalidParameterException {
|
||||
switch (blockchain) {
|
||||
case Ripple: return "application/xrpl-mainnet+json";
|
||||
case Bitcoin: return "application/btc-mainnet+json";
|
||||
case Ethereum: return "application/eth-mainnet+json";
|
||||
default: throw new InvalidParameterException("PayID is not supported for " + blockchain.getOfficialName());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRequestsSequenceCompleted() {
|
||||
Log.i(TAG, String.format("isRequestsSequenceCompleted: %s (%d requests left)", String.valueOf(requestsCount <= 0), requestsCount));
|
||||
return requestsCount <= 0;
|
||||
}
|
||||
|
||||
public void getAddress(String payID, SingleObserver<PayIdResponse> addressObserver) {
|
||||
public void getAddress(String payID, Blockchain blockchain, SingleObserver<PayIdResponse> addressObserver) throws InvalidParameterException {
|
||||
requestsCount++;
|
||||
Log.i(TAG, "new getAddress request");
|
||||
|
||||
|
|
@ -38,7 +49,7 @@ public class ServerApiPayId {
|
|||
|
||||
PayIdApi api = retrofit.create(PayIdApi.class);
|
||||
|
||||
Single<PayIdResponse> addressSingle = api.getAddress(user)
|
||||
Single<PayIdResponse> addressSingle = api.getAddress(user, getAcceptHeader(blockchain))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnEvent((object, throwable) -> requestsCount--);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue