use of com.odysee.app.exceptions.LbryioResponseException in project odysee-android by OdyseeTeam.
the class SyncGetTask method doInBackground.
protected WalletSync doInBackground(Void... params) {
try {
password = Helper.isNullOrEmpty(password) ? "" : password;
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_WALLET_STATUS, Lbryio.AUTH_TOKEN);
boolean isLocked = Helper.getJSONBoolean("is_locked", false, result);
boolean unlockSuccessful = !isLocked || (boolean) Lbry.authenticatedGenericApiCall(Lbry.METHOD_WALLET_UNLOCK, Lbry.buildSingleParam("password", password), Lbryio.AUTH_TOKEN);
if (!unlockSuccessful) {
throw new WalletException("The wallet could not be unlocked with the provided password.");
}
String hash = (String) Lbry.authenticatedGenericApiCall(Lbry.METHOD_SYNC_HASH, null, Lbryio.AUTH_TOKEN);
try {
JSONObject response = (JSONObject) Lbryio.parseResponse(Lbryio.call("sync", "get", Lbryio.buildSingleParam("hash", hash), Helper.METHOD_POST, null));
WalletSync walletSync = new WalletSync(Helper.getJSONString("hash", null, response), Helper.getJSONString("data", null, response), Helper.getJSONBoolean("changed", false, response));
if (applySyncChanges && (!hash.equalsIgnoreCase(walletSync.getHash()) || walletSync.isChanged())) {
// Lbry.sync_apply({ password, data: response.data, blocking: true });
try {
Map<String, Object> options = new HashMap<>();
options.put("password", Helper.isNullOrEmpty(password) ? "" : password);
options.put("data", walletSync.getData());
options.put("blocking", true);
JSONObject syncApplyResponse = (JSONObject) Lbry.authenticatedGenericApiCall(Lbry.METHOD_SYNC_APPLY, options, Lbryio.AUTH_TOKEN);
syncHash = Helper.getJSONString("hash", null, syncApplyResponse);
syncData = Helper.getJSONString("data", null, syncApplyResponse);
applySyncSuccessful = true;
} catch (ApiCallException | ClassCastException ex) {
// sync_apply failed
syncApplyError = ex;
}
}
if (Lbryio.isSignedIn() && !Lbryio.userHasSyncedWallet) {
// indicate that the user owns a synced wallet (only if the user is signed in)
Lbryio.userHasSyncedWallet = true;
}
return walletSync;
} catch (LbryioResponseException ex) {
// wallet sync data doesn't exist
return null;
}
} catch (ApiCallException | WalletException | ClassCastException | LbryioRequestException ex) {
error = ex;
return null;
}
}
use of com.odysee.app.exceptions.LbryioResponseException in project odysee-android by OdyseeTeam.
the class ClaimRewardTask method doInBackground.
public String doInBackground(Void... params) {
String message = null;
try {
String txid = null;
if (Reward.TYPE_FIRST_CHANNEL.equalsIgnoreCase(type)) {
// fetch a channel
txid = fetchSingleClaimTxid(Claim.TYPE_CHANNEL);
} else if (Reward.TYPE_FIRST_PUBLISH.equalsIgnoreCase(type)) {
// fetch a publish
txid = fetchSingleClaimTxid(Claim.TYPE_STREAM);
}
// Get a new wallet address for the reward
String address = (String) Lbry.genericApiCall(Lbry.METHOD_ADDRESS_UNUSED, authToken);
Map<String, String> options = new HashMap<>();
options.put("reward_type", type);
options.put("wallet_address", address);
if (!Helper.isNullOrEmpty(rewardCode)) {
options.put("code", rewardCode);
}
if (!Helper.isNullOrEmpty(txid)) {
options.put("transaction_id", txid);
}
if (authToken != null) {
options.put("auth_token", authToken);
}
JSONObject reward = (JSONObject) Lbryio.parseResponse(Lbryio.call("reward", "claim", options, Helper.METHOD_POST, null));
if (reward != null) {
amountClaimed = Helper.getJSONDouble("reward_amount", 0, reward);
message = Helper.getJSONString("reward_notification", "", reward);
}
} catch (ApiCallException | JSONException | LbryioRequestException | LbryioResponseException ex) {
error = ex;
}
return message;
}
use of com.odysee.app.exceptions.LbryioResponseException in project odysee-android by OdyseeTeam.
the class SignInActivity method performSignIn.
private void performSignIn(final String email, final String password) {
if (requestInProgress) {
return;
}
if (!emailSignInChecked) {
requestInProgress = true;
beforeSignInTransition();
executor.execute(new Runnable() {
@Override
public void run() {
Map<String, String> options = new HashMap<>();
options.put("email", email);
try {
Object response = Lbryio.parseResponse(Lbryio.call("user", "exists", options, Helper.METHOD_POST, SignInActivity.this));
requestInProgress = false;
if (response instanceof JSONObject) {
JSONObject json = (JSONObject) response;
boolean hasPassword = Helper.getJSONBoolean("has_password", false, json);
if (!hasPassword) {
setCurrentEmail(email);
handleUserSignInWithoutPassword(email);
return;
}
// email exists, we can use sign in flow. Show password field
setCurrentEmail(email);
emailSignInChecked = true;
displaySignInControls();
displayMagicLink();
}
} catch (LbryioRequestException | LbryioResponseException ex) {
if (ex instanceof LbryioResponseException) {
LbryioResponseException rex = (LbryioResponseException) ex;
if (rex.getStatusCode() == 412) {
// old email verification flow
setCurrentEmail(email);
handleUserSignInWithoutPassword(email);
Bundle bundle = new Bundle();
bundle.putString("email", currentEmail);
LbryAnalytics.logEvent(LbryAnalytics.EVENT_EMAIL_ADDED, bundle);
LbryAnalytics.logEvent("");
requestInProgress = false;
return;
}
}
requestInProgress = false;
restoreControls(true);
showError(ex.getMessage());
}
}
});
return;
}
if (Helper.isNullOrEmpty(password)) {
showError(getString(R.string.please_enter_signin_password));
return;
}
beforeSignInTransition();
requestInProgress = true;
executor.execute(new Runnable() {
@Override
public void run() {
Map<String, String> options = new HashMap<>();
options.put("email", email);
options.put("password", password);
try {
Object response = Lbryio.parseResponse(Lbryio.call("user", "signin", options, Helper.METHOD_POST, SignInActivity.this));
requestInProgress = false;
if (response instanceof JSONObject) {
Type type = new TypeToken<User>() {
}.getType();
Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
User user = gson.fromJson(response.toString(), type);
Lbryio.currentUser = user;
addOdyseeAccountExplicitly(user.getPrimaryEmail());
finishWithWalletSync();
return;
}
} catch (LbryioRequestException | LbryioResponseException ex) {
if (ex instanceof LbryioResponseException) {
if (((LbryioResponseException) ex).getStatusCode() == 409) {
handleEmailVerificationFlow(email);
return;
}
}
showError(ex.getMessage());
requestInProgress = false;
restoreControls(true);
return;
}
requestInProgress = false;
restoreControls(true);
showError(getString(R.string.unknown_error_occurred));
}
});
}
use of com.odysee.app.exceptions.LbryioResponseException in project odysee-android by OdyseeTeam.
the class SignInFragment method performSignIn.
private void performSignIn(final String email, final String password) {
if (requestInProgress) {
return;
}
if (!emailSignInChecked) {
requestInProgress = true;
if (firstRunStepHandler != null) {
firstRunStepHandler.onRequestInProgress(false);
}
beforeSignInTransition();
executor.execute(new Runnable() {
@Override
public void run() {
Map<String, String> options = new HashMap<>();
options.put("email", email);
try {
Object response = Lbryio.parseResponse(Lbryio.call("user", "exists", options, Helper.METHOD_POST, getContext()));
requestInProgress = false;
if (response instanceof JSONObject) {
JSONObject json = (JSONObject) response;
boolean hasPassword = Helper.getJSONBoolean("has_password", false, json);
if (!hasPassword) {
setCurrentEmail(email);
handleUserSignInWithoutPassword(email);
return;
}
// email exists, we can use sign in flow. Show password field
setCurrentEmail(email);
emailSignInChecked = true;
displaySignInControls();
displayMagicLink();
}
} catch (LbryioRequestException | LbryioResponseException ex) {
if (ex instanceof LbryioResponseException) {
LbryioResponseException rex = (LbryioResponseException) ex;
if (rex.getStatusCode() == 412) {
// old email verification flow
setCurrentEmail(email);
handleUserSignInWithoutPassword(email);
Bundle bundle = new Bundle();
bundle.putString("email", currentEmail);
LbryAnalytics.logEvent(LbryAnalytics.EVENT_EMAIL_ADDED, bundle);
LbryAnalytics.logEvent("");
requestInProgress = false;
return;
}
}
requestInProgress = false;
restoreControls(true);
if (firstRunStepHandler != null) {
firstRunStepHandler.onRequestCompleted(FirstRunActivity.FIRST_RUN_STEP_ACCOUNT);
}
showError(ex.getMessage());
}
}
});
return;
}
if (Helper.isNullOrEmpty(password)) {
showError(getString(R.string.please_enter_signin_password));
return;
}
beforeSignInTransition();
requestInProgress = true;
executor.execute(new Runnable() {
@Override
public void run() {
Map<String, String> options = new HashMap<>();
options.put("email", email);
options.put("password", password);
try {
Object response = Lbryio.parseResponse(Lbryio.call("user", "signin", options, Helper.METHOD_POST, getContext()));
requestInProgress = false;
if (response instanceof JSONObject) {
Type type = new TypeToken<User>() {
}.getType();
Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
User user = gson.fromJson(response.toString(), type);
Lbryio.currentUser = user;
addOdyseeAccountExplicitly(user.getPrimaryEmail());
finishWithWalletSync();
return;
}
} catch (LbryioRequestException | LbryioResponseException ex) {
if (ex instanceof LbryioResponseException) {
if (((LbryioResponseException) ex).getStatusCode() == 409) {
handleEmailVerificationFlow(email);
return;
}
}
showError(ex.getMessage());
requestInProgress = false;
restoreControls(true);
if (firstRunStepHandler != null) {
firstRunStepHandler.onRequestCompleted(FirstRunActivity.FIRST_RUN_STEP_ACCOUNT);
}
return;
}
requestInProgress = false;
restoreControls(true);
if (firstRunStepHandler != null) {
firstRunStepHandler.onRequestCompleted(FirstRunActivity.FIRST_RUN_STEP_ACCOUNT);
}
showError(getString(R.string.unknown_error_occurred));
}
});
}
Aggregations