Skip to content

Commit

Permalink
fix: wallets parsing (#595)
Browse files Browse the repository at this point in the history
## Description
Made a few fields nullable, so they can be parsed properly. 

## Type of Change
- [x] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Refactoring
- [ ] Documentation
- [ ] Chore
  • Loading branch information
ice-brontes authored Jan 23, 2025
1 parent 6089c14 commit 805a15f
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 82 deletions.
2 changes: 1 addition & 1 deletion lib/app/features/wallets/model/coin_in_wallet_data.c.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CoinInWalletData with _$CoinInWalletData {
required CoinData coin,
required double amount,
required double balanceUSD,
required String walletId, // real wallet, not wallet view
String? walletId, // real wallet, not wallet view
}) = _CoinInWalletData;

const CoinInWalletData._();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ Future<List<WalletViewData>> currentUserWalletViews(Ref ref) async {
?.asset;

if (asset != null) {
coinAmount = asset.balance;
// TODO: (1) Check the result of formula with other services
coinAmount = double.tryParse(asset.balance) ?? 0;
coinBalanceUSD = (coinAmount / pow(10, coinDTO.decimals)) * coinDTO.priceUSD;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class WalletAsset with _$WalletAsset {
required String? contract,
required String symbol,
required int decimals,
required double balance,
required String balance,
required bool? verified,
}) = _WalletAsset;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mixin _$WalletAsset {
String? get contract => throw _privateConstructorUsedError;
String get symbol => throw _privateConstructorUsedError;
int get decimals => throw _privateConstructorUsedError;
double get balance => throw _privateConstructorUsedError;
String get balance => throw _privateConstructorUsedError;
bool? get verified => throw _privateConstructorUsedError;

/// Serializes this WalletAsset to a JSON map.
Expand All @@ -48,7 +48,7 @@ abstract class $WalletAssetCopyWith<$Res> {
String? contract,
String symbol,
int decimals,
double balance,
String balance,
bool? verified});
}

Expand Down Expand Up @@ -94,7 +94,7 @@ class _$WalletAssetCopyWithImpl<$Res, $Val extends WalletAsset>
balance: null == balance
? _value.balance
: balance // ignore: cast_nullable_to_non_nullable
as double,
as String,
verified: freezed == verified
? _value.verified
: verified // ignore: cast_nullable_to_non_nullable
Expand All @@ -116,7 +116,7 @@ abstract class _$$WalletAssetImplCopyWith<$Res>
String? contract,
String symbol,
int decimals,
double balance,
String balance,
bool? verified});
}

Expand Down Expand Up @@ -160,7 +160,7 @@ class __$$WalletAssetImplCopyWithImpl<$Res>
balance: null == balance
? _value.balance
: balance // ignore: cast_nullable_to_non_nullable
as double,
as String,
verified: freezed == verified
? _value.verified
: verified // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -192,7 +192,7 @@ class _$WalletAssetImpl implements _WalletAsset {
@override
final int decimals;
@override
final double balance;
final String balance;
@override
final bool? verified;

Expand Down Expand Up @@ -244,7 +244,7 @@ abstract class _WalletAsset implements WalletAsset {
required final String? contract,
required final String symbol,
required final int decimals,
required final double balance,
required final String balance,
required final bool? verified}) = _$WalletAssetImpl;

