add monkey image to hive and display on wallet card

This commit is contained in:
ryleedavis 2023-07-26 11:54:10 -06:00
parent 683364750a
commit 2eb10e249f
2 changed files with 37 additions and 11 deletions

View file

@ -10,6 +10,7 @@
import 'dart:async';
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
@ -19,6 +20,7 @@ import 'package:stackwallet/pages/wallet_view/sub_widgets/wallet_refresh_button.
import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/providers/wallet/public_private_balance_state_provider.dart';
import 'package:stackwallet/providers/wallet/wallet_balance_toggle_state_provider.dart';
import 'package:stackwallet/services/coins/banano/banano_wallet.dart';
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
import 'package:stackwallet/services/event_bus/events/global/balance_refreshed_event.dart';
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
@ -101,10 +103,12 @@ class _WalletSummaryInfoState extends ConsumerState<WalletSummaryInfo> {
bool isMonkey = true;
final manager = ref.watch(walletsChangeNotifierProvider
.select((value) => value.getManager(widget.walletId)));
final externalCalls = ref.watch(
prefsChangeNotifierProvider.select((value) => value.externalCalls));
final coin = ref.watch(walletsChangeNotifierProvider
.select((value) => value.getManager(widget.walletId).coin));
final coin = manager.coin;
final balance = ref.watch(walletsChangeNotifierProvider
.select((value) => value.getManager(widget.walletId).balance));
@ -141,18 +145,24 @@ class _WalletSummaryInfoState extends ConsumerState<WalletSummaryInfo> {
title = _showAvailable ? "Available balance" : "Full balance";
}
List<int>? imageBytes;
if (coin == Coin.banano) {
imageBytes = (manager.wallet as BananoWallet).getMonkeyImageBytes();
}
return ConditionalParent(
condition: isMonkey && Coin == Coin.banano,
builder: (child) => Container(
decoration: BoxDecoration(
image: DecorationImage(
alignment: Alignment.centerRight,
image: NetworkImage(
'https://monkey.banano.cc/api/v1/monkey/$receivingAddress?format=png&size=512',
condition: imageBytes != null,
builder: (child) => Stack(
children: [
Positioned.fill(
left: 150.0,
child: SvgPicture.memory(
Uint8List.fromList(imageBytes!),
),
),
),
child: child,
child,
],
),
child: Row(
children: [

View file

@ -4,6 +4,7 @@ import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:isar/isar.dart';
import 'package:nanodart/nanodart.dart';
import 'package:stackwallet/db/hive/db.dart';
import 'package:stackwallet/db/isar/main_db.dart';
import 'package:stackwallet/models/balance.dart';
import 'package:stackwallet/models/isar/models/isar_models.dart';
@ -925,4 +926,19 @@ class BananoWallet extends CoinServiceAPI
);
await updateCachedChainHeight(height ?? 0);
}
Future<void> updateMonkeyImageBytes(List<int> bytes) async {
await DB.instance.put<dynamic>(
boxName: _walletId,
key: "monkeyImageBytesKey",
value: bytes,
);
}
List<int>? getMonkeyImageBytes() {
return DB.instance.get<dynamic>(
boxName: _walletId,
key: "monkeyImageBytesKey",
) as List<int>?;
}
}