-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Show warning and error depending on the blocked state
- Loading branch information
Showing
7 changed files
with
199 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/components/WorldListPage_WorldsForEnsOwnersFeature/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,51 @@ | ||
import { WorldsWalletStats } from 'lib/api/worlds' | ||
|
||
export const fromBytesToMegabytes = (bytes: number) => { | ||
return bytes / 1024 / 1024 | ||
} | ||
|
||
export const BLOCK_DELAY_IN_MILLISECONDS = 48 * 60 * 60 * 1000 // 48 hours | ||
|
||
export enum DCLWorldsStatus { | ||
OK = 'ok', | ||
BLOCKED = 'blocked', | ||
TO_BE_BLOCKED = 'to-be-blocked' | ||
} | ||
|
||
export type GetDCLWorldsStatusResult = | ||
| { | ||
status: DCLWorldsStatus.OK | ||
} | ||
| { | ||
status: DCLWorldsStatus.TO_BE_BLOCKED | ||
toBeBlockedAt: Date | ||
} | ||
| { | ||
status: DCLWorldsStatus.BLOCKED | ||
blockedAt: Date | ||
} | ||
|
||
export const getDCLWorldsStatus = (stats: WorldsWalletStats): GetDCLWorldsStatusResult => { | ||
const now = new Date().getTime() | ||
const blockedSince = stats.blockedSince ? new Date(stats.blockedSince).getTime() : null | ||
|
||
if (stats.usedSpace <= stats.maxAllowedSpace || !blockedSince || now < blockedSince) { | ||
return { | ||
status: DCLWorldsStatus.OK | ||
} | ||
} | ||
|
||
const blockedAt = new Date(blockedSince + BLOCK_DELAY_IN_MILLISECONDS) | ||
|
||
if (now - blockedSince > BLOCK_DELAY_IN_MILLISECONDS) { | ||
return { | ||
status: DCLWorldsStatus.BLOCKED, | ||
blockedAt: blockedAt | ||
} | ||
} | ||
|
||
return { | ||
status: DCLWorldsStatus.TO_BE_BLOCKED, | ||
toBeBlockedAt: blockedAt | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters