Skip to content

Commit

Permalink
fix: Fix bugs when farm doesn't exist in env
Browse files Browse the repository at this point in the history
  • Loading branch information
redDwarf03 committed Jul 9, 2024
1 parent db887eb commit 7c5df97
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 49 deletions.
5 changes: 4 additions & 1 deletion lib/application/router_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ class RouterFactory with ModelParser {

for (final result in results) {
final getFarmListResponse = GetFarmListResponse.fromJson(result);
if (getFarmListResponse.type != farmType) continue;
if (getFarmListResponse.type != null ||
getFarmListResponse.type == 2) {
continue;
}
final dexpool = poolList.singleWhere(
(pool) =>
pool.lpToken.address!.toUpperCase() ==
Expand Down
2 changes: 1 addition & 1 deletion lib/domain/models/util/get_farm_list_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class GetFarmListResponse with _$GetFarmListResponse {
@JsonKey(name: 'start_date') required int startDate,
@JsonKey(name: 'end_date') required int endDate,
@JsonKey(name: 'reward_token') required String rewardTokenAddress,
@JsonKey(name: 'type') required int type,
@JsonKey(name: 'type') int? type,
required String address,
}) = _GetFarmListResponse;

Expand Down
26 changes: 13 additions & 13 deletions lib/domain/models/util/get_farm_list_response.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mixin _$GetFarmListResponse {
@JsonKey(name: 'reward_token')
String get rewardTokenAddress => throw _privateConstructorUsedError;
@JsonKey(name: 'type')
int get type => throw _privateConstructorUsedError;
int? get type => throw _privateConstructorUsedError;
String get address => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
Expand All @@ -49,7 +49,7 @@ abstract class $GetFarmListResponseCopyWith<$Res> {
@JsonKey(name: 'start_date') int startDate,
@JsonKey(name: 'end_date') int endDate,
@JsonKey(name: 'reward_token') String rewardTokenAddress,
@JsonKey(name: 'type') int type,
@JsonKey(name: 'type') int? type,
String address});
}

Expand All @@ -70,7 +70,7 @@ class _$GetFarmListResponseCopyWithImpl<$Res, $Val extends GetFarmListResponse>
Object? startDate = null,
Object? endDate = null,
Object? rewardTokenAddress = null,
Object? type = null,
Object? type = freezed,
Object? address = null,
}) {
return _then(_value.copyWith(
Expand All @@ -90,10 +90,10 @@ class _$GetFarmListResponseCopyWithImpl<$Res, $Val extends GetFarmListResponse>
? _value.rewardTokenAddress
: rewardTokenAddress // ignore: cast_nullable_to_non_nullable
as String,
type: null == type
type: freezed == type
? _value.type
: type // ignore: cast_nullable_to_non_nullable
as int,
as int?,
address: null == address
? _value.address
: address // ignore: cast_nullable_to_non_nullable
Expand All @@ -115,7 +115,7 @@ abstract class _$$GetFarmListResponseImplCopyWith<$Res>
@JsonKey(name: 'start_date') int startDate,
@JsonKey(name: 'end_date') int endDate,
@JsonKey(name: 'reward_token') String rewardTokenAddress,
@JsonKey(name: 'type') int type,
@JsonKey(name: 'type') int? type,
String address});
}

Expand All @@ -134,7 +134,7 @@ class __$$GetFarmListResponseImplCopyWithImpl<$Res>
Object? startDate = null,
Object? endDate = null,
Object? rewardTokenAddress = null,
Object? type = null,
Object? type = freezed,
Object? address = null,
}) {
return _then(_$GetFarmListResponseImpl(
Expand All @@ -154,10 +154,10 @@ class __$$GetFarmListResponseImplCopyWithImpl<$Res>
? _value.rewardTokenAddress
: rewardTokenAddress // ignore: cast_nullable_to_non_nullable
as String,
type: null == type
type: freezed == type
? _value.type
: type // ignore: cast_nullable_to_non_nullable
as int,
as int?,
address: null == address
? _value.address
: address // ignore: cast_nullable_to_non_nullable
Expand All @@ -174,7 +174,7 @@ class _$GetFarmListResponseImpl implements _GetFarmListResponse {
@JsonKey(name: 'start_date') required this.startDate,
@JsonKey(name: 'end_date') required this.endDate,
@JsonKey(name: 'reward_token') required this.rewardTokenAddress,
@JsonKey(name: 'type') required this.type,
@JsonKey(name: 'type') this.type,
required this.address});

factory _$GetFarmListResponseImpl.fromJson(Map<String, dynamic> json) =>
Expand All @@ -194,7 +194,7 @@ class _$GetFarmListResponseImpl implements _GetFarmListResponse {
final String rewardTokenAddress;
@override
@JsonKey(name: 'type')
final int type;
final int? type;
@override
final String address;

Expand Down Expand Up @@ -245,7 +245,7 @@ abstract class _GetFarmListResponse implements GetFarmListResponse {
@JsonKey(name: 'start_date') required final int startDate,
@JsonKey(name: 'end_date') required final int endDate,
@JsonKey(name: 'reward_token') required final String rewardTokenAddress,
@JsonKey(name: 'type') required final int type,
@JsonKey(name: 'type') final int? type,
required final String address}) = _$GetFarmListResponseImpl;

factory _GetFarmListResponse.fromJson(Map<String, dynamic> json) =
Expand All @@ -265,7 +265,7 @@ abstract class _GetFarmListResponse implements GetFarmListResponse {
String get rewardTokenAddress;
@override
@JsonKey(name: 'type')
int get type;
int? get type;
@override
String get address;
@override
Expand Down
2 changes: 1 addition & 1 deletion lib/domain/models/util/get_farm_list_response.g.dart

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

1 change: 1 addition & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@
"farmLockBlockEarnRewardsHeader": "2) Earn more",
"farmLockBlockEarnRewardsDesc": "Farm your LP Tokens to earn rewards. By locking them for a specified period, you increase your rewards.\nThe longer you lock, the greater your rewards.",
"farmLockBlockEarnRewardsBtnAdd": "Add",
"farmLockBlockEarnRewardsBtnNotAvailable": "Farm not available",
"farmLockBlockEarnRewardsViewGuideArticle": "View the guide article",
"farmLockBlockAprLbl": "APR 3 years",
"farmLockBlockFarmedTokensSummaryHeader": "Farmed Tokens Summary",
Expand Down
54 changes: 31 additions & 23 deletions lib/ui/views/farm_lock/components/farm_lock_block_earn_rewards.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,36 +118,40 @@ class FarmLockBlockEarnRewards extends ConsumerWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
InkWell(
onTap: () async {
final poolJson = jsonEncode(pool.toJson());
final poolEncoded = Uri.encodeComponent(poolJson);
final farmLockJson = jsonEncode(farmLock!.toJson());
final farmLockEncoded = Uri.encodeComponent(farmLockJson);
await context.push(
Uri(
path: FarmLockDepositSheet.routerPage,
queryParameters: {
'pool': poolEncoded,
'farmLock': farmLockEncoded,
onTap: farmLock == null
? null
: () async {
final poolJson = jsonEncode(pool.toJson());
final poolEncoded = Uri.encodeComponent(poolJson);
final farmLockJson = jsonEncode(farmLock!.toJson());
final farmLockEncoded = Uri.encodeComponent(farmLockJson);
await context.push(
Uri(
path: FarmLockDepositSheet.routerPage,
queryParameters: {
'pool': poolEncoded,
'farmLock': farmLockEncoded,
},
).toString(),
);
if (context.mounted) {
{
await context
.findAncestorStateOfType<FarmLockSheetState>()
?.loadInfo(sortCriteria: sortCriteria);
}
}
},
).toString(),
);
if (context.mounted) {
{
await context
.findAncestorStateOfType<FarmLockSheetState>()
?.loadInfo(sortCriteria: sortCriteria);
}
}
},
child: Column(
children: [
Container(
height: 50,
width: 50,
alignment: Alignment.center,
decoration: BoxDecoration(
gradient: aedappfm.AppThemeBase.gradientBtn,
gradient: farmLock == null
? aedappfm.AppThemeBase.gradient
: aedappfm.AppThemeBase.gradientBtn,
shape: BoxShape.circle,
),
child: const Icon(
Expand All @@ -159,7 +163,11 @@ class FarmLockBlockEarnRewards extends ConsumerWidget {
height: 5,
),
Text(
AppLocalizations.of(context)!.farmLockBlockEarnRewardsBtnAdd,
farmLock == null
? AppLocalizations.of(context)!
.farmLockBlockEarnRewardsBtnNotAvailable
: AppLocalizations.of(context)!
.farmLockBlockEarnRewardsBtnAdd,
style: const TextStyle(fontSize: 10),
),
],
Expand Down
22 changes: 12 additions & 10 deletions lib/ui/views/farm_lock/farm_lock_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,18 @@ class FarmLockSheetState extends ConsumerState<FarmLockSheet> {
);

final farmLockAddress = contextAddresses.aeETHUCOFarmLockAddress;
farmLock = await ref.read(
DexFarmLockProviders.getFarmLockInfos(
farmLockAddress,
pool!.poolAddress,
dexFarmLockInput: DexFarmLock(
poolAddress: pool!.poolAddress,
farmAddress: farmLockAddress,
),
).future,
);
if (farmLockAddress.isNotEmpty) {
farmLock = await ref.read(
DexFarmLockProviders.getFarmLockInfos(
farmLockAddress,
pool!.poolAddress,
dexFarmLockInput: DexFarmLock(
poolAddress: pool!.poolAddress,
farmAddress: farmLockAddress,
),
).future,
);
}

ref.read(FarmLockFormProvider.farmLockForm.notifier)
..setPool(pool!)
Expand Down

0 comments on commit 7c5df97

Please sign in to comment.