2023-05-26 21:21:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Stack Wallet.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2023 Cypher Stack
|
|
|
|
* All Rights Reserved.
|
|
|
|
* The code is distributed under GPLv3 license, see LICENSE file for details.
|
|
|
|
* Generated by Cypher Stack on 2023-05-26
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-03-30 16:40:35 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-05-09 15:21:04 +00:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2023-03-30 16:40:35 +00:00
|
|
|
import 'package:flutter_svg/svg.dart';
|
|
|
|
import 'package:isar/isar.dart';
|
|
|
|
import 'package:stackwallet/models/isar/exchange_cache/currency.dart';
|
|
|
|
import 'package:stackwallet/services/exchange/exchange_data_loading_service.dart';
|
2023-05-09 15:21:04 +00:00
|
|
|
import 'package:stackwallet/themes/coin_icon_provider.dart';
|
2023-03-30 16:40:35 +00:00
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|
|
|
|
2023-05-09 15:21:04 +00:00
|
|
|
class EthTokenIcon extends ConsumerStatefulWidget {
|
2023-03-30 16:40:35 +00:00
|
|
|
const EthTokenIcon({
|
|
|
|
Key? key,
|
|
|
|
required this.contractAddress,
|
2023-04-03 22:38:48 +00:00
|
|
|
this.size = 22,
|
2023-03-30 16:40:35 +00:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final String contractAddress;
|
2023-04-03 22:38:48 +00:00
|
|
|
final double size;
|
2023-03-30 16:40:35 +00:00
|
|
|
|
|
|
|
@override
|
2023-05-09 15:21:04 +00:00
|
|
|
ConsumerState<EthTokenIcon> createState() => _EthTokenIconState();
|
2023-03-30 16:40:35 +00:00
|
|
|
}
|
|
|
|
|
2023-05-09 15:21:04 +00:00
|
|
|
class _EthTokenIconState extends ConsumerState<EthTokenIcon> {
|
2023-03-30 16:40:35 +00:00
|
|
|
late final String? imageUrl;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
imageUrl = ExchangeDataLoadingService.instance.isar.currencies
|
|
|
|
.where()
|
|
|
|
.filter()
|
|
|
|
.tokenContractEqualTo(widget.contractAddress, caseSensitive: false)
|
|
|
|
.findFirstSync()
|
|
|
|
?.image;
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
if (imageUrl == null || imageUrl!.isEmpty) {
|
|
|
|
return SvgPicture.asset(
|
2023-05-09 15:21:04 +00:00
|
|
|
ref.watch(coinIconProvider(Coin.ethereum)),
|
2023-04-03 22:38:48 +00:00
|
|
|
width: widget.size,
|
|
|
|
height: widget.size,
|
2023-03-30 16:40:35 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return SvgPicture.network(
|
|
|
|
imageUrl!,
|
2023-04-03 22:38:48 +00:00
|
|
|
width: widget.size,
|
|
|
|
height: widget.size,
|
2023-03-30 16:40:35 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|