Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mweb checkbox #2000

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cw_bitcoin/lib/electrum_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,8 @@ abstract class ElectrumWalletBase
}).toList();
final unconfirmedCoins = availableInputs.where((utx) => utx.confirmations == 0).toList();

// sort the unconfirmed coins so that mweb coins are first:
availableInputs.sort((a, b) => a.bitcoinAddressRecord.type == SegwitAddresType.mweb ? -1 : 1);
// sort the unconfirmed coins so that mweb coins are last:
availableInputs.sort((a, b) => a.bitcoinAddressRecord.type == SegwitAddresType.mweb ? 1 : -1);

for (int i = 0; i < availableInputs.length; i++) {
final utx = availableInputs[i];
Expand Down
2 changes: 1 addition & 1 deletion lib/di.dart
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ Future<void> setup({
getIt.get<ContactListViewModel>(),
_transactionDescriptionBox,
getIt.get<AppStore>().wallet!.isHardwareWallet ? getIt.get<LedgerViewModel>() : null,
coinTypeToSpendFrom: coinTypeToSpendFrom ?? UnspentCoinType.any,
coinTypeToSpendFrom: coinTypeToSpendFrom ?? UnspentCoinType.nonMweb,
getIt.get<UnspentCoinsListViewModel>(param1: coinTypeToSpendFrom),
),
);
Expand Down
602 changes: 311 additions & 291 deletions lib/src/screens/send/send_page.dart

Large diffs are not rendered by default.

615 changes: 330 additions & 285 deletions lib/src/screens/send/widgets/send_card.dart

Large diffs are not rendered by default.

202 changes: 202 additions & 0 deletions lib/src/widgets/adaptable_page_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

const _firstLayoutMaxHeight = 10000.0;

class PageViewHeightAdaptable extends StatefulWidget {
const PageViewHeightAdaptable({
super.key,
required this.controller,
required this.children,
}) : assert(children.length > 0, 'children must not be empty');

final PageController controller;
final List<Widget> children;

@override
State<PageViewHeightAdaptable> createState() => _PageViewHeightAdaptableState();
}

class _PageViewHeightAdaptableState extends State<PageViewHeightAdaptable> {
final _sizes = <int, Size>{};

@override
void didUpdateWidget(PageViewHeightAdaptable oldWidget) {
super.didUpdateWidget(oldWidget);

_sizes.clear();
}

@override
Widget build(BuildContext context) {
return ListenableBuilder(
listenable: widget.controller,
builder: (context, child) => _SizingContainer(
sizes: _sizes,
page: widget.controller.hasClients ? widget.controller.page ?? 0 : 0,
child: child!,
),
child: LayoutBuilder(
builder: (context, constraints) => PageView(
controller: widget.controller,
children: [
for (final (i, child) in widget.children.indexed)
Stack(
alignment: Alignment.topCenter,
clipBehavior: Clip.hardEdge,
children: [
SizedBox.fromSize(size: _sizes[i]),
Positioned(
left: 0,
top: 0,
right: 0,
child: _SizeAware(
child: child,
// don't setState, we'll use it in the layout phase
onSizeLaidOut: (size) {
_sizes[i] = size;
},
),
),
],
),
],
),
),
);
}
}

typedef _OnSizeLaidOutCallback = void Function(Size);

class _SizingContainer extends SingleChildRenderObjectWidget {
const _SizingContainer({
super.child,
required this.sizes,
required this.page,
});

final Map<int, Size> sizes;
final double page;

@override
_RenderSizingContainer createRenderObject(BuildContext context) {
return _RenderSizingContainer(
sizes: sizes,
page: page,
);
}

@override
void updateRenderObject(
BuildContext context,
_RenderSizingContainer renderObject,
) {
renderObject
..sizes = sizes
..page = page;
}
}

class _RenderSizingContainer extends RenderProxyBox {
_RenderSizingContainer({
RenderBox? child,
required Map<int, Size> sizes,
required double page,
}) : _sizes = sizes,
_page = page,
super(child);

Map<int, Size> _sizes;
Map<int, Size> get sizes => _sizes;
set sizes(Map<int, Size> value) {
if (_sizes == value) return;
_sizes = value;
markNeedsLayout();
}

double _page;
double get page => _page;
set page(double value) {
if (_page == value) return;
_page = value;
markNeedsLayout();
}

@override
void performLayout() {
if (child case final child?) {
child.layout(
constraints.copyWith(
minWidth: constraints.maxWidth,
minHeight: 0,
maxHeight: constraints.hasBoundedHeight ? null : _firstLayoutMaxHeight,
),
parentUsesSize: true,
);

final a = sizes[page.floor()]!;
final b = sizes[page.ceil()]!;

final height = lerpDouble(a.height, b.height, page - page.floor());

child.layout(
constraints.copyWith(minHeight: height, maxHeight: height),
parentUsesSize: true,
);
size = child.size;
} else {
size = computeSizeForNoChild(constraints);
}
}
}

class _SizeAware extends SingleChildRenderObjectWidget {
const _SizeAware({
required Widget child,
required this.onSizeLaidOut,
}) : super(child: child);

final _OnSizeLaidOutCallback onSizeLaidOut;

@override
_RenderSizeAware createRenderObject(BuildContext context) {
return _RenderSizeAware(
onSizeLaidOut: onSizeLaidOut,
);
}

@override
void updateRenderObject(BuildContext context, _RenderSizeAware renderObject) {
renderObject.onSizeLaidOut = onSizeLaidOut;
}
}

class _RenderSizeAware extends RenderProxyBox {
_RenderSizeAware({
RenderBox? child,
required _OnSizeLaidOutCallback onSizeLaidOut,
}) : _onSizeLaidOut = onSizeLaidOut,
super(child);

_OnSizeLaidOutCallback? _onSizeLaidOut;
_OnSizeLaidOutCallback get onSizeLaidOut => _onSizeLaidOut!;
set onSizeLaidOut(_OnSizeLaidOutCallback value) {
if (_onSizeLaidOut == value) return;
_onSizeLaidOut = value;
markNeedsLayout();
}

@override
void performLayout() {
super.performLayout();

onSizeLaidOut(
getDryLayout(
constraints.copyWith(maxHeight: double.infinity),
),
);
}
}
4 changes: 3 additions & 1 deletion lib/src/widgets/standard_checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ class StandardCheckbox extends StatelessWidget {
this.gradientBackground = false,
this.borderColor,
this.iconColor,
this.captionColor,
required this.onChanged});

