Skip to content

Commit

Permalink
Generic enhancements (#1668)
Browse files Browse the repository at this point in the history
* Add more choices for pin code required duration

* Fix spacing in Cake Features

* Update Cake Features cards

* Update Cake Pay image

* Add NanoGPT image

* Update Sign/Verify strings

* Update more flags

* update moonpay currency name

* Update more icons

* Add friendly message for less than minimum fee

* fix translation [skip ci]

* Fix icon theming and add Telegram link

* Fix color issue for restore screen

* rename matic poly to pol

* minor potential fix [skip ci]

* minor fix [skip ci]

* Update analysis_options.yaml

* fix translations

* fix translation

* revert regex changes

* Update bitcoin_cash_electrum_server_list.yml

* Update address_validator.dart

---------

Co-authored-by: OmarHatem <[email protected]>
  • Loading branch information
tuxpizza and OmarHatem28 authored Sep 23, 2024
1 parent e2b3507 commit 6592b7a
Show file tree
Hide file tree
Showing 58 changed files with 276 additions and 194 deletions.
3 changes: 2 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include: package:lints/recommended.yaml


analyzer:
exclude: [
build/**,
Expand Down Expand Up @@ -83,4 +84,4 @@ linter:
# - unawaited_futures
# - unnecessary_getters_setters
# - unrelated_type_equality_checks
# - valid_regexps
# - valid_regexps
9 changes: 8 additions & 1 deletion assets/bitcoin_cash_electrum_server_list.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-
uri: bitcoincash.stackwallet.com:50002
is_default: true
is_default: true
useSSL: true
-
uri: bch.aftrek.org:50002
useSSL: true
-
uri: node.minisatoshi.cash:50002
useSSL: true
Binary file added assets/images/cards.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 0 additions & 65 deletions assets/images/cards.svg

This file was deleted.

Binary file modified assets/images/flags/arm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/flags/bra.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/flags/hau.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/flags/ind.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/flags/ukr.png
Loading
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/nanogpt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions cw_bitcoin/lib/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ class BitcoinTransactionCommitFailedVoutNegative extends TransactionCommitFailed

class BitcoinTransactionCommitFailedBIP68Final extends TransactionCommitFailedBIP68Final {}

class BitcoinTransactionCommitFailedLessThanMin extends TransactionCommitFailedBIP68Final {}

class BitcoinTransactionSilentPaymentsNotSupported extends TransactionInputNotSupported {}
4 changes: 4 additions & 0 deletions cw_bitcoin/lib/pending_bitcoin_transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class PendingBitcoinTransaction with PendingTransaction {
throw BitcoinTransactionCommitFailedBIP68Final();
}

if (error.contains("min fee not met")) {
throw BitcoinTransactionCommitFailedLessThanMin();
}

throw BitcoinTransactionCommitFailed(errorMessage: error);
}

Expand Down
2 changes: 1 addition & 1 deletion cw_core/lib/crypto_currency.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> implemen
static const dcr = CryptoCurrency(title: 'DCR', fullName: 'Decred', raw: 47, name: 'dcr', iconPath: 'assets/images/dcr_icon.png', decimals: 8);
static const kmd = CryptoCurrency(title: 'KMD', fullName: 'Komodo', raw: 48, name: 'kmd', iconPath: 'assets/images/kmd_icon.png', decimals: 8);
static const mana = CryptoCurrency(title: 'MANA', tag: 'ETH', fullName: 'Decentraland', raw: 49, name: 'mana', iconPath: 'assets/images/mana_icon.png', decimals: 18);
static const maticpoly = CryptoCurrency(title: 'MATIC', tag: 'POLY', fullName: 'Polygon', raw: 50, name: 'maticpoly', iconPath: 'assets/images/matic_icon.png', decimals: 18);
static const maticpoly = CryptoCurrency(title: 'POL', tag: 'POLY', fullName: 'Polygon', raw: 50, name: 'maticpoly', iconPath: 'assets/images/matic_icon.png', decimals: 18);
static const matic = CryptoCurrency(title: 'MATIC', tag: 'ETH', fullName: 'Polygon', raw: 51, name: 'matic', iconPath: 'assets/images/matic_icon.png', decimals: 18);
static const mkr = CryptoCurrency(title: 'MKR', tag: 'ETH', fullName: 'Maker', raw: 52, name: 'mkr', iconPath: 'assets/images/mkr_icon.png', decimals: 18);
static const near = CryptoCurrency(title: 'NEAR', fullName: 'NEAR Protocol', raw: 53, name: 'near', iconPath: 'assets/images/near_icon.png', decimals: 24);
Expand Down
2 changes: 2 additions & 0 deletions cw_core/lib/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ class TransactionCommitFailedVoutNegative implements Exception {}

class TransactionCommitFailedBIP68Final implements Exception {}

class TransactionCommitFailedLessThanMin implements Exception {}

class TransactionInputNotSupported implements Exception {}
2 changes: 1 addition & 1 deletion cw_ethereum/lib/ethereum_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class EthereumWallet extends EVMChainWallet {
if (!hasKeysFile) rethrow;
}

final balance = EVMChainERC20Balance.fromJSON(data?['balance'] as String) ??
final balance = EVMChainERC20Balance.fromJSON(data?['balance'] as String?) ??
EVMChainERC20Balance(BigInt.zero);

final WalletKeysData keysData;
Expand Down
4 changes: 3 additions & 1 deletion lib/buy/moonpay/moonpay_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ class MoonPayProvider extends BuyProvider {

String _normalizeCurrency(CryptoCurrency currency) {
if (currency == CryptoCurrency.maticpoly) {
return "MATIC_POLYGON";
return "POL_POLYGON";
} else if (currency == CryptoCurrency.matic) {
return "POL";
}

return currency.toString().toLowerCase();
Expand Down
116 changes: 55 additions & 61 deletions lib/core/address_validator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import 'package:cake_wallet/solana/solana.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/erc20_token.dart';

const BEFORE_REGEX = '(^|\s)';
const AFTER_REGEX = '(\$|\s)';

class AddressValidator extends TextValidator {
AddressValidator({required CryptoCurrency type})
: super(
Expand All @@ -22,23 +19,21 @@ class AddressValidator extends TextValidator {
length: getLength(type));

static String getPattern(CryptoCurrency type) {
var pattern = "";
if (type is Erc20Token) {
pattern = '0x[0-9a-zA-Z]';
return '0x[0-9a-zA-Z]';
}
switch (type) {
case CryptoCurrency.xmr:
pattern = '4[0-9a-zA-Z]{94}|8[0-9a-zA-Z]{94}|[0-9a-zA-Z]{106}';
return '^4[0-9a-zA-Z]{94}\$|^8[0-9a-zA-Z]{94}\$|^[0-9a-zA-Z]{106}\$';
case CryptoCurrency.ada:
pattern = '[0-9a-zA-Z]{59}|[0-9a-zA-Z]{92}|[0-9a-zA-Z]{104}'
'|[0-9a-zA-Z]{105}|addr1[0-9a-zA-Z]{98}';
return '^[0-9a-zA-Z]{59}\$|^[0-9a-zA-Z]{92}\$|^[0-9a-zA-Z]{104}\$'
'|^[0-9a-zA-Z]{105}\$|^addr1[0-9a-zA-Z]{98}\$';
case CryptoCurrency.btc:
pattern =
'${P2pkhAddress.regex.pattern}|${P2shAddress.regex.pattern}|${P2wpkhAddress.regex.pattern}|${P2trAddress.regex.pattern}|${P2wshAddress.regex.pattern}|${SilentPaymentAddress.regex.pattern}';
return '^${P2pkhAddress.regex.pattern}\$|^${P2shAddress.regex.pattern}\$|^${P2wpkhAddress.regex.pattern}\$|${P2trAddress.regex.pattern}\$|^${P2wshAddress.regex.pattern}\$|^${SilentPaymentAddress.regex.pattern}\$';
case CryptoCurrency.nano:
pattern = '[0-9a-zA-Z_]';
return '[0-9a-zA-Z_]';
case CryptoCurrency.banano:
pattern = '[0-9a-zA-Z_]';
return '[0-9a-zA-Z_]';
case CryptoCurrency.usdc:
case CryptoCurrency.usdcpoly:
case CryptoCurrency.usdtPoly:
Expand Down Expand Up @@ -74,11 +69,11 @@ class AddressValidator extends TextValidator {
case CryptoCurrency.dydx:
case CryptoCurrency.steth:
case CryptoCurrency.shib:
pattern = '0x[0-9a-zA-Z]';
return '0x[0-9a-zA-Z]';
case CryptoCurrency.xrp:
pattern = '[0-9a-zA-Z]{34}|X[0-9a-zA-Z]{46}';
return '^[0-9a-zA-Z]{34}\$|^X[0-9a-zA-Z]{46}\$';
case CryptoCurrency.xhv:
pattern = 'hvx|hvi|hvs[0-9a-zA-Z]';
return '^hvx|hvi|hvs[0-9a-zA-Z]';
case CryptoCurrency.xag:
case CryptoCurrency.xau:
case CryptoCurrency.xaud:
Expand All @@ -100,43 +95,40 @@ class AddressValidator extends TextValidator {
case CryptoCurrency.dash:
case CryptoCurrency.eos:
case CryptoCurrency.wow:
pattern = '[0-9a-zA-Z]';
return '[0-9a-zA-Z]';
case CryptoCurrency.bch:
pattern =
'(?!bitcoincash:)[0-9a-zA-Z]*|(?!bitcoincash:)q|p[0-9a-zA-Z]{41}|(?!bitcoincash:)q|p[0-9a-zA-Z]{42}|bitcoincash:q|p[0-9a-zA-Z]{41}|bitcoincash:q|p[0-9a-zA-Z]{42}';
return '^(?!bitcoincash:)[0-9a-zA-Z]*\$|^(?!bitcoincash:)q|p[0-9a-zA-Z]{41}\$|^(?!bitcoincash:)q|p[0-9a-zA-Z]{42}\$|^bitcoincash:q|p[0-9a-zA-Z]{41}\$|^bitcoincash:q|p[0-9a-zA-Z]{42}\$';
case CryptoCurrency.bnb:
pattern = '[0-9a-zA-Z]';
return '[0-9a-zA-Z]';
case CryptoCurrency.ltc:
pattern = '(?!(ltc|LTC)1)[0-9a-zA-Z]*|(LTC1[A-Z0-9]*)|(ltc1[a-z0-9]*)';
return '^(?!(ltc|LTC)1)[0-9a-zA-Z]*\$|(^LTC1[A-Z0-9]*\$)|(^ltc1[a-z0-9]*\$)';
case CryptoCurrency.hbar:
pattern = '[0-9a-zA-Z.]';
return '[0-9a-zA-Z.]';
case CryptoCurrency.zaddr:
pattern = 'zs[0-9a-zA-Z]{75}';
return '^zs[0-9a-zA-Z]{75}';
case CryptoCurrency.zec:
pattern = 't1[0-9a-zA-Z]{33}|t3[0-9a-zA-Z]{33}';
return '^t1[0-9a-zA-Z]{33}\$|^t3[0-9a-zA-Z]{33}\$';
case CryptoCurrency.dcr:
pattern = 'D[ksecS]([0-9a-zA-Z])+';
return 'D[ksecS]([0-9a-zA-Z])+';
case CryptoCurrency.rvn:
pattern = '[Rr]([1-9a-km-zA-HJ-NP-Z]){33}';
return '[Rr]([1-9a-km-zA-HJ-NP-Z]){33}';
case CryptoCurrency.near:
pattern = '[0-9a-f]{64}';
return '[0-9a-f]{64}';
case CryptoCurrency.rune:
pattern = 'thor1[0-9a-z]{38}';
return 'thor1[0-9a-z]{38}';
case CryptoCurrency.scrt:
pattern = 'secret1[0-9a-z]{38}';
return 'secret1[0-9a-z]{38}';
case CryptoCurrency.stx:
pattern = 'S[MP][0-9a-zA-Z]+';
return 'S[MP][0-9a-zA-Z]+';
case CryptoCurrency.kmd:
pattern = 'R[0-9a-zA-Z]{33}';
return 'R[0-9a-zA-Z]{33}';
case CryptoCurrency.pivx:
pattern = 'D([1-9a-km-zA-HJ-NP-Z]){33}';
return 'D([1-9a-km-zA-HJ-NP-Z]){33}';
case CryptoCurrency.btcln:
pattern = '(lnbc|LNBC)([0-9]{1,}[a-zA-Z0-9]+)';
return '^(lnbc|LNBC)([0-9]{1,}[a-zA-Z0-9]+)';
default:
pattern = '[0-9a-zA-Z]';
return '[0-9a-zA-Z]';
}

return '$BEFORE_REGEX$pattern$AFTER_REGEX';
}

static List<int>? getLength(CryptoCurrency type) {
Expand Down Expand Up @@ -277,54 +269,56 @@ class AddressValidator extends TextValidator {
}

static String? getAddressFromStringPattern(CryptoCurrency type) {
String? pattern = null;

switch (type) {
case CryptoCurrency.xmr:
case CryptoCurrency.wow:
pattern = '4[0-9a-zA-Z]{94}'
'|8[0-9a-zA-Z]{94}'
'|[0-9a-zA-Z]{106}';
return '([^0-9a-zA-Z]|^)4[0-9a-zA-Z]{94}([^0-9a-zA-Z]|\$)'
'|([^0-9a-zA-Z]|^)8[0-9a-zA-Z]{94}([^0-9a-zA-Z]|\$)'
'|([^0-9a-zA-Z]|^)[0-9a-zA-Z]{106}([^0-9a-zA-Z]|\$)';
case CryptoCurrency.btc:
pattern =
'${P2pkhAddress.regex.pattern}|${P2shAddress.regex.pattern}|${P2wpkhAddress.regex.pattern}|${P2trAddress.regex.pattern}|${P2wshAddress.regex.pattern}|${SilentPaymentAddress.regex.pattern}';
return '([^0-9a-zA-Z]|^)([1mn][a-km-zA-HJ-NP-Z1-9]{25,34})([^0-9a-zA-Z]|\$)' //P2pkhAddress type
'|([^0-9a-zA-Z]|^)([23][a-km-zA-HJ-NP-Z1-9]{25,34})([^0-9a-zA-Z]|\$)' //P2shAddress type
'|([^0-9a-zA-Z]|^)((bc|tb)1q[ac-hj-np-z02-9]{25,39})([^0-9a-zA-Z]|\$)' //P2wpkhAddress type
'|([^0-9a-zA-Z]|^)((bc|tb)1q[ac-hj-np-z02-9]{40,80})([^0-9a-zA-Z]|\$)' //P2wshAddress type
'|([^0-9a-zA-Z]|^)((bc|tb)1p([ac-hj-np-z02-9]{39}|[ac-hj-np-z02-9]{59}|[ac-hj-np-z02-9]{8,89}))([^0-9a-zA-Z]|\$)' //P2trAddress type
'|${SilentPaymentAddress.regex.pattern}\$';

case CryptoCurrency.ltc:
pattern = '^L[a-zA-Z0-9]{26,33}'
'|[LM][a-km-zA-HJ-NP-Z1-9]{26,33}'
'|ltc[a-zA-Z0-9]{26,45}';
return '([^0-9a-zA-Z]|^)^L[a-zA-Z0-9]{26,33}([^0-9a-zA-Z]|\$)'
'|([^0-9a-zA-Z]|^)[LM][a-km-zA-HJ-NP-Z1-9]{26,33}([^0-9a-zA-Z]|\$)'
'|([^0-9a-zA-Z]|^)ltc[a-zA-Z0-9]{26,45}([^0-9a-zA-Z]|\$)';
case CryptoCurrency.eth:
pattern = '0x[0-9a-zA-Z]{42}';
return '0x[0-9a-zA-Z]{42}';
case CryptoCurrency.maticpoly:
pattern = '0x[0-9a-zA-Z]{42}';
return '0x[0-9a-zA-Z]{42}';
case CryptoCurrency.nano:
pattern = 'nano_[0-9a-zA-Z]{60}';
return 'nano_[0-9a-zA-Z]{60}';
case CryptoCurrency.banano:
pattern = 'ban_[0-9a-zA-Z]{60}';
return 'ban_[0-9a-zA-Z]{60}';
case CryptoCurrency.bch:
pattern = '(bitcoincash:)?q[0-9a-zA-Z]{41,42}';
return 'bitcoincash:q[0-9a-zA-Z]{41}([^0-9a-zA-Z]|\$)'
'|bitcoincash:q[0-9a-zA-Z]{42}([^0-9a-zA-Z]|\$)'
'|([^0-9a-zA-Z]|^)q[0-9a-zA-Z]{41}([^0-9a-zA-Z]|\$)'
'|([^0-9a-zA-Z]|^)q[0-9a-zA-Z]{42}([^0-9a-zA-Z]|\$)';
case CryptoCurrency.sol:
pattern = '[1-9A-HJ-NP-Za-km-z]{43,44}';
return '([^0-9a-zA-Z]|^)[1-9A-HJ-NP-Za-km-z]{43,44}([^0-9a-zA-Z]|\$)';
case CryptoCurrency.trx:
pattern = '(T|t)[1-9A-HJ-NP-Za-km-z]{33}';
return '(T|t)[1-9A-HJ-NP-Za-km-z]{33}';
default:
if (type.tag == CryptoCurrency.eth.title) {
pattern = '0x[0-9a-zA-Z]{42}';
return '0x[0-9a-zA-Z]{42}';
}
if (type.tag == CryptoCurrency.maticpoly.tag) {
pattern = '0x[0-9a-zA-Z]{42}';
return '0x[0-9a-zA-Z]{42}';
}
if (type.tag == CryptoCurrency.sol.title) {
pattern = '[1-9A-HJ-NP-Za-km-z]{43,44}';
return '([^0-9a-zA-Z]|^)[1-9A-HJ-NP-Za-km-z]{43,44}([^0-9a-zA-Z]|\$)';
}
if (type.tag == CryptoCurrency.trx.title) {
pattern = '(T|t)[1-9A-HJ-NP-Za-km-z]{33}';
return '(T|t)[1-9A-HJ-NP-Za-km-z]{33}';
}
}

if (pattern != null) {
return "$BEFORE_REGEX$pattern$AFTER_REGEX";
return null;
}

return null;
}
}
27 changes: 17 additions & 10 deletions lib/entities/pin_code_required_duration.dart
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
import 'package:cake_wallet/generated/i18n.dart';

enum PinCodeRequiredDuration {
always(0),
tenminutes(10),
onehour(60);
enum PinCodeRequiredDuration {
always(0),
tenMinutes(10),
halfHour(30),
fortyFiveMinutes(45),
oneHour(60);

const PinCodeRequiredDuration(this.value);

final int value;

static PinCodeRequiredDuration deserialize({required int raw}) =>
PinCodeRequiredDuration.values.firstWhere((e) => e.value == raw);

@override
String toString(){
String toString() {
String label = '';
switch (this) {
case PinCodeRequiredDuration.always:
label = S.current.always;
break;
case PinCodeRequiredDuration.tenminutes:
case PinCodeRequiredDuration.tenMinutes:
label = S.current.minutes_to_pin_code('10');
break;
case PinCodeRequiredDuration.onehour:
case PinCodeRequiredDuration.oneHour:
label = S.current.minutes_to_pin_code('60');
break;
case PinCodeRequiredDuration.halfHour:
label = S.current.minutes_to_pin_code('30');
break;
case PinCodeRequiredDuration.fortyFiveMinutes:
label = S.current.minutes_to_pin_code('45');
break;
}
return label;

}

}
}
2 changes: 1 addition & 1 deletion lib/exchange/provider/simpleswap_exchange_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class SimpleSwapExchangeProvider extends ExchangeProvider {
case CryptoCurrency.usdcsol:
return 'usdcspl';
case CryptoCurrency.matic:
return 'maticerc20';
return 'pol';
case CryptoCurrency.maticpoly:
return 'matic';
default:
Expand Down
3 changes: 2 additions & 1 deletion lib/polygon/cw_polygon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ class CWPolygon extends Polygon {
@override
CryptoCurrency assetOfTransaction(WalletBase wallet, TransactionInfo transaction) {
transaction as EVMChainTransactionInfo;
if (transaction.tokenSymbol == CryptoCurrency.maticpoly.title) {
if (transaction.tokenSymbol == CryptoCurrency.maticpoly.title ||
transaction.tokenSymbol == "MATIC") {
return CryptoCurrency.maticpoly;
}

Expand Down
24 changes: 18 additions & 6 deletions lib/src/screens/dashboard/pages/cake_features_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,26 @@ class CakeFeaturesPage extends StatelessWidget {
onTap: () => _navigatorToGiftCardsPage(context),
title: 'Cake Pay',
subTitle: S.of(context).cake_pay_subtitle,
svgPicture: SvgPicture.asset(
'assets/images/cards.svg',
height: 125,
width: 125,
image: Image.asset(
'assets/images/cards.png',
height: 100,
width: 115,
fit: BoxFit.cover,
),
),
SizedBox(height: 10),
DashBoardRoundedCardWidget(
onTap: () => _launchUrl("cake.nano-gpt.com"),
title: "NanoGPT",
subTitle: S.of(context).nanogpt_subtitle,
onTap: () => _launchUrl("cake.nano-gpt.com"),
image: Image.asset(
'assets/images/nanogpt.png',
height: 80,
width: 80,
fit: BoxFit.cover,
),
),
SizedBox(height: 20),
SizedBox(height: 10),
Observer(
builder: (context) {
if (!dashboardViewModel.hasSignMessages) {
Expand All @@ -75,6 +81,12 @@ class CakeFeaturesPage extends StatelessWidget {
onTap: () => Navigator.of(context).pushNamed(Routes.signPage),
title: S.current.sign_verify_message,
subTitle: S.current.sign_verify_message_sub,
icon: Icon(
Icons.speaker_notes_rounded,
color:
Theme.of(context).extension<DashboardPageTheme>()!.pageTitleTextColor,
size: 75,
),
);
},
),
Expand Down
Loading

0 comments on commit 6592b7a

Please sign in to comment.