Skip to content

Commit

Permalink
Hv (#295)
Browse files Browse the repository at this point in the history
* hv
* Change build version
  • Loading branch information
mkyq committed Mar 30, 2022
1 parent e7e419b commit 01150ef
Show file tree
Hide file tree
Showing 213 changed files with 23,969 additions and 669 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Expand Up @@ -111,8 +111,11 @@ ios/build
*.sublime-project

shared_external/**
cw_shared_external/**
cw_haven/**
cw_shared_external/ios/External/
# cw_haven/**
cw_haven/ios/External/
cw_haven/android/.externalNativeBuild/
cw_haven/android/.cxx/

lib/bitcoin/bitcoin.dart
lib/monero/monero.dart
Expand Down
11 changes: 11 additions & 0 deletions android/app/src/main/java/com/cakewallet/haven/Application.java
@@ -0,0 +1,11 @@
package com.cakewallet.haven;

import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class Application extends FlutterApplication implements PluginRegistrantCallback {
@Override
public void registerWith(PluginRegistry registry) {}
}
90 changes: 90 additions & 0 deletions android/app/src/main/java/com/cakewallet/haven/MainActivity.java
@@ -0,0 +1,90 @@
package com.cakewallet.haven;

import androidx.annotation.NonNull;

import io.flutter.embedding.android.FlutterFragmentActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;

import android.os.AsyncTask;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.view.WindowManager;

import com.unstoppabledomains.resolution.DomainResolution;
import com.unstoppabledomains.resolution.Resolution;

import java.security.SecureRandom;

public class MainActivity extends FlutterFragmentActivity {
final String UTILS_CHANNEL = "com.cake_wallet/native_utils";
final int UNSTOPPABLE_DOMAIN_MIN_VERSION_SDK = 24;

@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);

MethodChannel utilsChannel =
new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(),
UTILS_CHANNEL);

utilsChannel.setMethodCallHandler(this::handle);
}

private void handle(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
Handler handler = new Handler(Looper.getMainLooper());

try {
switch (call.method) {
case "enableWakeScreen":
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
handler.post(() -> result.success(true));
break;
case "disableWakeScreen":
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
handler.post(() -> result.success(true));
break;
case "sec_random":
int count = call.argument("count");
SecureRandom random = new SecureRandom();
byte bytes[] = new byte[count];
random.nextBytes(bytes);
handler.post(() -> result.success(bytes));
break;
case "getUnstoppableDomainAddress":
int version = Build.VERSION.SDK_INT;
if (version >= UNSTOPPABLE_DOMAIN_MIN_VERSION_SDK) {
getUnstoppableDomainAddress(call, result);
} else {
handler.post(() -> result.success(""));
}
break;
default:
handler.post(() -> result.notImplemented());
}
} catch (Exception e) {
handler.post(() -> result.error("UNCAUGHT_ERROR", e.getMessage(), null));
}
}

private void getUnstoppableDomainAddress(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
DomainResolution resolution = new Resolution();
Handler handler = new Handler(Looper.getMainLooper());
String domain = call.argument("domain");
String ticker = call.argument("ticker");

AsyncTask.execute(() -> {
try {
String address = resolution.getAddress(domain, ticker);
handler.post(() -> result.success(address));
} catch (Exception e) {
System.out.println("Expected Address, but got " + e.getMessage());
handler.post(() -> result.success(""));
}
});
}
}
6 changes: 6 additions & 0 deletions assets/haven_node_list.yml
@@ -0,0 +1,6 @@
-
uri: vault.havenprotocol.org:443
login: super
password: super
useSSL: true
is_default: true
Binary file added assets/images/haven_logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/haven_menu.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 8 additions & 7 deletions cw_bitcoin/lib/electrum_wallet.dart
Expand Up @@ -33,6 +33,7 @@ import 'package:cw_core/transaction_priority.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_bitcoin/electrum.dart';
import 'package:hex/hex.dart';
import 'package:cw_core/crypto_currency.dart';

part 'electrum_wallet.g.dart';

Expand All @@ -49,16 +50,16 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
@required this.mnemonic,
ElectrumClient electrumClient,
ElectrumBalance initialBalance})
: balance = initialBalance ??
const ElectrumBalance(confirmed: 0, unconfirmed: 0),
hd = bitcoin.HDWallet.fromSeed(mnemonicToSeedBytes(mnemonic),
: hd = bitcoin.HDWallet.fromSeed(mnemonicToSeedBytes(mnemonic),
network: networkType)
.derivePath("m/0'/0"),
syncStatus = NotConnectedSyncStatus(),
_password = password,
_feeRates = <int>[],
_isTransactionUpdating = false,
super(walletInfo) {
balance = ObservableMap<CryptoCurrency, ElectrumBalance>.of({
currency: initialBalance ?? const ElectrumBalance(confirmed: 0, unconfirmed: 0)});
this.electrumClient = electrumClient ?? ElectrumClient();
this.walletInfo = walletInfo;
this.unspentCoinsInfo = unspentCoinsInfo;
Expand All @@ -82,7 +83,7 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,

@override
@observable
ElectrumBalance balance;
ObservableMap<CryptoCurrency, ElectrumBalance> balance;

@override
@observable
Expand Down Expand Up @@ -233,7 +234,7 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,

final totalAmount = amount + fee;

if (totalAmount > balance.confirmed || totalAmount > allInputsAmount) {
if (totalAmount > balance[currency].confirmed || totalAmount > allInputsAmount) {
throw BitcoinTransactionWrongBalanceException(currency);
}

Expand Down Expand Up @@ -326,7 +327,7 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
'account_index': walletAddresses.currentReceiveAddressIndex.toString(),
'change_address_index': walletAddresses.currentChangeAddressIndex.toString(),
'addresses': walletAddresses.addresses.map((addr) => addr.toJSON()).toList(),
'balance': balance?.toJSON()
'balance': balance[currency]?.toJSON()
});

int feeRate(TransactionPriority priority) {
Expand Down Expand Up @@ -617,7 +618,7 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
}

Future<void> _updateBalance() async {
balance = await _fetchBalances();
balance[currency] = await _fetchBalances();
await save();
}

Expand Down
8 changes: 1 addition & 7 deletions cw_monero/lib/account.dart → cw_core/lib/account.dart
@@ -1,16 +1,10 @@
import 'package:cw_monero/api/structs/account_row.dart';

class Account {
Account({this.id, this.label});

Account.fromMap(Map map)
: this.id = map['id'] == null ? 0 : int.parse(map['id'] as String),
this.label = (map['label'] ?? '') as String;

Account.fromRow(AccountRow row)
: this.id = row.getId(),
this.label = row.getLabel();

final int id;
final String label;
}
}
16 changes: 16 additions & 0 deletions cw_core/lib/account_list.dart
@@ -0,0 +1,16 @@
import 'package:mobx/mobx.dart';

abstract class AccountList<T> {

ObservableList<T> get accounts;

void update();

List<T> getAll();

Future addAccount({String label});

Future setLabelAccount({int accountIndex, String label});

void refresh();
}
74 changes: 73 additions & 1 deletion cw_core/lib/crypto_currency.dart
Expand Up @@ -23,7 +23,8 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> {
CryptoCurrency.usdt,
CryptoCurrency.usdterc20,
CryptoCurrency.xlm,
CryptoCurrency.xrp
CryptoCurrency.xrp,
CryptoCurrency.xhv
];
static const xmr = CryptoCurrency(title: 'XMR', raw: 0);
static const ada = CryptoCurrency(title: 'ADA', raw: 1);
Expand All @@ -41,6 +42,21 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> {
static const usdterc20 = CryptoCurrency(title: 'USDTERC20', raw: 13);
static const xlm = CryptoCurrency(title: 'XLM', raw: 14);
static const xrp = CryptoCurrency(title: 'XRP', raw: 15);
static const xhv = CryptoCurrency(title: 'XHV', raw: 16);

static const xag = CryptoCurrency(title: 'XAG', raw: 17);
static const xau = CryptoCurrency(title: 'XAU', raw: 18);
static const xaud = CryptoCurrency(title: 'XAUD', raw: 19);
static const xbtc = CryptoCurrency(title: 'XBTC', raw: 20);
static const xcad = CryptoCurrency(title: 'XCAD', raw: 21);
static const xchf = CryptoCurrency(title: 'XCHF', raw: 22);
static const xcny = CryptoCurrency(title: 'XCNY', raw: 23);
static const xeur = CryptoCurrency(title: 'XEUR', raw: 24);
static const xgbp = CryptoCurrency(title: 'XGBP', raw: 25);
static const xjpy = CryptoCurrency(title: 'XJPY', raw: 26);
static const xnok = CryptoCurrency(title: 'XNOK', raw: 27);
static const xnzd = CryptoCurrency(title: 'XNZD', raw: 28);
static const xusd = CryptoCurrency(title: 'XUSD', raw: 29);

static CryptoCurrency deserialize({int raw}) {
switch (raw) {
Expand Down Expand Up @@ -76,6 +92,34 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> {
return CryptoCurrency.xlm;
case 15:
return CryptoCurrency.xrp;
case 16:
return CryptoCurrency.xhv;
case 17:
return CryptoCurrency.xag;
case 18:
return CryptoCurrency.xau;
case 19:
return CryptoCurrency.xaud;
case 20:
return CryptoCurrency.xbtc;
case 21:
return CryptoCurrency.xcad;
case 22:
return CryptoCurrency.xchf;
case 23:
return CryptoCurrency.xcny;
case 24:
return CryptoCurrency.xeur;
case 25:
return CryptoCurrency.xgbp;
case 26:
return CryptoCurrency.xjpy;
case 27:
return CryptoCurrency.xnok;
case 28:
return CryptoCurrency.xnzd;
case 29:
return CryptoCurrency.xusd;
default:
return null;
}
Expand Down Expand Up @@ -115,6 +159,34 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> {
return CryptoCurrency.xlm;
case 'xrp':
return CryptoCurrency.xrp;
case 'xhv':
return CryptoCurrency.xhv;
case 'xag':
return CryptoCurrency.xag;
case 'xau':
return CryptoCurrency.xau;
case 'xaud':
return CryptoCurrency.xaud;
case 'xbtc':
return CryptoCurrency.xbtc;
case 'xcad':
return CryptoCurrency.xcad;
case 'xchf':
return CryptoCurrency.xchf;
case 'xcny':
return CryptoCurrency.xcny;
case 'xeur':
return CryptoCurrency.xeur;
case 'xgbp':
return CryptoCurrency.xgbp;
case 'xjpy':
return CryptoCurrency.xjpy;
case 'xnok':
return CryptoCurrency.xnok;
case 'xnzd':
return CryptoCurrency.xnzd;
case 'xusd':
return CryptoCurrency.xusd;
default:
return null;
}
Expand Down
2 changes: 2 additions & 0 deletions cw_core/lib/currency_for_wallet_type.dart
Expand Up @@ -9,6 +9,8 @@ CryptoCurrency currencyForWalletType(WalletType type) {
return CryptoCurrency.xmr;
case WalletType.litecoin:
return CryptoCurrency.ltc;
case WalletType.haven:
return CryptoCurrency.xhv;
default:
return null;
}
Expand Down
File renamed without changes.
Expand Up @@ -8,7 +8,8 @@ final moneroAmountFormat = NumberFormat()
..minimumFractionDigits = 1;

String moneroAmountToString({int amount}) => moneroAmountFormat
.format(cryptoAmountToDouble(amount: amount, divider: moneroAmountDivider));
.format(cryptoAmountToDouble(amount: amount, divider: moneroAmountDivider))
.replaceAll(',', '');

double moneroAmountToDouble({int amount}) =>
cryptoAmountToDouble(amount: amount, divider: moneroAmountDivider);
Expand Down
@@ -1,6 +1,6 @@
import 'package:cw_core/balance.dart';
import 'package:flutter/foundation.dart';
import 'package:cw_monero/monero_amount_format.dart';
import 'package:cw_core/monero_amount_format.dart';

class MoneroBalance extends Balance {
MoneroBalance({@required this.fullBalance, @required this.unlockedBalance})
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions cw_core/lib/node.dart
Expand Up @@ -60,6 +60,8 @@ class Node extends HiveObject with Keyable {
return createUriFromElectrumAddress(uriRaw);
case WalletType.litecoin:
return createUriFromElectrumAddress(uriRaw);
case WalletType.haven:
return Uri.http(uriRaw, '');
default:
return null;
}
Expand Down
12 changes: 12 additions & 0 deletions cw_core/lib/subaddress.dart
@@ -0,0 +1,12 @@
class Subaddress {
Subaddress({this.id, this.address, this.label});

Subaddress.fromMap(Map map)
: this.id = map['id'] == null ? 0 : int.parse(map['id'] as String),
this.address = (map['address'] ?? '') as String,
this.label = (map['label'] ?? '') as String;

final int id;
final String address;
final String label;
}
13 changes: 13 additions & 0 deletions cw_core/lib/wallet_addresses_with_account.dart
@@ -0,0 +1,13 @@
import 'package:cw_core/wallet_addresses.dart';
import 'package:cw_core/account_list.dart';
import 'package:cw_core/wallet_info.dart';

abstract class WalletAddressesWithAccount<T> extends WalletAddresses {
WalletAddressesWithAccount(WalletInfo walletInfo) : super(walletInfo);

T get account;

set account(T account);

AccountList<T> get accountList;
}

0 comments on commit 01150ef

Please sign in to comment.