factory _WalletAsset.fromJson(Map<String, dynamic> json) =
Expand All @@ -259,7 +259,7 @@ abstract class _WalletAsset implements WalletAsset {
@override
int get decimals;
@override
double get balance;
String get balance;
@override
bool? get verified;

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ part 'coin_in_wallet.c.g.dart';
class CoinInWallet with _$CoinInWallet {
factory CoinInWallet({
required Coin coin,
required String walletId,
String? walletId,
}) = _CoinInWallet;

factory CoinInWallet.fromJson(Map<String, dynamic> json) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CoinInWallet _$CoinInWalletFromJson(Map<String, dynamic> json) {
/// @nodoc
mixin _$CoinInWallet {
Coin get coin => throw _privateConstructorUsedError;
String get walletId => throw _privateConstructorUsedError;
String? get walletId => throw _privateConstructorUsedError;

/// Serializes this CoinInWallet to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
Expand All @@ -39,7 +39,7 @@ abstract class $CoinInWalletCopyWith<$Res> {
CoinInWallet value, $Res Function(CoinInWallet) then) =
_$CoinInWalletCopyWithImpl<$Res, CoinInWallet>;
@useResult
$Res call({Coin coin, String walletId});
$Res call({Coin coin, String? walletId});

$CoinCopyWith<$Res> get coin;
}
Expand All @@ -60,17 +60,17 @@ class _$CoinInWalletCopyWithImpl<$Res, $Val extends CoinInWallet>
@override
$Res call({
Object? coin = null,
Object? walletId = null,
Object? walletId = freezed,
}) {
return _then(_value.copyWith(
coin: null == coin
? _value.coin
: coin // ignore: cast_nullable_to_non_nullable
as Coin,
walletId: null == walletId
walletId: freezed == walletId
? _value.walletId
: walletId // ignore: cast_nullable_to_non_nullable
as String,
as String?,
) as $Val);
}

Expand All @@ -93,7 +93,7 @@ abstract class _$$CoinInWalletImplCopyWith<$Res>
__$$CoinInWalletImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({Coin coin, String walletId});
$Res call({Coin coin, String? walletId});

@override
$CoinCopyWith<$Res> get coin;
Expand All @@ -113,33 +113,33 @@ class __$$CoinInWalletImplCopyWithImpl<$Res>
@override
$Res call({
Object? coin = null,
Object? walletId = null,
Object? walletId = freezed,
}) {
return _then(_$CoinInWalletImpl(
coin: null == coin
? _value.coin
: coin // ignore: cast_nullable_to_non_nullable
as Coin,
walletId: null == walletId
walletId: freezed == walletId
? _value.walletId
: walletId // ignore: cast_nullable_to_non_nullable
as String,
as String?,
));
}
}

/// @nodoc
@JsonSerializable()
class _$CoinInWalletImpl implements _CoinInWallet {
_$CoinInWalletImpl({required this.coin, required this.walletId});
_$CoinInWalletImpl({required this.coin, this.walletId});

factory _$CoinInWalletImpl.fromJson(Map<String, dynamic> json) =>
_$$CoinInWalletImplFromJson(json);

@override
final Coin coin;
@override
final String walletId;
final String? walletId;

@override
String toString() {
Expand Down Expand Up @@ -177,17 +177,16 @@ class _$CoinInWalletImpl implements _CoinInWallet {
}

abstract class _CoinInWallet implements CoinInWallet {
factory _CoinInWallet(
{required final Coin coin,
required final String walletId}) = _$CoinInWalletImpl;
factory _CoinInWallet({required final Coin coin, final String? walletId}) =
_$CoinInWalletImpl;

factory _CoinInWallet.fromJson(Map<String, dynamic> json) =
_$CoinInWalletImpl.fromJson;

@override
Coin get coin;
@override
String get walletId;
String? get walletId;

/// Create a copy of CoinInWallet
/// with the given fields replaced by the non-null parameter values.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CoinInWalletListConverter implements JsonConverter<List<CoinInWallet>, Lis
return json.map((e) {
final json = e as Map<String, dynamic>;
return CoinInWallet(
walletId: json['walletId'] as String,
walletId: json['walletId'] as String?,
coin: Coin.fromJson(json),
);
}).toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ WalletViewAggregationItem _$WalletViewAggregationItemFromJson(

/// @nodoc
mixin _$WalletViewAggregationItem {
@JsonKey(defaultValue: [])
List<WalletViewAggregationWallet> get wallets =>
throw _privateConstructorUsedError;
double get totalBalance => throw _privateConstructorUsedError;
Expand All @@ -41,7 +42,9 @@ abstract class $WalletViewAggregationItemCopyWith<$Res> {
$Res Function(WalletViewAggregationItem) then) =
_$WalletViewAggregationItemCopyWithImpl<$Res, WalletViewAggregationItem>;
@useResult
$Res call({List<WalletViewAggregationWallet> wallets, double totalBalance});
$Res call(
{@JsonKey(defaultValue: []) List<WalletViewAggregationWallet> wallets,
double totalBalance});
}

/// @nodoc
Expand Down Expand Up @@ -85,7 +88,9 @@ abstract class _$$WalletViewAggregationItemImplCopyWith<$Res>
__$$WalletViewAggregationItemImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({List<WalletViewAggregationWallet> wallets, double totalBalance});
$Res call(
{@JsonKey(defaultValue: []) List<WalletViewAggregationWallet> wallets,
double totalBalance});
}

/// @nodoc
Expand Down Expand Up @@ -123,7 +128,8 @@ class __$$WalletViewAggregationItemImplCopyWithImpl<$Res>
@JsonSerializable()
class _$WalletViewAggregationItemImpl implements _WalletViewAggregationItem {
const _$WalletViewAggregationItemImpl(
{required final List<WalletViewAggregationWallet> wallets,
{@JsonKey(defaultValue: [])
required final List<WalletViewAggregationWallet> wallets,
required this.totalBalance})
: _wallets = wallets;

Expand All @@ -132,6 +138,7 @@ class _$WalletViewAggregationItemImpl implements _WalletViewAggregationItem {

final List<WalletViewAggregationWallet> _wallets;
@override
@JsonKey(defaultValue: [])
List<WalletViewAggregationWallet> get wallets {
if (_wallets is EqualUnmodifiableListView) return _wallets;
// ignore: implicit_dynamic_type
Expand Down Expand Up @@ -180,13 +187,15 @@ class _$WalletViewAggregationItemImpl implements _WalletViewAggregationItem {

abstract class _WalletViewAggregationItem implements WalletViewAggregationItem {
const factory _WalletViewAggregationItem(
{required final List<WalletViewAggregationWallet> wallets,
{@JsonKey(defaultValue: [])
required final List<WalletViewAggregationWallet> wallets,
required final double totalBalance}) = _$WalletViewAggregationItemImpl;

factory _WalletViewAggregationItem.fromJson(Map<String, dynamic> json) =
_$WalletViewAggregationItemImpl.fromJson;

@override
@JsonKey(defaultValue: [])
List<WalletViewAggregationWallet> get wallets;
@override
double get totalBalance;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ part 'wallet_view_coin_data.c.g.dart';
@freezed
class WalletViewCoinData with _$WalletViewCoinData {
const factory WalletViewCoinData({
required String walletId,

required String coinId,
String? walletId,
}) = _WalletViewCoinData;

factory WalletViewCoinData.fromJson(Map<String, dynamic> json) =>
Expand Down
Loading

0 comments on commit 805a15f

Please sign in to comment.