-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
240 additions
and
9 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
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
96 changes: 96 additions & 0 deletions
96
src/components/WorldListPage_WorldsForEnsOwnersFeature/utils.spec.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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { WorldsWalletStats } from 'lib/api/worlds' | ||
import { BLOCK_DELAY_IN_MILLISECONDS, DCLWorldsStatus, fromBytesToMegabytes, getDCLWorldsStatus } from './utils' | ||
|
||
describe('when converting from bytes to megabytes', () => { | ||
describe('when the number is 10000000', () => { | ||
it('should return 9.5367431640625', () => { | ||
expect(fromBytesToMegabytes(10000000)).toBe(9.5367431640625) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('when getting the dcl worlds status', () => { | ||
let stats: WorldsWalletStats | ||
|
||
beforeEach(() => { | ||
stats = { | ||
usedSpace: '0', | ||
maxAllowedSpace: '0' | ||
} as WorldsWalletStats | ||
}) | ||
|
||
describe('when the used space is lower than the max allowed space', () => { | ||
beforeEach(() => { | ||
stats.usedSpace = '100' | ||
stats.maxAllowedSpace = '101' | ||
}) | ||
|
||
it('should return status ok', () => { | ||
expect(getDCLWorldsStatus(stats)).toEqual({ status: DCLWorldsStatus.OK }) | ||
}) | ||
}) | ||
|
||
describe('when the used space is equal to the max allowed space', () => { | ||
beforeEach(() => { | ||
stats.usedSpace = '100' | ||
stats.maxAllowedSpace = '100' | ||
}) | ||
|
||
it('should return status ok', () => { | ||
expect(getDCLWorldsStatus(stats)).toEqual({ status: DCLWorldsStatus.OK }) | ||
}) | ||
}) | ||
|
||
describe('when the used space is greater to the max allowed space', () => { | ||
beforeEach(() => { | ||
stats.usedSpace = '101' | ||
stats.maxAllowedSpace = '100' | ||
}) | ||
|
||
describe('and blocked since is not defined', () => { | ||
beforeEach(() => { | ||
stats.blockedSince = undefined | ||
}) | ||
|
||
it('should return status ok', () => { | ||
expect(getDCLWorldsStatus(stats)).toEqual({ status: DCLWorldsStatus.OK }) | ||
}) | ||
}) | ||
|
||
describe('and blocked since is defined as 1 day later than now', () => { | ||
beforeEach(() => { | ||
stats.blockedSince = new Date(Date.now() + 24 * 60 * 60 * 1000 /* 1 day */).toISOString() | ||
}) | ||
|
||
it('should return status ok', () => { | ||
expect(getDCLWorldsStatus(stats)).toEqual({ status: DCLWorldsStatus.OK }) | ||
}) | ||
}) | ||
|
||
describe('and blocked since is defined as 1 day earlier than now', () => { | ||
beforeEach(() => { | ||
stats.blockedSince = new Date(Date.now() - 24 * 60 * 60 * 1000 /* 1 day */).toISOString() | ||
}) | ||
|
||
it('should return status to be blocked with the to be blocked date', () => { | ||
expect(getDCLWorldsStatus(stats)).toEqual({ | ||
status: DCLWorldsStatus.TO_BE_BLOCKED, | ||
toBeBlockedAt: new Date(new Date(stats.blockedSince!).getTime() + BLOCK_DELAY_IN_MILLISECONDS) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('and blocked since is defined as 3 days earlier than now', () => { | ||
beforeEach(() => { | ||
stats.blockedSince = new Date(Date.now() - 72 * 60 * 60 * 1000 /* 3 days */).toISOString() | ||
}) | ||
|
||
it('should return status to be blocked with the to be blocked date', () => { | ||
expect(getDCLWorldsStatus(stats)).toEqual({ | ||
status: DCLWorldsStatus.BLOCKED, | ||
blockedAt: new Date(new Date(stats.blockedSince!).getTime() + BLOCK_DELAY_IN_MILLISECONDS) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
50 changes: 49 additions & 1 deletion
50
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 / 1000000 | ||
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