Skip to content

Commit

Permalink
refactor: update tx list and details style
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Oct 4, 2024
1 parent ae7bafb commit cc5a7d2
Show file tree
Hide file tree
Showing 20 changed files with 609 additions and 405 deletions.
3 changes: 3 additions & 0 deletions assets/svg/dots-bg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ const List<String> CUSTOM_ICON_NAMES = [
'stake-dark',
'stake-icon-dark',
'stake-icon',
'dots-bg',
'stake',
'transaction-error',
'transaction-success',
Expand Down
5 changes: 3 additions & 2 deletions lib/theme/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'
show Color, MaterialColor, WidgetState, WidgetStateColor;

class WitnetPallet {
static const black = Color(0xFF1D1D1B);
static const black = Color(0xFF232323);
static const white = Color(0xFFFFFFFF);
static const opacityWhite = Color(0xAFFFFFFF);
static const opacityWhite2 = Color(0xA0FFFFFF);
Expand All @@ -11,8 +11,9 @@ class WitnetPallet {

static const lighterGrey = Color(0xFFEDECEC);
static const lightGrey = Color(0xFFBDBDBD);
static const mediumGrey = Color(0xFF656565);
static const mediumGrey = Color(0xFF707070);
static const darkGrey = Color(0xFF424242);
static const darkGrey2 = Color(0xFF343434);
static const darkerGrey = Color(0xFF292929);

static const transparent = Color(0x00FFFFFF);
Expand Down
14 changes: 6 additions & 8 deletions lib/theme/dark_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,27 @@ TextTheme textTheme = TextTheme(
fontWeight: FontWeight.normal),
);
InputDecorationTheme inputDecorationTheme = InputDecorationTheme(
fillColor: WitnetPallet.black,
fillColor: WitnetPallet.darkGrey2,
filled: true,
errorStyle: TextStyle(color: WitnetPallet.brightRed),
helperStyle: TextStyle(color: WitnetPallet.white),
helperMaxLines: 1,
errorMaxLines: 1,
hintStyle: TextStyle(color: WitnetPallet.lighterGrey),
labelStyle: TextStyle(color: WitnetPallet.opacityWhite),
hintStyle: TextStyle(color: WitnetPallet.mediumGrey),
labelStyle: TextStyle(color: WitnetPallet.mediumGrey),
hoverColor: const Color.fromARGB(9, 255, 255, 255),
focusColor: WitnetPallet.brightCyanOpacity1,
isDense: true,
isCollapsed: false,
contentPadding: EdgeInsets.all(16),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: WitnetPallet.white, width: 1.0, style: BorderStyle.solid),
color: WitnetPallet.darkGrey2, width: 1.0, style: BorderStyle.solid),
borderRadius: BorderRadius.circular(24),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: WitnetPallet.brightCyanOpacity1,
width: 2.0,
style: BorderStyle.solid),
color: WitnetPallet.brightCyan, width: 2.0, style: BorderStyle.solid),
borderRadius: BorderRadius.circular(24),
),
errorBorder: OutlineInputBorder(
Expand Down Expand Up @@ -176,7 +174,7 @@ ElevatedButtonThemeData elevatedButtonTheme = ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.all(16),
foregroundColor: WitnetPallet.black,
backgroundColor: WitnetPallet.white,
backgroundColor: WitnetPallet.brightCyan,
disabledForegroundColor:
Color.fromARGB(102, 164, 212, 204).withOpacity(0.38),
disabledBackgroundColor:
Expand Down
12 changes: 6 additions & 6 deletions lib/theme/extended_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class ExtendedTheme extends ThemeExtension<ExtendedTheme> {
dropdownBackgroundColor: WitnetPallet.white,
dropdownTextColor: WitnetPallet.darkGrey,
navigationActiveButton: WitnetPallet.lightGrey,
navigationPointerActiveButton: WitnetPallet.deepAqua,
navigationPointerActiveButton: WitnetPallet.black,
headerActiveTextColor: WitnetPallet.black,
headerTextColor: WitnetPallet.black,
headerBackgroundColor: WitnetPallet.brightCyan,
Expand All @@ -345,8 +345,8 @@ class ExtendedTheme extends ThemeExtension<ExtendedTheme> {
txBorderColor: WitnetPallet.lightGrey,
txValueNegativeColor: WitnetPallet.darkRed,
txValuePositiveColor: WitnetPallet.darkGreen,
stepBarActiveColor: WitnetPallet.deepAqua,
stepBarActionableColor: WitnetPallet.darkGrey,
stepBarActiveColor: WitnetPallet.black,
stepBarActionableColor: WitnetPallet.mediumGrey,
stepBarColor: WitnetPallet.lightGrey,
switchActiveBg: WitnetPallet.black,
switchActiveFg: WitnetPallet.white,
Expand Down Expand Up @@ -408,7 +408,7 @@ class ExtendedTheme extends ThemeExtension<ExtendedTheme> {
selectedTextColor: WitnetPallet.black,
dropdownBackgroundColor: WitnetPallet.darkerGrey,
dropdownTextColor: WitnetPallet.lighterGrey,
navigationPointerActiveButton: WitnetPallet.deepAqua,
navigationPointerActiveButton: WitnetPallet.lightGrey,
navigationActiveButton: WitnetPallet.lightGrey,
headerActiveTextColor: WitnetPallet.black,
headerTextColor: WitnetPallet.black,
Expand All @@ -418,8 +418,8 @@ class ExtendedTheme extends ThemeExtension<ExtendedTheme> {
walletActiveItemBackgroundColor: WitnetPallet.brightCyanOpacity3,
walletActiveItemBorderColor: WitnetPallet.brightCyan,
walletItemBorderColor: WitnetPallet.opacityWhite2,
inputIconColor: WitnetPallet.opacityWhite2,
txBorderColor: WitnetPallet.opacityWhite2,
inputIconColor: WitnetPallet.white,
txBorderColor: WitnetPallet.darkGrey2,
txValueNegativeColor: WitnetPallet.brightRed,
txValuePositiveColor: WitnetPallet.brightGreen,
stepBarActiveColor: WitnetPallet.brightCyan,
Expand Down
18 changes: 9 additions & 9 deletions lib/theme/light_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ TextTheme textTheme = TextTheme(
fontFamily: 'Almarai',
letterSpacing: 0,
height: 1.15,
color: WitnetPallet.deepAqua,
color: WitnetPallet.black,
fontSize: 16,
fontWeight: FontWeight.normal),
titleLarge: TextStyle(
Expand Down Expand Up @@ -100,7 +100,7 @@ TextTheme textTheme = TextTheme(
fontFamily: 'Almarai',
letterSpacing: 0,
height: 1.15,
color: WitnetPallet.deepAqua,
color: WitnetPallet.black,
fontSize: 16,
fontWeight: FontWeight.normal),
);
Expand All @@ -116,7 +116,7 @@ InputDecorationTheme inputDecorationTheme = InputDecorationTheme(
helperStyle: TextStyle(color: WitnetPallet.darkerGrey),
helperMaxLines: 1,
errorMaxLines: 1,
hintStyle: TextStyle(),
hintStyle: TextStyle(color: WitnetPallet.mediumGrey),
hoverColor: WitnetPallet.white,
focusColor: WitnetPallet.brightCyan,
isDense: true,
Expand Down Expand Up @@ -198,25 +198,25 @@ OutlinedButtonThemeData outlinedButtonTheme = OutlinedButtonThemeData(
),
));
IconThemeData iconTheme = IconThemeData(
color: WitnetPallet.deepAqua,
color: WitnetPallet.black,
size: 16,
);
IconThemeData primaryIconTheme = IconThemeData(
color: WitnetPallet.deepAqua,
color: WitnetPallet.black,
size: 24,
);
CheckboxThemeData checkboxTheme = CheckboxThemeData(
splashRadius: 0,
side: WidgetStateBorderSide.resolveWith(
(_) => const BorderSide(width: 2, color: WitnetPallet.deepAqua)),
(_) => const BorderSide(width: 2, color: WitnetPallet.black)),
fillColor: WidgetStateProperty.resolveWith((Set<WidgetState> states) {
if (states.contains(WidgetState.selected)) {
return WitnetPallet.deepAqua;
return WitnetPallet.brightCyan;
}
return WitnetPallet.transparent;
}),
checkColor: WidgetStateProperty.all(WitnetPallet.white),
overlayColor: WidgetStateProperty.all(WitnetPallet.white),
checkColor: WidgetStateProperty.all(WitnetPallet.black),
overlayColor: WidgetStateProperty.all(WitnetPallet.black),
);

Color getColorPrimary(Set<WidgetState> states) {
Expand Down
226 changes: 226 additions & 0 deletions lib/util/transaction_details.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
import 'package:flutter/material.dart';
import 'package:my_wit_wallet/constants.dart';
import 'package:my_wit_wallet/shared/api_database.dart';
import 'package:my_wit_wallet/shared/locator.dart';
import 'package:my_wit_wallet/theme/colors.dart';
import 'package:my_wit_wallet/theme/extended_theme.dart';
import 'package:my_wit_wallet/util/get_localization.dart';
import 'package:my_wit_wallet/util/storage/database/account.dart';
import 'package:my_wit_wallet/util/storage/database/adapters/transaction_adapter.dart';
import 'package:my_wit_wallet/util/storage/database/wallet.dart';
import 'package:my_wit_wallet/util/extensions/num_extensions.dart';
import 'package:my_wit_wallet/util/transactions_list/get_transaction_address.dart';
import 'package:my_wit_wallet/util/extensions/string_extensions.dart';
import 'package:my_wit_wallet/util/transactions_list/get_transaction_label.dart';
import 'package:witnet/explorer.dart';
import 'package:witnet/schema.dart';

class TransactionValue {
final String label;
final String prefix;
final String amount;
TransactionValue(
{required this.label, required this.prefix, required this.amount});
}

class TransactionUtils {
Wallet currentWallet =
Locator.instance.get<ApiDatabase>().walletStorage.currentWallet;

final GeneralTransaction vti;
TransactionUtils({required this.vti});

List<String> get externalAddresses {
return currentWallet.externalAccounts.values
.map((account) => account.address)
.toList();
}

List<String> get internalAddresses {
return currentWallet.internalAccounts.values
.map((account) => account.address)
.toList();
}

Account? get singleAddressAccount {
return currentWallet.walletType == WalletType.single
? currentWallet.masterAccount
: null;
}

int lockedValue() {
int amountLocked = 0;
if (vti.type == TransactionType.value_transfer) {
vti.vtt!.outputs.forEach((element) {
if (element.timeLock > DateTime.now().millisecondsSinceEpoch ~/ 1000) {
amountLocked += element.value.toInt();
}
});
}
return amountLocked;
}

int receiveValue() {
int nanoWitvalue = 0;
if (vti.type == TransactionType.value_transfer) {
vti.vtt!.outputs.forEach((element) {
if ((externalAddresses.contains(element.pkh.address) ||
internalAddresses.contains(element.pkh.address))) {
nanoWitvalue += element.value.toInt();
} else if (singleAddressAccount != null &&
singleAddressAccount!.address == element.pkh.address) {
nanoWitvalue += element.value.toInt();
}
});
return nanoWitvalue;
} else if (vti.mint != null) {
vti.mint!.outputs.forEach((element) {
if ((externalAddresses.contains(element.pkh.address) ||
internalAddresses.contains(element.pkh.address))) {
nanoWitvalue += element.value.toInt();
} else if (singleAddressAccount != null &&
singleAddressAccount!.address == element.pkh.address) {
nanoWitvalue += element.value.toInt();
}
});
return nanoWitvalue;
} else if (vti.stake != null) {
// TODO(#542): get value and correct type for for stake transactions
vti.stake!.outputs.forEach((element) {
if ((externalAddresses.contains(element.pkh.address) ||
internalAddresses.contains(element.pkh.address))) {
nanoWitvalue += element.value.toInt();
} else if (singleAddressAccount != null &&
singleAddressAccount!.address == element.pkh.address) {
nanoWitvalue += element.value.toInt();
}
});
return nanoWitvalue;
} else {
// TODO(#542): get value and correct type for unstake transactions
vti.unstake!.outputs.forEach((element) {
if ((externalAddresses.contains(element.pkh.address) ||
internalAddresses.contains(element.pkh.address))) {
nanoWitvalue += element.value.toInt();
} else if (singleAddressAccount != null &&
singleAddressAccount!.address == element.pkh.address) {
nanoWitvalue += element.value.toInt();
}
});
return nanoWitvalue;
}
}

int sendValue() {
if (vti.type != TransactionType.value_transfer ||
vti.vtt!.outputs.length <= 0) {
return 0;
}
bool isInternalTx =
externalAddresses.contains(vti.vtt!.outputs[0].pkh.address) ||
internalAddresses.contains(vti.vtt!.outputs[0].pkh.address) ||
singleAddressAccount?.address == vti.vtt!.outputs[0].pkh.address;
return isInternalTx ? vti.fee : vti.vtt!.outputs[0].value.toInt();
}

String getLabel() {
if (vti.type == TransactionType.value_transfer) {
return getTransactionLabel(externalAddresses, internalAddresses,
vti.vtt!.inputs, singleAddressAccount);
} else {
// TODO(#542): set stake and unstake transaction label when feature is supported
return localization.from;
}
}

String getAddress() {
if (vti.type == TransactionType.value_transfer) {
return getTransactionAddress(
getLabel(), vti.vtt!.inputs, vti.vtt!.outputs);
} else {
// TODO(#542): set stake and unstake transaction label when feature is supported
return 'Mint';
}
}

String getTransactionAddress(
String label, List<InputUtxo> inputs, List<ValueTransferOutput> outputs) {
String address = '';
if (inputs.length < 1)
return 'genesis';
else if (label == localization.from && inputs.length > 0) {
address = getSenderAddress().cropMiddle(18);
} else if (outputs.length > 0) {
address = getRecipientAddress().cropMiddle(18);
}
return address;
}

String getSenderAddress() {
return vti.vtt!.inputs[0].address;
}

String getRecipientAddress() {
return vti.vtt!.outputs[0].pkh.address;
}

TransactionValue getTransactionValue() {
String _label = getLabel();
if (_label == localization.from) {
return TransactionValue(
label: _label,
prefix: '+',
amount:
'${receiveValue().standardizeWitUnits().formatWithCommaSeparator()} ${WIT_UNIT[WitUnit.Wit]}',
);
} else if (sendValue().standardizeWitUnits().toString() != '0') {
return TransactionValue(
label: _label,
prefix: '-',
amount:
'${sendValue().standardizeWitUnits().formatWithCommaSeparator()} ${WIT_UNIT[WitUnit.Wit]}',
);
} else {
return TransactionValue(
label: _label,
prefix: '',
amount:
'${sendValue().standardizeWitUnits().formatWithCommaSeparator()} ${WIT_UNIT[WitUnit.Wit]}',
);
}
}

Widget buildTransactionValue(label, context) {
final theme = Theme.of(context);
final extendedTheme = theme.extension<ExtendedTheme>()!;
int _lockedWit = lockedValue();
if (label == localization.from) {
return Text(
' + ${receiveValue().standardizeWitUnits().formatWithCommaSeparator()} ${WIT_UNIT[WitUnit.Wit]}',
style: theme.textTheme.bodyLarge?.copyWith(
color: _lockedWit > 0
? WitnetPallet.mediumGrey
: extendedTheme.txValuePositiveColor),
overflow: TextOverflow.ellipsis,
);
} else if (sendValue().standardizeWitUnits().toString() != '0') {
return Text(
' - ${sendValue().standardizeWitUnits().formatWithCommaSeparator()} ${WIT_UNIT[WitUnit.Wit]}',
style: theme.textTheme.bodyLarge?.copyWith(
color: _lockedWit > 0
? WitnetPallet.mediumGrey
: extendedTheme.txValueNegativeColor),
overflow: TextOverflow.ellipsis,
);
} else {
return Text(
'${sendValue().standardizeWitUnits().formatWithCommaSeparator()} ${WIT_UNIT[WitUnit.Wit]}',
style: theme.textTheme.bodyLarge!.copyWith(
color: _lockedWit > 0
? WitnetPallet.mediumGrey
: theme.textTheme.bodyLarge!.color),
overflow: TextOverflow.ellipsis,
);
}
}
}
Loading

0 comments on commit cc5a7d2

Please sign in to comment.