Skip to content

Commit

Permalink
Merge pull request #53 from 3Dpass/dev
Browse files Browse the repository at this point in the history
FEATURE: Notifications
  • Loading branch information
L3odr0id authored Sep 16, 2023
2 parents acfdfab + 2ec0fe7 commit 785f4f4
Show file tree
Hide file tree
Showing 61 changed files with 1,647 additions and 883 deletions.
51 changes: 0 additions & 51 deletions .github/workflows/ci.yaml

This file was deleted.

22 changes: 0 additions & 22 deletions .github/workflows/dart_code_metrics.yaml

This file was deleted.

16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# threedpass
# Threedpass

3Dpass mobile light wallet for Android and iOS. [Read more](https://3dpass.org/mobile-wallet) about its features.

Expand Down Expand Up @@ -32,16 +32,22 @@ Follow this short instruction:
2. Add locale info in ```lib/main.dart```
```
EasyLocalization(
supportedLocales: const [Locale('en')], // Add new locale here
...
supportedLocales: const [
Locale('en'),
Locale('es'),
Locale('sr'),
// Add new locale here
],
)
```
3. Add LANG_CODE in ```ios/Runner/Info.plist``` as described here:
```
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>nb</string>
<string>en</string>
<string>es</string>
<string>sr</string>
// Add new locale here
</array>
```

Expand Down
12 changes: 11 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,15 @@
"@2.7.2":{
},
"choose_transfer_keep_alive": "Keep sender alive",
"transfer_keep_alive_help": "With the keep-alive option set, the account is protected against removal due to low balances."
"transfer_keep_alive_help": "With the keep-alive option set, the account is protected against removal due to low balances.",

"@2.8.0":{
},
"notifications_titile": "Transactions",
"transfer_status": "Transfer status:",
"status_pending": "Pending",
"status_success": "Success",
"status_failed": "Failed",
"status_error": "Error",
"error_wrong_amount_int": "A positive integer expected"
}
3 changes: 3 additions & 0 deletions lib/core/polkawallet/app_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class AppService {

plugin.sdk.api.account.unsubscribeBalance();

// plugin.sdk.webView.
// serviceRoot.webView!.addMsgHandler(msgId, onStatusChange);

if (address != null) {
unawaited(
plugin.sdk.api.account.subscribeBalance(
Expand Down
13 changes: 12 additions & 1 deletion lib/core/polkawallet/bloc/app_service_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:threedpass/core/polkawallet/constants.dart';
import 'package:threedpass/core/polkawallet/plugins/d3p_core_plugin.dart';
import 'package:threedpass/core/polkawallet/plugins/d3p_live_net_plugin.dart';
import 'package:threedpass/core/polkawallet/plugins/d3p_test_net_plugin.dart';
import 'package:threedpass/core/polkawallet/utils/tx_update_event_logs_handler.dart';
import 'package:threedpass/features/accounts/domain/account_info.dart';
import 'package:threedpass/features/settings_page/bloc/settings_page_cubit.dart';
import 'package:threedpass/features/settings_page/domain/entities/global_settings.dart';
Expand Down Expand Up @@ -147,7 +148,8 @@ class AppServiceLoaderCubit extends Cubit<AppService> {

state.keyring.setCurrent(keyPairData);

final pseudoNewState = state.copyWith();
final pseudoNewState =
state.copyWith(status: AppServiceInitStatus.connected);

await pseudoNewState.subscribeToBalance();

Expand Down Expand Up @@ -194,4 +196,13 @@ class AppServiceLoaderCubit extends Cubit<AppService> {
),
);
}

void addHandler(
final String msgId,
final void Function(String) setTransactionResult,
) {
state.plugin.sdk.webView!.addGlobalHandler(
TxUpdateEventLogsHandler(msgId, setTransactionResult),
);
}
}
6 changes: 2 additions & 4 deletions lib/core/polkawallet/utils/balance_utils.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import 'dart:math';

import 'package:intl/intl.dart';
import 'package:logger/logger.dart';
import 'package:polkawallet_sdk/api/types/balanceData.dart';
import 'package:threedpass/setup.dart';

class BalanceUtils {
static BigInt balanceTotal(final BalanceData? balance) {
Expand Down Expand Up @@ -100,8 +98,8 @@ class BalanceUtils {
}

/// Just to use it as double
static double balanceToDouble(final String balance) {
return double.parse(balance.replaceAll(',', ''));
static double balanceToDouble(final String raw, final int decimals) {
return bigIntToDouble(balanceInt(raw), decimals);
}
}

Expand Down
49 changes: 49 additions & 0 deletions lib/core/polkawallet/utils/tx_update_event_logs_handler.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'dart:convert';

import 'package:polkawallet_sdk/utils/web_logs_handler.dart';

class TxUpdateEventLogsHandler extends WebLogsHandler {
const TxUpdateEventLogsHandler(
this.msgId,
this.setTransactionResult,
);

final String msgId;

/// @param {String} is extrinsicSuccess or message
final void Function(String) setTransactionResult;

static const String extrinsicSuccess = 'ok';

@override
void handle(final String data) {
final dynamic rawData = jsonDecode(data);

if (!(rawData is Map &&
rawData.keys.contains('path') &&
rawData.keys.contains('data'))) {
return;
}

final dynamic path = rawData['path'];

if (!(path is String && path.contains('txUpdateEvent|msgId=$msgId'))) {
return;
}

final dynamic dataSection = rawData['data'];

if (!(dataSection is Map &&
dataSection.keys.contains('title') &&
dataSection.keys.contains('message'))) {
return;
}

final String title = dataSection['title'] as String;
if (title == "system.ExtrinsicSuccess") {
setTransactionResult(extrinsicSuccess);
} else if (title == 'system.ExtrinsicFailed') {
setTransactionResult(dataSection['message'] as String);
}
}
}
6 changes: 6 additions & 0 deletions lib/core/theme/d3p_special_colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,9 @@ extension PinCodeColors on CustomColors {
? D3pColors.lightScaffoldBackground
: D3pColors.alternativeDarkBackground;
}

extension NotificationCard on CustomColors {
Color get errorCardBGColor => brightness == Brightness.light
? Colors.red.shade100
: Colors.red.shade900;
}
3 changes: 1 addition & 2 deletions lib/core/widgets/buttons/custom_back_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ class CustomBackButton extends StatelessWidget {

@override
Widget build(final BuildContext context) {
final needSpecialPop =
!context.router.canNavigateBack; // TODO CHECK BACKBUTTON
final needSpecialPop = !context.router.canNavigateBack;
final theme = Theme.of(context);

return PlatformIconButton(
Expand Down
36 changes: 8 additions & 28 deletions lib/core/widgets/buttons/enum_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ class EnumButton extends StatelessWidget {
shape: MaterialStateProperty.all<OutlinedBorder>(border),
),
),
cupertino: (final context, final platform) => CupertinoTextButtonData(
// color: mainColor,
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
),
cupertino: (final context, final platform) =>
_CupertinoTextButtonData(),
),
),
);
Expand All @@ -84,27 +82,9 @@ class _Icon extends StatelessWidget {
}
}

// class _ListTileMaterial {
// final ThemeData themeData;
// final Color? backgroundColor;
// final RoundedRectangleBorder border;

// _ListTileMaterial({
// required this.themeData,
// required this.backgroundColor,
// required this.border,
// });

// MaterialTextButtonData style() {
// return MaterialTextButtonData(
// style: themeData.textButtonTheme.style!.copyWith(
// // padding: MaterialStateProperty.all(EdgeInsets.zero),
// backgroundColor: MaterialStateProperty.all<Color>(
// backgroundColor ?? themeData.cardColor,
// ),
// tapTargetSize: MaterialTapTargetSize.shrinkWrap,
// shape: MaterialStateProperty.all<OutlinedBorder>(border),
// ),
// );
// }
// }
class _CupertinoTextButtonData extends CupertinoTextButtonData {
_CupertinoTextButtonData()
: super(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
);
}
13 changes: 11 additions & 2 deletions lib/core/widgets/buttons/icon_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class D3pIconButton extends StatelessWidget {
this.onPressed,
this.iconColor,
this.size,
this.splashRadius,
this.emptyContraints = false,
super.key,
});

Expand All @@ -15,12 +17,16 @@ class D3pIconButton extends StatelessWidget {
}) : iconData = Icons.abc,
size = null,
iconColor = Colors.transparent,
emptyContraints = false,
splashRadius = null,
onPressed = null;

final IconData iconData;
final Color? iconColor;
final void Function()? onPressed;
final double? size;
final bool emptyContraints;
final double? splashRadius;

@override
Widget build(final BuildContext context) {
Expand All @@ -31,8 +37,11 @@ class D3pIconButton extends StatelessWidget {
color: iconColor,
),
onPressed: onPressed,
material: (final _, final __) =>
MaterialIconButtonData(padding: EdgeInsets.zero),
material: (final _, final __) => MaterialIconButtonData(
padding: EdgeInsets.zero,
constraints: emptyContraints ? const BoxConstraints() : null,
splashRadius: splashRadius,
),
);
}
}
Loading

0 comments on commit 785f4f4

Please sign in to comment.