-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from ethereum-push-notification-service/pre-re…
…lease-1.1.13 Release 1.1.13
- Loading branch information
Showing
34 changed files
with
1,020 additions
and
321 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export default function DisableSnoozeButton() { | ||
const defaultSnapOrigin = `local:http://localhost:8080`; | ||
|
||
const disableSnooze = async () => { | ||
console.log( | ||
await window.ethereum?.request({ | ||
method: "wallet_invokeSnap", | ||
params: { | ||
snapId: defaultSnapOrigin, | ||
request: { | ||
method: "pushproto_disablesnooze", | ||
}, | ||
}, | ||
}) | ||
); | ||
}; | ||
|
||
return ( | ||
<button | ||
onClick={disableSnooze} | ||
className="flex bg-white text-black font-bold text-sm p-2 rounded-lg border-2 border-text-secondary ring-1 ring-white" | ||
> | ||
Disable Snooze | ||
</button> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
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,46 @@ | ||
import React, { useState } from 'react'; | ||
|
||
export default function SnoozeButton() { | ||
const defaultSnapOrigin = `local:http://localhost:8080`; | ||
const [snoozeDuration, setSnoozeDuration] = useState(''); | ||
|
||
const Snooze = async () => { | ||
// Check if snoozeDuration is within the range of 1 to 72 | ||
const duration = parseInt(snoozeDuration); | ||
if (duration >= 1 && duration <= 72) { | ||
console.log(await window.ethereum?.request({ | ||
method: "wallet_invokeSnap", | ||
params: { | ||
snapId: defaultSnapOrigin, | ||
request: { | ||
method: 'pushproto_setsnoozeduration', | ||
params: { snoozeDuration: snoozeDuration } | ||
}, | ||
}, | ||
})); | ||
} else { | ||
// Display an error message if the input is invalid | ||
console.error('Invalid input. Please enter a number between 1 and 72.'); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className='flex'> | ||
<input | ||
type="number" | ||
min="1" | ||
max="72" | ||
value={snoozeDuration} | ||
onChange={(e) => setSnoozeDuration(e.target.value)} | ||
className="mr-2 p-2 border border-gray-300 rounded-lg grow" | ||
placeholder="Enter duration (1-72)" | ||
/> | ||
<button | ||
onClick={Snooze} | ||
className="flex bg-white text-black font-bold text-sm p-2 rounded-lg border-2 border-text-secondary ring-1 ring-white" | ||
> | ||
Snooze | ||
</button> | ||
</div> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
import SendMessageButton from "../buttons/SendMessageButton" | ||
import DisableSnoozeButton from "../buttons/DisableSnoozeButton" | ||
import SendMessageButton from "../buttons/SnoozeButton" | ||
import { NOTIFICATION_TESTS } from "@/utils/constants" | ||
|
||
export default function NotificationTests() { | ||
return ( | ||
<div className="dark:bg-bg-secondary rounded-[20px] border-2 dark:border-white/30 w-[275px] h-[226px] p-6"> | ||
<div className="dark:bg-bg-secondary rounded-[20px] border-2 dark:border-white/30 w-[350px] h-auto p-6"> | ||
<h2 className="text-xl font-semibold"> | ||
{NOTIFICATION_TESTS.HEAD_1} | ||
</h2> | ||
<p className="text-sm pt-5 pb-7"> | ||
<p className="text-sm pt-5 pb-2"> | ||
{NOTIFICATION_TESTS.PARA_1} | ||
</p> | ||
<SendMessageButton/> | ||
<p className="text-sm pt-5 pb-2"> | ||
{NOTIFICATION_TESTS.PARA_2} | ||
</p> | ||
<DisableSnoozeButton /> | ||
</div> | ||
) | ||
} | ||
|
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { LatestSnapState } from "../../types"; | ||
import { getPopupsCountSinceTimestamp, updateSnapState } from "../../utils"; | ||
|
||
/** | ||
* Performs garbage collection on the snapshot state by removing popups older than two hours. | ||
* @param state - The latest snapshot state. | ||
* @returns A promise that resolves when the garbage collection is complete. | ||
*/ | ||
export const garbageCollectCronJob = async ( | ||
state: LatestSnapState | ||
): Promise<void> => { | ||
try { | ||
const updatedState = { ...state }; | ||
if (updatedState.popupsTimestamp.length === 0) return; | ||
|
||
// need to remove all popupsTimestamp storage that came two hours ago | ||
const lastTwoHourTimestamp = Date.now() - 2 * 60 * 60 * 1000; // Timestamp of two hours ago | ||
const popupsCountSinceLastTwoHours = getPopupsCountSinceTimestamp( | ||
updatedState, | ||
lastTwoHourTimestamp | ||
); // Get the number of popups shown since two hours ago | ||
|
||
// Calculate the number of popups to remove | ||
const popupsToRemove = Math.max( | ||
0, | ||
updatedState.popupsTimestamp.length - popupsCountSinceLastTwoHours | ||
); | ||
|
||
// Remove the extra popups from the beginning of the array | ||
updatedState.popupsTimestamp.splice(0, popupsToRemove); | ||
|
||
// update the state | ||
await updateSnapState({ | ||
newState: updatedState, | ||
encrypted: false, | ||
}); | ||
} catch (error) { | ||
// Handle or log the error as needed | ||
console.error("Error in garbageCollectCronJob:", error); | ||
// Optionally rethrow the error if you want it to propagate further | ||
throw error; | ||
} | ||
}; |
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,4 @@ | ||
export * from "./notifCronJob"; | ||
// export * from "./checkActivityCronJob"; | ||
// export * from "./removeSnoozeCronJob"; | ||
export * from "./garbageCollectCronJob"; |
Oops, something went wrong.