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

Feature/tokens v2 #271

Merged
merged 6 commits into from
Apr 29, 2024
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ app.*.map.json
## ios build/distribution directory
ios/archive
ios/build
/node_modules
/scripts/node_modules
28 changes: 17 additions & 11 deletions lib/core/firebase/firebase_database_service.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:hypha_wallet/core/firebase/firebase_token_data.dart';
import 'package:hypha_wallet/core/logging/log_helper.dart';
import 'package:hypha_wallet/core/network/models/network.dart';

class FirebaseDatabaseService {
const FirebaseDatabaseService._();
Expand Down Expand Up @@ -97,19 +98,24 @@ class FirebaseDatabaseService {
}

/// Get all tokens
Future<List<FirebaseTokenData>> getAllTokens() async {
final db = FirebaseFirestore.instance;
Future<List<FirebaseTokenData>> getAllTokens(Network network) async {
print("getting tokens 'tokens/$network'");
// Access the collection
final CollectionReference tokens = FirebaseFirestore.instance.collection('tokens');

// Query the subcollection for the specified network
final QuerySnapshot querySnapshot = await tokens.doc(network.name).collection('tokens').get();

final tokens = await db.collection('tokens').get();
final mappedTokens = tokens.docs
//final tokens = await db.collection('tokens/${network.name}').get();
final mappedTokens = querySnapshot.docs
.map(
(QueryDocumentSnapshot<Map<String, dynamic>> token) => FirebaseTokenData(
image: token.data()['image'],
name: token.data()['name'],
contract: token.data()['contract'],
symbol: token.data()['symbol'],
id: token.data()['id'],
precision: token.data()['precision'],
(QueryDocumentSnapshot<Object?> token) => FirebaseTokenData(
network: network.name,
image: (token.data() as Map<String, dynamic>)['image'],
name: (token.data() as Map<String, dynamic>)['name'],
contract: (token.data() as Map<String, dynamic>)['contract'],
symbol: (token.data() as Map<String, dynamic>)['symbol'],
precision: (token.data() as Map<String, dynamic>)['precision'],
),
)
.toList();
Expand Down
13 changes: 7 additions & 6 deletions lib/core/firebase/firebase_token_data.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
class FirebaseTokenData {
final String image;
final String name;
final String network;
final String contract;
final String symbol;
final String id;
final String image;
final String name;
final int precision;
String get id => '$network-$contract-$symbol';

const FirebaseTokenData({
required this.image,
required this.name,
required this.network,
required this.contract,
required this.symbol,
required this.id,
required this.image,
required this.name,
required this.precision,
});
}
5 changes: 3 additions & 2 deletions lib/core/network/api/services/remote_config_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class RemoteConfigService {

int get newAccountFreshnessHours => FirebaseRemoteConfig.instance.getInt('newAccountFreshnessHours');

bool get isWalletEnabled => FirebaseRemoteConfig.instance.getBool('walletEnabled');
bool get isWalletEnabled => FirebaseRemoteConfig.instance.getBool('walletEnabled2');

bool isPayCpuEnabled(Network network) => _getMap('payCpuEnabledNetwork')[network.name] ?? false;

Expand Down Expand Up @@ -208,7 +208,8 @@ class RemoteConfigService {
}),
'signUpEnabled': true,
"signUpLinkUrl": "https://dao.hypha.earth/hypha/login",
'walletEnabled': false,
'walletEnabled': false, // to be retired
'walletEnabled2': true,
'newAccountFreshnessHours': 48,
'payCpuEnabledNetwork': json.encode({"telos": false, "telosTestnet": true, "eos": true, "eosTestnet": true})
});
Expand Down
12 changes: 8 additions & 4 deletions lib/ui/home_page/components/scanner_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,14 @@ class _ScannerWidgetState extends State<ScannerWidget> {
Get.back(result: true);
},
primaryButtonText: 'Continue',
secondaryButtonText: 'CLOSE',
secondaryButtonCallback: () {
Get.back(result: false);
},

// Note: Due to new App store rules, we can't have close button here
// Thanks for nothing, Apple!
//
// secondaryButtonText: 'CLOSE',
// secondaryButtonCallback: () {
// Get.back(result: false);
// },
),
),
shape: const RoundedRectangleBorder(
Expand Down
20 changes: 10 additions & 10 deletions lib/ui/token/token_details/components/token_details_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ class TokenDetailsView extends StatelessWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: HyphaAppButton(
title: 'Receive',
onPressed: () {
Get.to(() => ReceivePage(tokenData: context.read<TokenDetailsBloc>().state.token));
},
buttonType: ButtonType.secondary,
),
),
const SizedBox(width: 22),
// Expanded(
// child: HyphaAppButton(
// title: 'Receive',
// onPressed: () {
// Get.to(() => ReceivePage(tokenData: context.read<TokenDetailsBloc>().state.token));
// },
// buttonType: ButtonType.secondary,
// ),
// ),
// const SizedBox(width: 22),
Expanded(
child: HyphaAppButton(
title: 'Send',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class TokenDetailsBloc extends Bloc<TokenDetailsEvent, TokenDetailsState> {

FutureOr<void> _initial(_Initial event, Emitter<TokenDetailsState> emit) async {
emit(state.copyWith(loadingTransaction: true, loadingTokenBalance: true));

await _getTransactionHistoryDataUseCase
.getTransferTransactionsForToken(contract: state.token.contract, symbol: state.token.symbol)
.then((result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TokensSettingsView extends StatelessWidget {
withGradient: true,
child: Scaffold(
backgroundColor: Colors.transparent,
appBar: const OnboardingAppbar(title: 'Available Hypha', subTitle: ' network tokens'),
appBar: const OnboardingAppbar(title: 'Available Tokens', subTitle: ''),
body: BlocBuilder<TokensSettingsBloc, TokensSettingsState>(
builder: (context, state) {
return Padding(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:collection/collection.dart';
import 'package:hypha_wallet/core/firebase/firebase_database_service.dart';
import 'package:hypha_wallet/core/firebase/firebase_token_data.dart';
import 'package:hypha_wallet/core/network/repository/auth_repository.dart';
Expand All @@ -13,22 +14,23 @@ class GetAllTokensUseCase {

Future<Stream<List<WalletTokenData>>> run() async {
final user = _authRepository.authDataOrCrash;
final List<FirebaseTokenData> allTokens = await _database.getAllTokens();
final List<FirebaseTokenData> allTokens = await _database.getAllTokens(user.userProfileData.network);

final Stream<List<String>> userTokens = _database.getUserTokensLive(accountName: user.userProfileData.accountName);
final Stream<List<WalletTokenData>> tokens = userTokens.map((List<String> userTokens) {
return allTokens
.map(
(e) => WalletTokenData(
network: user.userProfileData.network.name,
selected: userTokens.contains(e.id),
image: e.image,
name: e.name,
contract: e.contract,
symbol: e.symbol,
id: e.id,
precision: e.precision,
),
)
.sortedBy((e) => e.name)
.toList();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ReceiveView extends StatelessWidget {
return HyphaSafeBottomNavigationBar(
child: HyphaAppButton(
onPressed: () {
/// Navigate to receive screen
context.read<ReceiveBloc>().add(const ReceiveEvent.onNextTapped());
},
title: 'Next',
buttonType: ButtonType.primary,
Expand Down
11 changes: 7 additions & 4 deletions lib/ui/transfer_tokens/receive/interactor/receive_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ part 'receive_state.dart';
class ReceiveBloc extends Bloc<ReceiveEvent, ReceiveState> {
final SendTokenUseCase sendTokenUseCase;

ReceiveBloc(
WalletTokenData tokenData,
this.sendTokenUseCase
) : super(ReceiveState(tokenData: tokenData)) {
ReceiveBloc(WalletTokenData tokenData, this.sendTokenUseCase) : super(ReceiveState(tokenData: tokenData)) {
on<_Initial>(_initial);
on<_OnKeypadTapped>(_onKeypadTapped);
on<_OnMemoEntered>(_onMemoEntered);
on<_OnNextTapped>(_onNextTapped);
on<_ClearPageCommand>((_, emit) => emit(state.copyWith(command: null)));
}

Expand Down Expand Up @@ -60,4 +58,9 @@ class ReceiveBloc extends Bloc<ReceiveEvent, ReceiveState> {
FutureOr<void> _onMemoEntered(_OnMemoEntered event, Emitter<ReceiveState> emit) {
emit(state.copyWith(memo: event.memo));
}

FutureOr<void> _onNextTapped(_OnNextTapped event, Emitter<ReceiveState> emit) {
print('Not yet implemented');
//emit(state.copyWith(memo: event.memo));
}
}
Loading
Loading