Search in sources :

Example 1 with NetworkError

use of run.wallet.iota.api.responses.error.NetworkError in project run-wallet-android by runplay.

the class BasicApiProvider method processRequest.

@Override
public ApiResponse processRequest(ApiRequest apiRequest) {
    ApiResponse response = null;
    try {
        if (useRequestHandlerMap.containsKey(apiRequest.getClass())) {
            RequestHandler requestHandler = useRequestHandlerMap.get(apiRequest.getClass());
            response = requestHandler.handle(apiRequest);
        }
    } catch (IllegalAccessError e) {
        NetworkError error = new NetworkError();
        error.setErrorType(NetworkErrorType.ACCESS_ERROR);
        response = error;
        Log.e("ERR-B-API1", "" + e.getMessage());
    } catch (Exception e) {
        Log.e("ERR-B-API2", e.toString() + " -- " + e.getMessage());
        response = new NetworkError();
    }
    return response == null ? new NetworkError() : response;
}
Also used : RequestHandler(run.wallet.iota.api.handler.RequestHandler) WebGetExchangeRatesHistoryRequestHandler(run.wallet.iota.api.handler.WebGetExchangeRatesHistoryRequestHandler) WebGetExchangeRatesRequestHandler(run.wallet.iota.api.handler.WebGetExchangeRatesRequestHandler) NetworkError(run.wallet.iota.api.responses.error.NetworkError) ApiResponse(run.wallet.iota.api.responses.ApiResponse)

Example 2 with NetworkError

use of run.wallet.iota.api.responses.error.NetworkError in project run-wallet-android by runplay.

the class IotaMessageApiProvider method processRequest.

@Override
public ApiResponse processRequest(ApiRequest apiRequest) {
    ApiResponse response = null;
    try {
        // Log.e("IotaMessageApiProvider", "");
        if (this.requestHandlerMap.containsKey(apiRequest.getClass())) {
            // Log.e("IotaMessageApiProvider", "requesting");
            RequestHandler requestHandler = this.requestHandlerMap.get(apiRequest.getClass());
            response = requestHandler.handle(apiRequest);
        }
    } catch (IllegalAccessError e) {
        NetworkError error = new NetworkError();
        error.setErrorType(NetworkErrorType.ACCESS_ERROR);
        response = error;
    // Log.e("IotaMessageApi ERR",""+e.getMessage());
    } catch (Exception e) {
        Log.e("ERR-API", "ex: " + e.getMessage());
        response = new NetworkError();
    }
    return response == null ? new NetworkError() : response;
}
Also used : MessageFirstLoadRequestHandler(run.wallet.iota.api.handler.MessageFirstLoadRequestHandler) RequestHandler(run.wallet.iota.api.handler.RequestHandler) MessageSendRequestHandler(run.wallet.iota.api.handler.MessageSendRequestHandler) MessageNewAddressRequestHandler(run.wallet.iota.api.handler.MessageNewAddressRequestHandler) NetworkError(run.wallet.iota.api.responses.error.NetworkError) ApiResponse(run.wallet.iota.api.responses.ApiResponse)

Example 3 with NetworkError

use of run.wallet.iota.api.responses.error.NetworkError in project run-wallet-android by runplay.

the class AddressSecurityChangeRequestHandler method handle.

@Override
public ApiResponse handle(ApiRequest request) {
    ApiResponse response;
    AddressSecurityChangeRequest gnr = ((AddressSecurityChangeRequest) request);
    try {
        jota.dto.response.GetNewAddressResponse resp = apiProxy.getNewAddress(gnr.getAddress().getAddress(), gnr.getSecurity(), gnr.getAddress().getIndex(), false, 1, true);
        // Log.e("ADDRES-SECURITY","has response: "+resp.getAddresses().get(0));
        response = new GetNewAddressResponse(gnr.getSeed(), resp);
        Store.updateAddressFromSecurity(context, gnr, (GetNewAddressResponse) response);
        return new AddressSecurityChangeResponse();
    } catch (ArgumentException e) {
        response = new NetworkError();
    }
    return response;
}
Also used : GetNewAddressResponse(run.wallet.iota.api.responses.GetNewAddressResponse) AddressSecurityChangeRequest(run.wallet.iota.api.requests.AddressSecurityChangeRequest) AddressSecurityChangeResponse(run.wallet.iota.api.responses.AddressSecurityChangeResponse) NetworkError(run.wallet.iota.api.responses.error.NetworkError) ArgumentException(jota.error.ArgumentException) ApiResponse(run.wallet.iota.api.responses.ApiResponse)

Example 4 with NetworkError

use of run.wallet.iota.api.responses.error.NetworkError in project run-wallet-android by runplay.

the class GetBalanceAndFormatRequestHandler method handle.