final bool value;
final String caption;
final bool gradientBackground;
final Color? borderColor;
final Color? iconColor;
final Color? captionColor;
final Function(bool) onChanged;

@override
Expand Down Expand Up @@ -68,7 +70,7 @@ class StandardCheckbox extends StatelessWidget {
fontSize: 16.0,
fontFamily: 'Lato',
fontWeight: FontWeight.normal,
color: Theme.of(context).extension<CakeTextTheme>()!.titleColor,
color: captionColor ?? Theme.of(context).extension<CakeTextTheme>()!.titleColor,
decoration: TextDecoration.none,
),
),
Expand Down
12 changes: 10 additions & 2 deletions lib/view_model/send/send_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
this.transactionDescriptionBox,
this.ledgerViewModel,
this.unspentCoinsListViewModel, {
this.coinTypeToSpendFrom = UnspentCoinType.any,
this.coinTypeToSpendFrom = UnspentCoinType.nonMweb,
}) : state = InitialExecutionState(),
currencies = appStore.wallet!.balance.keys.toList(),
selectedCryptoCurrency = appStore.wallet!.currency,
Expand Down Expand Up @@ -110,7 +110,8 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor

ObservableList<Output> outputs;

final UnspentCoinType coinTypeToSpendFrom;
@observable
UnspentCoinType coinTypeToSpendFrom;

bool get showAddressBookPopup => _settingsStore.showAddressBookPopupEnabled;

Expand All @@ -133,6 +134,13 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
addOutput();
}

@action
void setAllowMwebCoins(bool allow) {
if (wallet.type == WalletType.litecoin) {
coinTypeToSpendFrom = allow ? UnspentCoinType.any : UnspentCoinType.nonMweb;
}
}

@computed
bool get isBatchSending => outputs.length > 1;

