Skip to content

Commit

Permalink
2.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielWeigl committed Oct 1, 2015
1 parent 5b19bd4 commit 7e216bb
Show file tree
Hide file tree
Showing 30 changed files with 531 additions and 134 deletions.
4 changes: 2 additions & 2 deletions public/mbw/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ android {
buildToolsVersion androidSdkBuildVersion

defaultConfig {
versionCode 25202
versionName '2.5.2'
versionCode 25300
versionName '2.5.3'
multiDexEnabled true
}

Expand Down
54 changes: 37 additions & 17 deletions public/mbw/src/main/java/com/mycelium/wallet/CoinapultManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public Comparable apply(@Nullable com.coinapult.api.httpclient.Transaction.Json
private long satoshiDifference(com.coinapult.api.httpclient.Transaction.Json input) {
boolean isSending = isSending(input);
int sign = isSending ? -1 : 1;
return sign * CoinapultManager.this.getSatoshis(input.out.amount, input.out.currency);
return sign * CoinapultManager.this.getSatoshis(input.out.expected, input.out.currency);
}

private boolean isSending(com.coinapult.api.httpclient.Transaction.Json input) {
Expand All @@ -336,8 +336,9 @@ private boolean isSending(com.coinapult.api.httpclient.Transaction.Json input) {
if (isInvoice) {
return false;
}
throw new IllegalStateException("unexpected tx type: " + input.type);

// other unexpected tx type - but ignore it
return false;
}

private <T> List<T> limitedList(int offset, int limit, List<T> list) {
Expand Down Expand Up @@ -460,37 +461,55 @@ private void buildBalance() throws CoinapultBackendException {
final long oneMinuteAgo = new Date().getTime() - 1000 * 60;

BigDecimal receivingUsd = BigDecimal.ZERO;
BigDecimal sendingUsd = BigDecimal.ZERO;
BigDecimal receivingUsdNotIncludedInBalance = BigDecimal.ZERO;
BigDecimal sendingUsdNotIncludedInBalance = BigDecimal.ZERO;
for (com.coinapult.api.httpclient.Transaction.Json json : getHistoryWithExtras()) {
boolean sending = isSending(json);
if (json.state.equals("processing") || json.completeTime * 1000 > oneMinuteAgo) {
if (sending) {
sendingUsdNotIncludedInBalance = sendingUsdNotIncludedInBalance.add(json.in.amount);
sendingUsdNotIncludedInBalance = sendingUsdNotIncludedInBalance.add(json.in.expected);
} else {
receivingUsd = receivingUsd.add(json.out.amount);
}
} else if (json.state.equals("confirming")) {
if (sending) {
sendingUsdNotIncludedInBalance = sendingUsdNotIncludedInBalance.add(json.in.amount);
sendingUsdNotIncludedInBalance = sendingUsdNotIncludedInBalance.add(json.in.expected);
} else {
receivingUsdNotIncludedInBalance = receivingUsdNotIncludedInBalance.add(json.out.amount);
receivingUsdNotIncludedInBalance = receivingUsdNotIncludedInBalance.add(json.out.expected);
}
}
}
BigDecimal withoutUnconfirmed = balanceUSD1.amount.subtract(receivingUsd).add(sendingUsd);
BigDecimal withoutUnconfirmed = balanceUSD1.amount.subtract(receivingUsd);
BigDecimal totalReceiving = receivingUsd.add(receivingUsdNotIncludedInBalance);

if (withoutUnconfirmed.compareTo(BigDecimal.ZERO) < 0) {
MbwManager.getInstance(null).reportIgnoredException(
new RuntimeException(String
.format("Calculated withoutUnconfirmed-amount for coinapult account is negative {}, sending: {}, recv: {}", withoutUnconfirmed, sendingUsd, receivingUsd))
.format("Calculated withoutUnconfirmed-amount for coinapult account is negative withoutUnconfirmed: %f, sending: %f, recv: %f", withoutUnconfirmed, sendingUsdNotIncludedInBalance, totalReceiving))
);
withoutUnconfirmed=BigDecimal.ZERO;
}

if (sendingUsdNotIncludedInBalance.compareTo(BigDecimal.ZERO) < 0) {
MbwManager.getInstance(null).reportIgnoredException(
new RuntimeException(String
.format("Calculated sendingUsdNotIncludedInBalance-amount for coinapult account is negative withoutUnconfirmed: %f, sending: %f, recv: %f", withoutUnconfirmed, sendingUsdNotIncludedInBalance, totalReceiving))
);
sendingUsdNotIncludedInBalance=BigDecimal.ZERO;
}

if (totalReceiving.compareTo(BigDecimal.ZERO) < 0) {
MbwManager.getInstance(null).reportIgnoredException(
new RuntimeException(String
.format("Calculated totalReceiving-amount for coinapult account is negative withoutUnconfirmed: %f, sending: %f, recv: %f", withoutUnconfirmed, sendingUsdNotIncludedInBalance, totalReceiving))
);
sendingUsdNotIncludedInBalance=BigDecimal.ZERO;
}

balanceUSD = new CurrencyBasedBalance(
ExactCurrencyValue.from(withoutUnconfirmed, "USD"),
ExactCurrencyValue.from(sendingUsd.add(sendingUsdNotIncludedInBalance), "USD"),
ExactCurrencyValue.from(receivingUsd.add(receivingUsdNotIncludedInBalance), "USD")
ExactCurrencyValue.from(sendingUsdNotIncludedInBalance, "USD"),
ExactCurrencyValue.from(totalReceiving, "USD")
);
}

Expand Down Expand Up @@ -567,6 +586,14 @@ public PreparedCoinapult prepareCoinapultTx(Receiver receiver) throws StandardTr
}
}

public PreparedCoinapult prepareCoinapultTx(Address receivingAddress, ExactFiatValue amountEntered) throws StandardTransactionBuilder.InsufficientFundsException {
if (balanceUSD.confirmed.getValue().compareTo(amountEntered.getValue()) < 0) {
throw new StandardTransactionBuilder.InsufficientFundsException(getSatoshis(amountEntered), 0);
}
return new PreparedCoinapult(receivingAddress, amountEntered);
}


public boolean broadcast(PreparedCoinapult preparedCoinapult) {
try {
final com.coinapult.api.httpclient.Transaction.Json send;
Expand Down Expand Up @@ -603,13 +630,6 @@ public CurrencyBasedBalance getCurrencyBasedBalance() {
return new CurrencyBasedBalance(zero, zero, zero, true);
}

public PreparedCoinapult prepareCoinapultTx(Address receivingAddress, ExactFiatValue amountEntered) throws StandardTransactionBuilder.InsufficientFundsException {
if (balanceUSD.confirmed.getValue().compareTo(amountEntered.getValue()) < 0) {
throw new StandardTransactionBuilder.InsufficientFundsException(getSatoshis(amountEntered), 0);
}
return new PreparedCoinapult(receivingAddress, amountEntered);
}

public boolean setMail(Optional<String> mail) {
if (!mail.isPresent()) {
return false;
Expand Down
21 changes: 10 additions & 11 deletions public/mbw/src/main/java/com/mycelium/wallet/MbwManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public class MbwManager {
* 0x424944 = "BID"
*/
private static final int BIP32_ROOT_AUTHENTICATION_INDEX = 0x80424944;
private Optional<CoinapultManager> coinapultManager;
private Optional<CoinapultManager> _coinapultManager;

/**
* The index proposed for bit id as per https://github.com/bitid/bitid/blob/master/BIP_draft.md
Expand Down Expand Up @@ -259,8 +259,8 @@ private MbwManager(Context evilContext) {
_eventTranslator = new EventTranslator(new Handler(), _eventBus);
_walletManager.addObserver(_eventTranslator);
_exchangeRateManager.subscribe(_eventTranslator);
coinapultManager = createCoinapultManager();
_walletManager.setExtraAccount(coinapultManager);
_coinapultManager = createCoinapultManager();
_walletManager.setExtraAccount(_coinapultManager);
migrateOldKeys();
createTempWalletManager();

Expand Down Expand Up @@ -1044,8 +1044,8 @@ public WalletAccount getSelectedAccount() {
}
}

if (coinapultManager.isPresent() && coinapultManager.get().getId().equals(uuid)) {
return coinapultManager.get();
if (_coinapultManager.isPresent() && _coinapultManager.get().getId().equals(uuid)) {
return _coinapultManager.get();
}

// If nothing is selected, or selected is archived, pick the first one
Expand Down Expand Up @@ -1190,15 +1190,14 @@ public void setPinRequiredOnStartup(boolean _pinRequiredOnStartup) {
* @return
*/
public CoinapultManager getCoinapultManager() {
if (coinapultManager.isPresent()) {
return coinapultManager.get();
if (_coinapultManager.isPresent()) {
return _coinapultManager.get();
} else {
//lazily create one
coinapultManager = createCoinapultManager();
_coinapultManager = createCoinapultManager();
//still not certain, if user never created one
if (coinapultManager.isPresent()) {
_walletManager.setExtraAccount(coinapultManager);
return coinapultManager.get();
if (_coinapultManager.isPresent()) {
return _coinapultManager.get();
} else {
throw new IllegalStateException("tried to obtain coinapult manager without having created one");
}
Expand Down
11 changes: 5 additions & 6 deletions public/mbw/src/main/java/com/mycelium/wallet/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,9 @@
import com.mycelium.wallet.activity.AdditionalBackupWarningActivity;
import com.mycelium.wallet.activity.export.BackupToPdfActivity;
import com.mycelium.wallet.activity.export.ExportAsQrCodeActivity;
import com.mycelium.wapi.wallet.AesKeyCipher;
import com.mycelium.wapi.wallet.currency.CurrencyValue;
import com.mycelium.wapi.wallet.currency.CurrencyBasedBalance;
import com.mycelium.wapi.wallet.currency.ExactBitcoinValue;
import com.mycelium.wapi.wallet.currency.ExactCurrencyValue;
import com.mycelium.wallet.persistence.MetadataStorage;
import com.mycelium.wapi.model.Balance;
import com.mycelium.wapi.wallet.ExportableAccount;
import com.mycelium.wapi.wallet.WalletAccount;
import com.mycelium.wapi.wallet.bip44.Bip44Account;
Expand Down Expand Up @@ -631,7 +628,7 @@ public void onClick(DialogInterface dialog, int id) {
}

public static void exportSelectedAccount(final Activity parent) {
WalletAccount account = MbwManager.getInstance(parent).getSelectedAccount();
final WalletAccount account = MbwManager.getInstance(parent).getSelectedAccount();
if (!(account instanceof ExportableAccount)) {
return;
}
Expand All @@ -641,7 +638,9 @@ public static void exportSelectedAccount(final Activity parent) {
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
Intent intent = new Intent(parent, ExportAsQrCodeActivity.class);
Intent intent = ExportAsQrCodeActivity.getIntent(parent,
((ExportableAccount) account).getExportData(AesKeyCipher.defaultKeyCipher())
);
parent.startActivity(intent);
}
}).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Html;
import android.text.InputType;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.coinapult.api.httpclient.CoinapultClient;
Expand Down Expand Up @@ -251,13 +249,16 @@ protected UUID doInBackground(Void... params) {
protected void onPostExecute(UUID account) {
_progress.dismiss();
if (account != null) {
_mbwManager.getWalletManager(false).setExtraAccount(Optional.of(coinapultManager));
bus.post(new AccountChanged(account));
Intent result = new Intent();
result.putExtra(RESULT_KEY, coinapultManager.getId());
setResult(RESULT_COINAPULT, result);
finish();
} else {
// something went wrong - clean up the half ready coinapultManager
Toast.makeText(AddAccountActivity.this, R.string.coinapult_unable_to_create_account, Toast.LENGTH_SHORT).show();
_mbwManager.getMetadataStorage().setPairedService("coinapult", false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,22 @@
import com.mycelium.wapi.wallet.AesKeyCipher;
import com.mycelium.wapi.wallet.ExportableAccount;
import com.mycelium.wapi.wallet.KeyCipher;
import com.mycelium.wapi.wallet.WalletAccount;

public class ExportAsQrCodeActivity extends Activity {


public static final String ACCOUNT = "account";
private MbwManager _mbwManager;
private WalletAccount account;
private ExportableAccount.Data accountData;
private Switch swSelectData;
private boolean hasWarningAccepted = false;

public static Intent getIntent(Activity activity, ExportableAccount.Data accountData){
Intent intent = new Intent(activity, ExportAsQrCodeActivity.class);
intent.putExtra(ACCOUNT, accountData);
return intent;
}

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
Expand All @@ -75,15 +81,18 @@ public void onCreate(Bundle savedInstanceState) {

// Get base58 encoded private key
_mbwManager = MbwManager.getInstance(getApplication());
account = _mbwManager.getSelectedAccount();
if (!(account instanceof ExportableAccount)) {
accountData = (ExportableAccount.Data) getIntent().getSerializableExtra(ACCOUNT);
if (accountData == null ||
(!accountData.publicData.isPresent() && !accountData.privateData.isPresent())
){
finish();
return;
}


// hide the priv/pub switch, if this is a watch-only account
// hide the priv/pub switch, if this is a watch-only accountData
swSelectData = (Switch) findViewById(R.id.swSelectData);
if (((ExportableAccount) account).containsPrivateData()) {
if (accountData.privateData.isPresent()) {
swSelectData.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
Expand Down Expand Up @@ -117,7 +126,7 @@ private void updateData() {
}

private boolean isPrivateDataSelected() {
if (((ExportableAccount) account).containsPrivateData()) {
if (accountData.privateData.isPresent()) {
return swSelectData.isChecked();
}else {
return false;
Expand Down Expand Up @@ -146,12 +155,8 @@ private void showPrivateData(){

if (hasWarningAccepted) {
setWarningVisibility(false);
try {
String privateData = ((ExportableAccount) account).getPrivateData(AesKeyCipher.defaultKeyCipher());
showData(privateData);
} catch (KeyCipher.InvalidKeyCipher invalidKeyCipher) {
throw new RuntimeException(invalidKeyCipher);
}
String privateData = accountData.privateData.get();
showData(privateData);
}else{
setWarningVisibility(true);
}
Expand All @@ -161,7 +166,7 @@ private void showPrivateData(){

private void showPublicData(){
setWarningVisibility(false);
String publicData = ((ExportableAccount) account).getPublicData();
String publicData = accountData.publicData.get();
showData(publicData);
((TextView)findViewById(R.id.tvWarning)).setText(this.getString(R.string.export_warning_pubkey));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,13 @@ private void updateUi() {
return;
}
WalletAccount account = Preconditions.checkNotNull(_mbwManager.getSelectedAccount());
CurrencyBasedBalance balance = Preconditions.checkNotNull(account.getCurrencyBasedBalance());

CurrencyBasedBalance balance;
try {
balance = Preconditions.checkNotNull(account.getCurrencyBasedBalance());
} catch (IllegalArgumentException ex){
_mbwManager.reportIgnoredException(ex);
balance = CurrencyBasedBalance.ZERO_BITCOIN_BALANCE;
}
if (account.canSpend()) {
// Show spend button
_root.findViewById(R.id.btSend).setVisibility(View.VISIBLE);
Expand Down
Loading

0 comments on commit 7e216bb

Please sign in to comment.