43 lines
1.6 KiB
Java
43 lines
1.6 KiB
Java
package monnethic.mobile.restApi;
|
|
|
|
import org.json.JSONArray;
|
|
import org.json.JSONObject;
|
|
|
|
import java.net.URL;
|
|
import java.util.ArrayList;
|
|
|
|
import monnethic.mobile.wallet.Wallet;
|
|
|
|
public class WalletApiHandler {
|
|
|
|
public ArrayList<Wallet> getUserWallets(String[] params){
|
|
ArrayList<Wallet> walletList = new ArrayList<>();
|
|
HttpCallHandler httpCallHandler = new HttpCallHandler();
|
|
try {
|
|
String url = Config.WALLET_GET_USER_WALLETS+"?userHash="+params[0];
|
|
String responseCall = httpCallHandler.getHttp(new URL(url));
|
|
JSONArray jsonArray = new JSONArray(responseCall);
|
|
|
|
for(int i=0; i<jsonArray.length(); i++){
|
|
Wallet wallet = new Wallet();
|
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
|
|
|
wallet.setType(jsonObject.getJSONObject("Record").getJSONObject("walletType").getString("string"));
|
|
wallet.setWallet_hash(jsonObject.getJSONObject("Record").getJSONObject("id").getString("string"));
|
|
wallet.setUser_hash(jsonObject.getJSONObject("Record").getJSONObject("owner").getString("string"));
|
|
|
|
String urlGetWallet = Config.WALLET_GET_WALLET+"?walletHash="+wallet.getWallet_hash();
|
|
String responseWallet = httpCallHandler.getHttp(new URL(urlGetWallet));
|
|
JSONObject jsonWallet = new JSONObject(responseWallet);
|
|
|
|
wallet.setBalance(jsonWallet.getDouble("balance"));
|
|
walletList.add(wallet);
|
|
}
|
|
} catch (Exception e){
|
|
e.printStackTrace();
|
|
}
|
|
|
|
return walletList;
|
|
}
|
|
}
|