Skip to content
Merged
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
3 changes: 3 additions & 0 deletions mobile-app/assets/v2/axe.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 4 additions & 13 deletions mobile-app/lib/features/components/get_started.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
import 'package:quantus_sdk/quantus_sdk.dart';
import 'package:resonance_network_wallet/features/styles/app_colors_theme.dart';
import 'package:resonance_network_wallet/features/styles/app_text_theme.dart';
import 'package:resonance_network_wallet/shared/utils/open_external_url.dart';
import 'package:resonance_network_wallet/utils/url_utils.dart';
import 'package:url_launcher/url_launcher.dart';

class GetStarted extends StatelessWidget {
const GetStarted({super.key});
Expand Down Expand Up @@ -33,26 +33,17 @@ class GetStarted extends StatelessWidget {
),
const SizedBox(height: 25),
GestureDetector(
onTap: () {
final Uri url = Uri.parse(AppConstants.tutorialsAndGuidesUrl);
launchUrl(url);
},
onTap: () => openUrl(AppConstants.tutorialsAndGuidesUrl),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these style and API changes should be in a separate PR, they have nothing to do with the feature

child: Text('Tutorials & Guides →', style: context.themeText.smallParagraph),
),
const SizedBox(height: 25),
GestureDetector(
onTap: () {
final Uri url = Uri.parse(AppConstants.communityUrl);
launchUrl(url);
},
onTap: () => openUrl(AppConstants.communityUrl),
child: Text('Community →', style: context.themeText.smallParagraph),
),
const SizedBox(height: 25),
GestureDetector(
onTap: () {
final Uri url = Uri.parse(AppConstants.techSupportUrl);
launchUrl(url);
},
onTap: () => openUrl(AppConstants.techSupportUrl),
child: Text('Tech Support →', style: context.themeText.smallParagraph),
),
],
Expand Down
4 changes: 2 additions & 2 deletions mobile-app/lib/features/components/link_text.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:resonance_network_wallet/features/styles/app_text_theme.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:resonance_network_wallet/shared/utils/open_external_url.dart';