@Override
public ApiResponse handle(ApiRequest request) {
    int notificationId = Utils.createNewID();
    ApiResponse response;
    try {
        StopWatch stopWatch = new StopWatch();
        // stopWatch.
        // Log.e("BALF","Getting balances and format");
        response = new GetBalanceAndFormatResponse(apiProxy.getBalanceAndFormat(((GetBalanceAndFormatRequest) request).addresses, 0L, 0, stopWatch, 0));
        List<Input> inputs = ((GetBalanceAndFormatResponse) response).getInputs();
    } catch (ArgumentException e) {
        NetworkError error = new NetworkError();
        if (e instanceof ArgumentException) {
            if (e.getMessage().contains("Sending to a used address.") || e.getMessage().contains("Private key reuse detect!")) {
                final Activity activity = (Activity) context;
                Bundle bundle = new Bundle();
                bundle.putString("error", e.getMessage());
                KeyReuseDetectedDialog dialog = new KeyReuseDetectedDialog();
                dialog.setArguments(bundle);
                dialog.show(activity.getFragmentManager(), null);
                error.setErrorType(NetworkErrorType.KEY_REUSE_ERROR);
            }
        }
        if (error.getErrorType() != NetworkErrorType.KEY_REUSE_ERROR) {
            error.setErrorType(NetworkErrorType.NETWORK_ERROR);
        }
        response = error;
    }
    return response;
}
Also used : Input(jota.model.Input) Bundle(android.os.Bundle) NetworkError(run.wallet.iota.api.responses.error.NetworkError) Activity(android.app.Activity) ArgumentException(jota.error.ArgumentException) KeyReuseDetectedDialog(run.wallet.iota.ui.dialog.KeyReuseDetectedDialog) ApiResponse(run.wallet.iota.api.responses.ApiResponse) StopWatch(jota.utils.StopWatch) GetBalanceAndFormatResponse(run.wallet.iota.api.responses.GetBalanceAndFormatResponse)

Example 5 with NetworkError

use of run.wallet.iota.api.responses.error.NetworkError in project run-wallet-android by runplay.

the class GetNewAddressRequestHandler method handle.

@Override
public ApiResponse handle(ApiRequest request) {
    ApiResponse response;
    GetNewAddressRequest gnr = ((GetNewAddressRequest) request);
    List<Address> alreadyAddress = Store.getAddresses(context, gnr.getSeed());
    gnr.setIndex(alreadyAddress.size());
    try {
        jota.dto.response.GetNewAddressResponse resp = apiProxy.getNewAddress(String.valueOf(Store.getSeedRaw(context, gnr.getSeed())), gnr.getSecurity(), alreadyAddress.size(), gnr.isChecksum(), 1, gnr.isReturnAll());
        /*
            jota.dto.response.GetNewAddressResponse resp=apiProxy.getNewAddress(((GetNewAddressRequest) request).getSeedValue(),
                    ((GetNewAddressRequest) request).getSecurity(),
                    ((GetNewAddressRequest) request).getIndex(),
                    ((GetNewAddressRequest) request).isChecksum(),
                    ((GetNewAddressRequest) request).getTotal(),
                    ((GetNewAddressRequest) request).isReturnAll());
            */
        response = new GetNewAddressResponse(gnr.getSeed(), resp);
        Store.addAddress(context, gnr, (GetNewAddressResponse) response);
        AppService.auditAddresses(context, gnr.getSeed());
    // SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
    // if (prefs.getBoolean(Constants.PREFERENCES_LOCAL_POW, true)
    // && !((GetNewAddressResponse) response).getAddresses().isEmpty()) {
    // AppService.attachNewAddress(context,((GetNewAddressRequest) request).getSeed(),((GetNewAddressResponse) response).getAddresses().get(0));
    // }
    } catch (ArgumentException e) {
        response = new NetworkError();
    }
    return response;
}
Also used : GetNewAddressResponse(run.wallet.iota.api.responses.GetNewAddressResponse) Address(run.wallet.iota.model.Address) GetNewAddressRequest(run.wallet.iota.api.requests.GetNewAddressRequest) NetworkError(run.wallet.iota.api.responses.error.NetworkError) ArgumentException(jota.error.ArgumentException) ApiResponse(run.wallet.iota.api.responses.ApiResponse)

Aggregations

NetworkError (run.wallet.iota.api.responses.error.NetworkError)14 ApiResponse (run.wallet.iota.api.responses.ApiResponse)13 ArgumentException (jota.error.ArgumentException)10 Address (run.wallet.iota.model.Address)6 Activity (android.app.Activity)3 Bundle (android.os.Bundle)3 ArrayList (java.util.ArrayList)3 RequestHandler (run.wallet.iota.api.handler.RequestHandler)3 Transfer (run.wallet.iota.model.Transfer)3 Wallet (run.wallet.iota.model.Wallet)3 KeyReuseDetectedDialog (run.wallet.iota.ui.dialog.KeyReuseDetectedDialog)3 NotificationManager (android.app.NotificationManager)2 GetNewAddressResponse (jota.dto.response.GetNewAddressResponse)2 RunSendTransferResponse (jota.dto.response.RunSendTransferResponse)2 Input (jota.model.Input)2 StopWatch (jota.utils.StopWatch)2 GetNewAddressRequest (run.wallet.iota.api.requests.GetNewAddressRequest)2 NudgeRequest (run.wallet.iota.api.requests.NudgeRequest)2 GetNewAddressResponse (run.wallet.iota.api.responses.GetNewAddressResponse)2 NudgeResponse (run.wallet.iota.api.responses.NudgeResponse)2