Skip to content

Commit

Permalink
Generic fixes (#1282)
Browse files Browse the repository at this point in the history
* New versions

* Fix unspent coins issue

* Fix white screen issues for some users
  • Loading branch information
OmarHatem28 authored Jan 30, 2024
1 parent 952503f commit b92ccb5
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 53 deletions.
2 changes: 1 addition & 1 deletion lib/bitcoin/cw_bitcoin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class CWBitcoin extends Bitcoin {
return bitcoinWallet.unspentCoins;
}

void updateUnspents(Object wallet) async {
Future<void> updateUnspents(Object wallet) async {
final bitcoinWallet = wallet as ElectrumWallet;
await bitcoinWallet.updateUnspent();
}
Expand Down
7 changes: 5 additions & 2 deletions lib/entities/default_settings_migration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ Future<void> defaultSettingsMigration(
await rewriteSecureStoragePin(secureStorage: secureStorage);
break;
case 26:
await insecureStorageMigration(secureStorage: secureStorage, sharedPreferences: sharedPreferences);
/// commented out as it was a probable cause for some users to have white screen issues
/// maybe due to multiple access on Secure Storage at once
/// or long await time on start of the app
// await insecureStorageMigration(secureStorage: secureStorage, sharedPreferences: sharedPreferences);
break;
default:
break;
Expand Down Expand Up @@ -507,7 +510,7 @@ Future<void> changeLitecoinCurrentElectrumServerToDefault(
Future<void> changeBitcoinCashCurrentNodeToDefault(
{required SharedPreferences sharedPreferences, required Box<Node> nodes}) async {
final server = getBitcoinCashDefaultElectrumServer(nodes: nodes);
final serverId = server?.key as int ?? 0;
final serverId = server?.key as int? ?? 0;

await sharedPreferences.setInt(PreferencesKey.currentBitcoinCashNodeIdKey, serverId);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/monero/cw_monero.dart
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class CWMonero extends Monero {
}

@override
void updateUnspents(Object wallet) async {
Future<void> updateUnspents(Object wallet) async {
final moneroWallet = wallet as MoneroWallet;
await moneroWallet.updateUnspent();
}
Expand Down
20 changes: 11 additions & 9 deletions lib/src/screens/exchange_trade/exchange_trade_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,17 @@ class ExchangeTradeState extends State<ExchangeTradeForm> {

if (state is TransactionCommitted) {
WidgetsBinding.instance.addPostFrameCallback((_) {
showPopUp<void>(
context: context,
builder: (BuildContext popupContext) {
return AlertWithOneAction(
alertTitle: S.of(popupContext).sending,
alertContent: S.of(popupContext).transaction_sent,
buttonText: S.of(popupContext).ok,
buttonAction: () => Navigator.of(popupContext).pop());
});
if (context.mounted) {
showPopUp<void>(
context: context,
builder: (BuildContext popupContext) {
return AlertWithOneAction(
alertTitle: S.of(popupContext).sending,
alertContent: S.of(popupContext).transaction_sent,
buttonText: S.of(popupContext).ok,
buttonAction: () => Navigator.of(popupContext).pop());
});
}
});
}
});
Expand Down
10 changes: 5 additions & 5 deletions lib/src/screens/root/root.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ class RootState extends State<Root> with WidgetsBindingObserver {

@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback((_) async {
bool value = await widget.authService.requireAuth();
setState(() {
_requestAuth = value;
WidgetsBinding.instance.addObserver(this);

widget.authService.requireAuth().then((value) {
WidgetsBinding.instance.addPostFrameCallback((_) {
setState(() => _requestAuth = value);
});
});
_isInactiveController = StreamController<bool>.broadcast();
_isInactive = false;
_postFrameCallback = false;
WidgetsBinding.instance.addObserver(this);
super.initState();
if (DeviceInfo.instance.isMobile) {
initUniLinks();
Expand Down
12 changes: 11 additions & 1 deletion lib/store/settings_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ abstract class SettingsStoreBase with Store {
final allowBiometricalAuthentication = await SecureKey.getBool(
secureStorage: secureStorage,
sharedPreferences: sharedPreferences,
key: SecureKey.pinTimeOutDuration,
key: SecureKey.allowBiometricalAuthenticationKey,
) ??
false;

Expand Down Expand Up @@ -1247,6 +1247,16 @@ abstract class SettingsStoreBase with Store {
) ??
totpSecretKey;

final timeOutDuration = await SecureKey.getInt(
secureStorage: _secureStorage,
sharedPreferences: sharedPreferences,
key: SecureKey.pinTimeOutDuration,
);

pinTimeOutDuration = timeOutDuration != null
? PinCodeRequiredDuration.deserialize(raw: timeOutDuration)
: defaultPinCodeTimeOutDuration;

allowBiometricalAuthentication = await SecureKey.getBool(
secureStorage: _secureStorage,
sharedPreferences: sharedPreferences,
Expand Down
54 changes: 34 additions & 20 deletions lib/view_model/unspent_coins/unspent_coins_list_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,17 @@ abstract class UnspentCoinsListViewModelBase with Store {
UnspentCoinsListViewModelBase(
{required this.wallet, required Box<UnspentCoinsInfo> unspentCoinsInfo})
: _unspentCoinsInfo = unspentCoinsInfo {
_updateUnspentCoinsInfo();
_updateUnspents();
}

WalletBase wallet;
final Box<UnspentCoinsInfo> _unspentCoinsInfo;

final ObservableList<UnspentCoinsItem> _items = ObservableList();

@computed
ObservableList<UnspentCoinsItem> get items => ObservableList.of(_getUnspents().map((elem) {
final info =
getUnspentCoinInfo(elem.hash, elem.address, elem.value, elem.vout, elem.keyImage);

return UnspentCoinsItem(
address: elem.address,
amount: '${formatAmountToString(elem.value)} ${wallet.currency.title}',
hash: elem.hash,
isFrozen: info.isFrozen,
note: info.note,
isSending: info.isSending,
amountRaw: elem.value,
vout: elem.vout,
keyImage: elem.keyImage,
isChange: elem.isChange,
);
}));
ObservableList<UnspentCoinsItem> get items => _items;

Future<void> saveUnspentCoinInfo(UnspentCoinsItem item) async {
try {
Expand Down Expand Up @@ -77,9 +64,14 @@ abstract class UnspentCoinsListViewModelBase with Store {
}

Future<void> _updateUnspents() async {
if (wallet.type == WalletType.monero) return monero!.updateUnspents(wallet);
if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash].contains(wallet.type))
return bitcoin!.updateUnspents(wallet);
if (wallet.type == WalletType.monero) {
await monero!.updateUnspents(wallet);
}
if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash].contains(wallet.type)) {
await bitcoin!.updateUnspents(wallet);
}

_updateUnspentCoinsInfo();
}

List<Unspent> _getUnspents() {
Expand All @@ -88,4 +80,26 @@ abstract class UnspentCoinsListViewModelBase with Store {
return bitcoin!.getUnspents(wallet);
return List.empty();
}

@action
void _updateUnspentCoinsInfo() {
_items.clear();
_items.addAll(_getUnspents().map((elem) {
final info =
getUnspentCoinInfo(elem.hash, elem.address, elem.value, elem.vout, elem.keyImage);

return UnspentCoinsItem(
address: elem.address,
amount: '${formatAmountToString(elem.value)} ${wallet.currency.title}',
hash: elem.hash,
isFrozen: info.isFrozen,
note: info.note,
isSending: info.isSending,
amountRaw: elem.value,
vout: elem.vout,
keyImage: elem.keyImage,
isChange: elem.isChange,
);
}));
}
}
8 changes: 4 additions & 4 deletions scripts/android/app_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ TYPES=($MONERO_COM $CAKEWALLET $HAVEN)
APP_ANDROID_TYPE=$1

MONERO_COM_NAME="Monero.com"
MONERO_COM_VERSION="1.10.1"
MONERO_COM_BUILD_NUMBER=73
MONERO_COM_VERSION="1.10.2"
MONERO_COM_BUILD_NUMBER=74
MONERO_COM_BUNDLE_ID="com.monero.app"
MONERO_COM_PACKAGE="com.monero.app"
MONERO_COM_SCHEME="monero.com"

CAKEWALLET_NAME="Cake Wallet"
CAKEWALLET_VERSION="4.13.1"
CAKEWALLET_BUILD_NUMBER=190
CAKEWALLET_VERSION="4.13.2"
CAKEWALLET_BUILD_NUMBER=191
CAKEWALLET_BUNDLE_ID="com.cakewallet.cake_wallet"
CAKEWALLET_PACKAGE="com.cakewallet.cake_wallet"
CAKEWALLET_SCHEME="cakewallet"
Expand Down
8 changes: 4 additions & 4 deletions scripts/ios/app_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ TYPES=($MONERO_COM $CAKEWALLET $HAVEN)
APP_IOS_TYPE=$1

MONERO_COM_NAME="Monero.com"
MONERO_COM_VERSION="1.10.1"
MONERO_COM_BUILD_NUMBER=71
MONERO_COM_VERSION="1.10.2"
MONERO_COM_BUILD_NUMBER=72
MONERO_COM_BUNDLE_ID="com.cakewallet.monero"

CAKEWALLET_NAME="Cake Wallet"
CAKEWALLET_VERSION="4.13.1"
CAKEWALLET_BUILD_NUMBER=209
CAKEWALLET_VERSION="4.13.2"
CAKEWALLET_BUILD_NUMBER=210
CAKEWALLET_BUNDLE_ID="com.fotolockr.cakewallet"

HAVEN_NAME="Haven"
Expand Down
8 changes: 4 additions & 4 deletions scripts/macos/app_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ if [ -n "$1" ]; then
fi

MONERO_COM_NAME="Monero.com"
MONERO_COM_VERSION="1.0.1"
MONERO_COM_BUILD_NUMBER=3
MONERO_COM_VERSION="1.0.2"
MONERO_COM_BUILD_NUMBER=4
MONERO_COM_BUNDLE_ID="com.cakewallet.monero"

CAKEWALLET_NAME="Cake Wallet"
CAKEWALLET_VERSION="1.6.1"
CAKEWALLET_BUILD_NUMBER=51
CAKEWALLET_VERSION="1.6.2"
CAKEWALLET_BUILD_NUMBER=52
CAKEWALLET_BUNDLE_ID="com.fotolockr.cakewallet"

if ! [[ " ${TYPES[*]} " =~ " ${APP_MACOS_TYPE} " ]]; then
Expand Down
4 changes: 2 additions & 2 deletions tool/configure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ abstract class Bitcoin {
String bitcoinTransactionPriorityWithLabel(TransactionPriority priority, int rate);
List<Unspent> getUnspents(Object wallet);
void updateUnspents(Object wallet);
Future<void> updateUnspents(Object wallet);
WalletService createBitcoinWalletService(Box<WalletInfo> walletInfoSource, Box<UnspentCoinsInfo> unspentCoinSource);
WalletService createLitecoinWalletService(Box<WalletInfo> walletInfoSource, Box<UnspentCoinsInfo> unspentCoinSource);
TransactionPriority getBitcoinTransactionPriorityMedium();
Expand Down Expand Up @@ -270,7 +270,7 @@ abstract class Monero {
List<String> getMoneroWordList(String language);
List<Unspent> getUnspents(Object wallet);
void updateUnspents(Object wallet);
Future<void> updateUnspents(Object wallet);
WalletCredentials createMoneroRestoreWalletFromKeysCredentials({
required String name,
Expand Down

0 comments on commit b92ccb5

Please sign in to comment.