Expand Down
1 change: 1 addition & 0 deletions res/values/strings_ar.arb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@
"light_theme": "فاتح",
"litecoin_enable_mweb_sync": "تمكين MWEB المسح الضوئي",
"litecoin_mweb": "mweb",
"litecoin_mweb_allow_coins": "السماح للعملات المعدنية MWEB",
"litecoin_mweb_always_scan": "اضبط MWEB دائمًا على المسح الضوئي",
"litecoin_mweb_description": "MWEB هو بروتوكول جديد يجلب معاملات أسرع وأرخص وأكثر خصوصية إلى Litecoin",
"litecoin_mweb_dismiss": "رفض",
Expand Down
1 change: 1 addition & 0 deletions res/values/strings_bg.arb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@
"light_theme": "Светло",
"litecoin_enable_mweb_sync": "Активирайте сканирането на MWeb",
"litecoin_mweb": "Mweb",
"litecoin_mweb_allow_coins": "Позволете на MWeb монети",
"litecoin_mweb_always_scan": "Задайте MWeb винаги сканиране",
"litecoin_mweb_description": "MWeb е нов протокол, който носи по -бърз, по -евтин и повече частни транзакции на Litecoin",
"litecoin_mweb_dismiss": "Уволнение",
Expand Down
1 change: 1 addition & 0 deletions res/values/strings_cs.arb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@
"light_theme": "Světlý",
"litecoin_enable_mweb_sync": "Povolit skenování MWeb",
"litecoin_mweb": "MWeb",
"litecoin_mweb_allow_coins": "Povolte mweb mince",
"litecoin_mweb_always_scan": "Nastavit MWeb vždy skenování",
"litecoin_mweb_description": "MWEB je nový protokol, který do Litecoin přináší rychlejší, levnější a více soukromých transakcí",
"litecoin_mweb_dismiss": "Propustit",
Expand Down
1 change: 1 addition & 0 deletions res/values/strings_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@
"light_theme": "Hell",
"litecoin_enable_mweb_sync": "Aktivieren Sie das MWEB-Scannen",
"litecoin_mweb": "MWeb",
"litecoin_mweb_allow_coins": "MWEB -Münzen zulassen",
"litecoin_mweb_always_scan": "Setzen Sie MWeb immer scannen",
"litecoin_mweb_description": "MWWB ist ein neues Protokoll, das schnellere, billigere und privatere Transaktionen zu Litecoin bringt",
"litecoin_mweb_dismiss": "Zurückweisen",
Expand Down
1 change: 1 addition & 0 deletions res/values/strings_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@
"light_theme": "Light",
"litecoin_enable_mweb_sync": "Enable MWEB scanning",
"litecoin_mweb": "MWEB",
"litecoin_mweb_allow_coins": "Allow MWEB coins",
"litecoin_mweb_always_scan": "Set MWEB always scanning",
"litecoin_mweb_description": "MWEB is a new protocol that brings faster, cheaper, and more private transactions to Litecoin",
"litecoin_mweb_dismiss": "Dismiss",
Expand Down
1 change: 1 addition & 0 deletions res/values/strings_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@
"light_theme": "Ligero",
"litecoin_enable_mweb_sync": "Habilitar el escaneo mweb",
"litecoin_mweb": "Mweb",
"litecoin_mweb_allow_coins": "Permitir monedas mweb",
"litecoin_mweb_always_scan": "Establecer mweb siempre escaneo",
"litecoin_mweb_description": "Mweb es un nuevo protocolo que trae transacciones más rápidas, más baratas y más privadas a Litecoin",
"litecoin_mweb_dismiss": "Despedir",
Expand Down
1 change: 1 addition & 0 deletions res/values/strings_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@
"light_theme": "Clair",
"litecoin_enable_mweb_sync": "Activer la numérisation MWEB",
"litecoin_mweb": "Mweb",
"litecoin_mweb_allow_coins": "Autoriser les pièces MWeb",
"litecoin_mweb_always_scan": "Définir MWEB Score Scanning",
"litecoin_mweb_description": "MWEB est un nouveau protocole qui apporte des transactions plus rapides, moins chères et plus privées à Litecoin",
"litecoin_mweb_dismiss": "Rejeter",
Expand Down
1 change: 1 addition & 0 deletions res/values/strings_ha.arb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@
"light_theme": "Haske",
"litecoin_enable_mweb_sync": "Kunna binciken Mweb",
"litecoin_mweb": "Mweb",
"litecoin_mweb_allow_coins": "Bada izinin Coins na Mweb",
"litecoin_mweb_always_scan": "Saita Mweb koyaushe",
"litecoin_mweb_description": "Mweb shine sabon tsarin yarjejeniya da ya kawo da sauri, mai rahusa, da kuma ma'amaloli masu zaman kansu zuwa Litecoin",
"litecoin_mweb_dismiss": "Tuɓe \\ sallama",
Expand Down
1 change: 1 addition & 0 deletions res/values/strings_hi.arb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@
"light_theme": "रोशनी",
"litecoin_enable_mweb_sync": "MWEB स्कैनिंग सक्षम करें",
"litecoin_mweb": "मावली",
"litecoin_mweb_allow_coins": "MWEB सिक्कों की अनुमति दें",
"litecoin_mweb_always_scan": "MWEB हमेशा स्कैनिंग सेट करें",
"litecoin_mweb_description": "MWEB एक नया प्रोटोकॉल है जो लिटकोइन के लिए तेजी से, सस्ता और अधिक निजी लेनदेन लाता है",
"litecoin_mweb_dismiss": "नकार देना",
Expand Down
1 change: 1 addition & 0 deletions res/values/strings_hr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@
"light_theme": "Svijetla",
"litecoin_enable_mweb_sync": "Omogućite MWEB skeniranje",
"litecoin_mweb": "MWeb",
"litecoin_mweb_allow_coins": "Dopustite MWeb kovanice",
"litecoin_mweb_always_scan": "Postavite MWeb uvijek skeniranje",
"litecoin_mweb_description": "MWEB je novi protokol koji u Litecoin donosi brže, jeftinije i privatnije transakcije",
"litecoin_mweb_dismiss": "Odbaciti",
Expand Down
1 change: 1 addition & 0 deletions res/values/strings_hy.arb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@
"light_theme": "Լուսավոր",
"litecoin_enable_mweb_sync": "Միացնել MWEB սկան",
"litecoin_mweb": "Մուեբ",
"litecoin_mweb_allow_coins": "Թույլ տվեք MWeb մետաղադրամներ",
"litecoin_mweb_always_scan": "Սահմանեք Mweb Միշտ սկանավորում",
"litecoin_mweb_description": "Mweb- ը նոր արձանագրություն է, որը բերում է ավելի արագ, ավելի էժան եւ ավելի մասնավոր գործարքներ դեպի LITECOIN",
"litecoin_mweb_dismiss": "Հեռացնել",
Expand Down
1 change: 1 addition & 0 deletions res/values/strings_id.arb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@
"light_theme": "Terang",
"litecoin_enable_mweb_sync": "Aktifkan pemindaian MWEB",
"litecoin_mweb": "Mweb",
"litecoin_mweb_allow_coins": "Izinkan koin mWeb",
"litecoin_mweb_always_scan": "Atur mWeb selalu memindai",
"litecoin_mweb_description": "MWEB adalah protokol baru yang membawa transaksi yang lebih cepat, lebih murah, dan lebih pribadi ke Litecoin",
"litecoin_mweb_dismiss": "Membubarkan",
Expand Down
1 change: 1 addition & 0 deletions res/values/strings_it.arb
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@
"light_theme": "Bianco",
"litecoin_enable_mweb_sync": "Abilita la scansione MWeb",
"litecoin_mweb": "MWeb",
"litecoin_mweb_allow_coins": "Consenti monete mWeb",
"litecoin_mweb_always_scan": "Imposta MWeb per scansionare sempre",
"litecoin_mweb_description": "MWeb è un nuovo protocollo che porta transazioni più veloci, più economiche e più private a Litecoin",
"litecoin_mweb_dismiss": "Congedare",
Expand Down
1 change: 1 addition & 0 deletions res/values/strings_ja.arb
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@
"light_theme": "光",
"litecoin_enable_mweb_sync": "MWEBスキャンを有効にします",
"litecoin_mweb": "mweb",
"litecoin_mweb_allow_coins": "MWEBコインを許可します",
"litecoin_mweb_always_scan": "MWEBを常にスキャンします",
"litecoin_mweb_description": "MWEBは、Litecoinにより速く、より安価で、よりプライベートなトランザクションをもたらす新しいプロトコルです",
"litecoin_mweb_dismiss": "却下する",
Expand Down
Loading
Loading