mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-05-03 03:12:18 +00:00
eth token prices fixes
This commit is contained in:
parent
aaa6905f95
commit
b0eeec7568
5 changed files with 19 additions and 14 deletions
lib
|
@ -317,13 +317,6 @@ class _MaterialAppWithThemeState extends ConsumerState<MaterialAppWithTheme>
|
||||||
_desktopHasPassword =
|
_desktopHasPassword =
|
||||||
await ref.read(storageCryptoHandlerProvider).hasPassword();
|
await ref.read(storageCryptoHandlerProvider).hasPassword();
|
||||||
}
|
}
|
||||||
|
|
||||||
ref
|
|
||||||
.read(priceAnd24hChangeNotifierProvider)
|
|
||||||
.tokenContractAddressesToCheck
|
|
||||||
.addAll(
|
|
||||||
await MainDB.instance.getEthContracts().addressProperty().findAll(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> load() async {
|
Future<void> load() async {
|
||||||
|
|
|
@ -23,6 +23,7 @@ import 'package:stackwallet/pages/add_wallet_views/add_token_view/sub_widgets/ad
|
||||||
import 'package:stackwallet/pages/add_wallet_views/add_token_view/sub_widgets/add_token_text.dart';
|
import 'package:stackwallet/pages/add_wallet_views/add_token_view/sub_widgets/add_token_text.dart';
|
||||||
import 'package:stackwallet/pages/home_view/home_view.dart';
|
import 'package:stackwallet/pages/home_view/home_view.dart';
|
||||||
import 'package:stackwallet/pages_desktop_specific/desktop_home_view.dart';
|
import 'package:stackwallet/pages_desktop_specific/desktop_home_view.dart';
|
||||||
|
import 'package:stackwallet/providers/global/price_provider.dart';
|
||||||
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
||||||
import 'package:stackwallet/themes/stack_colors.dart';
|
import 'package:stackwallet/themes/stack_colors.dart';
|
||||||
import 'package:stackwallet/utilities/assets.dart';
|
import 'package:stackwallet/utilities/assets.dart';
|
||||||
|
@ -151,6 +152,7 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
|
||||||
|
|
||||||
if (contract != null) {
|
if (contract != null) {
|
||||||
await MainDB.instance.putEthContract(contract);
|
await MainDB.instance.putEthContract(contract);
|
||||||
|
unawaited(ref.read(priceAnd24hChangeNotifierProvider).updatePrice());
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
if (tokenEntities
|
if (tokenEntities
|
||||||
|
@ -175,7 +177,8 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
|
||||||
|
|
||||||
if (contracts.isEmpty) {
|
if (contracts.isEmpty) {
|
||||||
contracts.addAll(DefaultTokens.list);
|
contracts.addAll(DefaultTokens.list);
|
||||||
MainDB.instance.putEthContracts(contracts);
|
MainDB.instance.putEthContracts(contracts).then(
|
||||||
|
(_) => ref.read(priceAnd24hChangeNotifierProvider).updatePrice());
|
||||||
}
|
}
|
||||||
|
|
||||||
tokenEntities.addAll(contracts.map((e) => AddTokenListElementData(e)));
|
tokenEntities.addAll(contracts.map((e) => AddTokenListElementData(e)));
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
@ -107,6 +108,7 @@ class _AddWalletViewState extends ConsumerState<AddWalletView> {
|
||||||
|
|
||||||
if (contract != null) {
|
if (contract != null) {
|
||||||
await MainDB.instance.putEthContract(contract);
|
await MainDB.instance.putEthContract(contract);
|
||||||
|
unawaited(ref.read(priceAnd24hChangeNotifierProvider).updatePrice());
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
if (tokenEntities
|
if (tokenEntities
|
||||||
|
@ -143,7 +145,8 @@ class _AddWalletViewState extends ConsumerState<AddWalletView> {
|
||||||
|
|
||||||
if (contracts.isEmpty) {
|
if (contracts.isEmpty) {
|
||||||
contracts.addAll(DefaultTokens.list);
|
contracts.addAll(DefaultTokens.list);
|
||||||
MainDB.instance.putEthContracts(contracts);
|
MainDB.instance.putEthContracts(contracts).then(
|
||||||
|
(value) => ref.read(priceAnd24hChangeNotifierProvider).updatePrice());
|
||||||
}
|
}
|
||||||
|
|
||||||
tokenEntities.addAll(contracts.map((e) => EthTokenEntity(e)));
|
tokenEntities.addAll(contracts.map((e) => EthTokenEntity(e)));
|
||||||
|
|
|
@ -104,7 +104,7 @@ class _TransactionCardStateV2 extends ConsumerState<TransactionCardV2> {
|
||||||
|
|
||||||
final price = ref
|
final price = ref
|
||||||
.watch(priceAnd24hChangeNotifierProvider.select((value) => isTokenTx
|
.watch(priceAnd24hChangeNotifierProvider.select((value) => isTokenTx
|
||||||
? value.getTokenPrice(_transaction.otherData!)
|
? value.getTokenPrice(tokenContract!.address)
|
||||||
: value.getPrice(coin)))
|
: value.getPrice(coin)))
|
||||||
.item1;
|
.item1;
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,9 @@ import 'dart:async';
|
||||||
|
|
||||||
import 'package:decimal/decimal.dart';
|
import 'package:decimal/decimal.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:http/http.dart';
|
import 'package:isar/isar.dart';
|
||||||
|
import 'package:stackwallet/db/isar/main_db.dart';
|
||||||
|
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||||
import 'package:stackwallet/networking/http.dart';
|
import 'package:stackwallet/networking/http.dart';
|
||||||
import 'package:stackwallet/services/price.dart';
|
import 'package:stackwallet/services/price.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
|
@ -20,7 +22,9 @@ import 'package:tuple/tuple.dart';
|
||||||
|
|
||||||
class PriceService extends ChangeNotifier {
|
class PriceService extends ChangeNotifier {
|
||||||
late final String baseTicker;
|
late final String baseTicker;
|
||||||
final Set<String> tokenContractAddressesToCheck = {};
|
Future<Set<String>> get tokenContractAddressesToCheck async =>
|
||||||
|
(await MainDB.instance.getEthContracts().addressProperty().findAll())
|
||||||
|
.toSet();
|
||||||
final Duration updateInterval = const Duration(seconds: 60);
|
final Duration updateInterval = const Duration(seconds: 60);
|
||||||
|
|
||||||
Timer? _timer;
|
Timer? _timer;
|
||||||
|
@ -52,9 +56,11 @@ class PriceService extends ChangeNotifier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tokenContractAddressesToCheck.isNotEmpty) {
|
final _tokenContractAddressesToCheck = await tokenContractAddressesToCheck;
|
||||||
|
|
||||||
|
if (_tokenContractAddressesToCheck.isNotEmpty) {
|
||||||
final tokenPriceMap = await _priceAPI.getPricesAnd24hChangeForEthTokens(
|
final tokenPriceMap = await _priceAPI.getPricesAnd24hChangeForEthTokens(
|
||||||
contractAddresses: tokenContractAddressesToCheck,
|
contractAddresses: _tokenContractAddressesToCheck,
|
||||||
baseCurrency: baseTicker,
|
baseCurrency: baseTicker,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue