Skip to content

Commit 574f87a

Browse files
committed
refactor: simplify expiry extraction using extractExpiryToReadableDate utility
- Use extractExpiryToReadableDate from time-utils instead of manual extraction - Remove UTC zone specification from convertTimestampToReadableDate - Reduce getExpirationDate function from 26 to 9 lines - Import GatorPermissionRule type for proper typing
1 parent 03f5634 commit 574f87a

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

shared/lib/gator-permissions/time-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function convertAmountPerSecondToAmountPerPeriod(
8787
* Converts a unix timestamp(in seconds) to a human-readable date format.
8888
*
8989
* @param timestamp - The unix timestamp in seconds.
90-
* @returns The formatted date string in mm/dd/yyyy format in UTC timezone.
90+
* @returns The formatted date string in mm/dd/yyyy format in local timezone.
9191
*/
9292
export const convertTimestampToReadableDate = (timestamp: number): string => {
9393
if (timestamp === 0) {

ui/components/multichain/pages/gator-permissions/components/review-gator-permission-item.tsx

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import {
3737
getPeriodFrequencyValueTranslationKey,
3838
convertAmountPerSecondToAmountPerPeriod,
3939
getDecimalizedHexValue,
40+
extractExpiryToReadableDate,
41+
GatorPermissionRule,
4042
} from '../../../../../../shared/lib/gator-permissions';
4143
import { PreferredAvatar } from '../../../../app/preferred-avatar';
4244
import { BackgroundColor } from '../../../../../helpers/constants/design-system';
@@ -160,33 +162,19 @@ export const ReviewGatorPermissionItem = ({
160162
};
161163

162164
/**
163-
* Returns the expiration date from the delegation context
165+
* Returns the expiration date from the permission rules
164166
*
165167
* @returns The expiration date
166168
*/
167169
const getExpirationDate = useCallback((): string => {
168-
// Check if rules exist in the permission response
169-
if ('rules' in permissionResponse) {
170-
const { rules } = permissionResponse;
171-
172-
if (rules && Array.isArray(rules)) {
173-
const expiryRule = rules.find(
174-
(rule: { type: string }) => rule.type === 'expiry',
175-
);
176-
177-
if (
178-
expiryRule &&
179-
'data' in expiryRule &&
180-
expiryRule.data &&
181-
typeof expiryRule.data === 'object' &&
182-
'timestamp' in expiryRule.data
183-
) {
184-
const { timestamp } = expiryRule.data;
185-
return convertTimestampToReadableDate(timestamp as number);
186-
}
170+
if ('rules' in permissionResponse && permissionResponse.rules) {
171+
const expiryDate = extractExpiryToReadableDate(
172+
permissionResponse.rules as GatorPermissionRule[],
173+
);
174+
if (expiryDate) {
175+
return expiryDate;
187176
}
188177
}
189-
190178
return t('gatorPermissionNoExpiration');
191179
}, [permissionResponse, t]);
192180

0 commit comments

Comments
 (0)