class LinkText extends StatelessWidget {
final String label;
Expand All @@ -19,7 +19,7 @@ class LinkText extends StatelessWidget {
child: Text(label, style: effectiveTextStyle),
onTap: () {
final Uri uri = Uri.parse(url);
launchUrl(uri);
openUrl(uri.toString());
},
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import 'package:resonance_network_wallet/providers/wallet_providers.dart';
import 'package:resonance_network_wallet/services/reversible_transfer_monitoring_service.dart';
import 'package:resonance_network_wallet/shared/extensions/media_query_data_extension.dart';
import 'package:resonance_network_wallet/shared/extensions/toaster_extensions.dart';
import 'package:resonance_network_wallet/shared/utils/open_external_url.dart';
import 'package:resonance_network_wallet/shared/utils/tx_filter_family_provider.dart';
import 'package:url_launcher/url_launcher.dart';

enum ReversibleTransactionMode { reversible, guardianIntercept }

Expand Down Expand Up @@ -310,7 +310,7 @@ class _ReversibleTransactionActionSheetState extends ConsumerState<ReversibleTra
final Uri url = Uri.parse(
'${AppConstants.explorerEndpoint}/reversible-transactions/${widget.transaction.extrinsicHash}',
);
await launchUrl(url);
openUrl(url.toString());
},
child: SizedBox(
width: 136,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import 'package:resonance_network_wallet/shared/extensions/clipboard_extensions.
import 'package:resonance_network_wallet/shared/extensions/media_query_data_extension.dart';
import 'package:resonance_network_wallet/shared/extensions/toaster_extensions.dart';
import 'package:resonance_network_wallet/shared/extensions/transaction_event_extension.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:resonance_network_wallet/shared/utils/open_external_url.dart';

class TransactionDetailsActionSheet extends ConsumerStatefulWidget {
final TransactionEvent transaction;
Expand Down Expand Up @@ -311,13 +311,13 @@ class _TransactionDetailsActionSheetState extends ConsumerState<TransactionDetai
'${AppConstants.explorerEndpoint}/$transactionType/${widget.transaction.extrinsicHash}',
);
print('url: $url');
await launchUrl(url);
openUrl(url.toString());
} else if (isMinerReward) {
final Uri url = Uri.parse(
'${AppConstants.explorerEndpoint}/$transactionType/${widget.transaction.blockHash}',
);
print('miner url: $url');
await launchUrl(url);
openUrl(url.toString());
}
},
child: Row(
Expand Down
22 changes: 20 additions & 2 deletions mobile-app/lib/providers/mining_rewards_provider.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:quantus_sdk/quantus_sdk.dart';
import 'package:resonance_network_wallet/providers/account_providers.dart';
import 'package:resonance_network_wallet/providers/wallet_providers.dart';
import 'package:resonance_network_wallet/services/mining_rewards_service.dart';

final miningRewardsServiceProvider = Provider<MiningRewardsService>((ref) => MiningRewardsService());

final miningRewardsProvider = FutureProvider<MiningRewardsData>((ref) async {
final service = ref.watch(miningRewardsServiceProvider);
final accounts = ref.watch(accountsProvider).value;

if (accounts == null || accounts.isEmpty) {
return const MiningRewardsData(resonanceBlocks: 0, schrodingerBlocks: 0, diracBlocks: 0, planckBlocks: 0);
return MiningRewardsData(
resonanceBlocks: 0,
schrodingerBlocks: 0,
diracBlocks: 0,
planckBlocks: 0,
planckRewards: BigInt.zero,
redeemedRewards: BigInt.zero,
redeemableRewards: BigInt.zero,
);
}

final mnemonic = await ref.watch(settingsServiceProvider).getMnemonic(0);
if (mnemonic == null) {
throw Exception('Mnemonic not found!');
}
final keyPair = ref.watch(hdWalletServiceProvider).deriveWormholeKeyPair(mnemonic: mnemonic);

final oldMiningAccountId = await TaskmasterService().getOldMiningAccountId();
final accountsList = accounts.map((a) => a.accountId).toList();
accountsList.add(oldMiningAccountId);
return service.getMiningRewards(accountsList);

return service.getMiningRewards(ref, keyPair, accountsList);
});
8 changes: 8 additions & 0 deletions mobile-app/lib/providers/wallet_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ final highSecurityServiceProvider = Provider<HighSecurityService>((ref) {
return HighSecurityService();
});

final hdWalletServiceProvider = Provider<HdWalletService>((ref) {
return HdWalletService();
});

final wormholeUtxoServiceProvider = Provider<WormholeUtxoService>((ref) {
return WormholeUtxoService();
});

final isHighSecurityProvider = FutureProvider.family<bool, Account>((ref, account) async {
final highSecurityService = ref.watch(highSecurityServiceProvider);
return await highSecurityService.isHighSecurity(account);
Expand Down
28 changes: 19 additions & 9 deletions mobile-app/lib/services/mining_rewards_service.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import 'dart:convert';

import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:quantus_sdk/quantus_sdk.dart';
import 'package:resonance_network_wallet/providers/wallet_providers.dart';
import 'package:resonance_network_wallet/utils/env_utils.dart';

class MiningRewardsData {
final int resonanceBlocks;
final int schrodingerBlocks;
final int diracBlocks;
final int planckBlocks;
final BigInt planckRewards;
final BigInt redeemedRewards;
final BigInt redeemableRewards;

const MiningRewardsData({
required this.resonanceBlocks,
required this.schrodingerBlocks,
required this.diracBlocks,
required this.planckBlocks,
required this.planckRewards,
required this.redeemedRewards,
required this.redeemableRewards,
});

int get totalBlocks => resonanceBlocks + schrodingerBlocks + diracBlocks + planckBlocks;
Expand All @@ -33,8 +41,9 @@ class MiningRewardsService {
_cachedAccountIds = null;
}

Future<MiningRewardsData> getMiningRewards(List<String> currentAccountIds) async {
Future<MiningRewardsData> getMiningRewards(Ref ref, WormholeKeyPair keyPair, List<String> currentAccountIds) async {
print('[MiningRewards] Current account IDs: $currentAccountIds');
final wormholeUtxoService = ref.read(wormholeUtxoServiceProvider);

final miners = <String, List<_MinerEntry>>{};
for (final entry in _assets.entries) {
Expand All @@ -49,22 +58,23 @@ class MiningRewardsService {
final resonance = _countBlocks('resonance', miners['resonance']!, allAccountIds);
final schrodinger = _countBlocks('schrodinger', miners['schrodinger']!, allAccountIds);
final dirac = _countBlocks('dirac', miners['dirac']!, allAccountIds);
final planck = await _fetchPlanckBlocks(allAccountIds);
final (planckStats, redeemableRewards) = await (
TaskmasterService().getMinerStats(),
wormholeUtxoService.getUnspentBalance(wormholeAddress: keyPair.address, secretHex: keyPair.secretHex),
).wait;
final redeemedRewards = planckStats.totalRewards - redeemableRewards;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redeemed rewards can be negative from data inconsistency

Medium Severity

The calculation planckStats.totalRewards - redeemableRewards can produce a negative BigInt if the wormhole unspent balance exceeds the total rewards reported by the miner stats endpoint. This can occur due to timing differences between the two independent API calls, or if the wormhole address received funds from non-mining sources. The negative value would be formatted and displayed in the UI under "REDEEMED", showing something like "-0.5 QUAN" which is nonsensical.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a4ac898. Configure here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is nonsense


print('[MiningRewards] Resonance: $resonance, Schrödinger: $schrodinger, Dirac: $dirac, Planck: $planck');
return MiningRewardsData(
resonanceBlocks: resonance,
schrodingerBlocks: schrodinger,
diracBlocks: dirac,
planckBlocks: planck,
planckBlocks: planckStats.totalMinedBlocks,
planckRewards: planckStats.totalRewards,
redeemedRewards: redeemedRewards,
redeemableRewards: redeemableRewards,
);
}

Future<int> _fetchPlanckBlocks(Set<String> accountIds) async {
final minerStats = await TaskmasterService().getMinerStats();
return minerStats.totalMinedBlocks;
}

List<_MinerEntry> _parseMiners(String jsonStr) {
final decoded = jsonDecode(jsonStr);
final stats = decoded['data']['minerStats'] as List;
Expand Down
13 changes: 13 additions & 0 deletions mobile-app/lib/shared/utils/open_external_url.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:url_launcher/url_launcher.dart';

Future<void> openUrl(String urlString, {LaunchMode mode = LaunchMode.platformDefault}) async {
final uri = Uri.parse(urlString);
try {
final launched = await launchUrl(uri, mode: mode);
if (!launched) {
print('launchUrl returned false: $urlString');
}
} catch (e, st) {
print('launchUrl failed: $urlString error=$e\n$st');
}
}
3 changes: 1 addition & 2 deletions mobile-app/lib/v2/screens/accounts/account_ready_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class AccountReadyScreen extends StatelessWidget {
final String checksumPhrase;
final String accountId;

static const _galleryLargeTitle = Color(0xFFEBEBEB);
static const _successRingSize = 78.0;
static const _checkIconSize = 32.0;
static const _borderWidth = 2.0;
Expand Down Expand Up @@ -92,7 +91,7 @@ class AccountReadyScreen extends StatelessWidget {
Text(
headline,
textAlign: TextAlign.center,
style: text.paragraph?.copyWith(fontSize: 32, color: _galleryLargeTitle, height: 1.0),
style: text.paragraph?.copyWith(fontSize: 32, color: colors.textLightGray, height: 1.0),
),
],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import 'package:resonance_network_wallet/features/components/dotted_border.dart'
import 'package:resonance_network_wallet/providers/currency_display_provider.dart';
import 'package:resonance_network_wallet/providers/wallet_providers.dart';
import 'package:resonance_network_wallet/shared/extensions/transaction_event_extension.dart';
import 'package:resonance_network_wallet/shared/utils/open_external_url.dart';
import 'package:resonance_network_wallet/v2/components/amount_display_with_conversion.dart';
import 'package:resonance_network_wallet/v2/components/bottom_sheet_container.dart';
import 'package:resonance_network_wallet/v2/theme/app_colors.dart';
import 'package:resonance_network_wallet/v2/theme/app_text_styles.dart';
import 'package:url_launcher/url_launcher.dart';

void showTransactionDetailSheet(BuildContext context, TransactionEvent tx, String activeAccountId) {
BottomSheetContainer.show(
Expand Down Expand Up @@ -213,6 +213,6 @@ class _ExplorerLink extends StatelessWidget {
path = '$transactionType/${tx.blockHash}';
}

if (path != null) launchUrl(Uri.parse('${AppConstants.explorerEndpoint}/$path'));
if (path != null) openUrl('${AppConstants.explorerEndpoint}/$path');
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we changing semantics here, and why?

All these changes should be in separate PRs - there's some style changes, class changes, and the main implementation of miner reweards all mixed together.

}
Loading
Loading