Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(widget): maintenance #2616

Merged
merged 28 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7a1bb74
Fetch pause data and store JSON object in client browser
bigboydiamonds May 11, 2024
6f553fc
Refetch only if last fetch was more than 24 hours ago
bigboydiamonds May 11, 2024
f005f88
Read chain + module pause from local storage
bigboydiamonds May 15, 2024
d544214
Maintenance components rendering based off of fetched pause data
bigboydiamonds May 15, 2024
2a76885
Pause Bridge button based on Maintenance status
bigboydiamonds May 15, 2024
876c97c
Filter quotes based on paused modules
bigboydiamonds May 15, 2024
02f2ed9
Use user defined styling or defaults
bigboydiamonds May 15, 2024
64b086d
Style Progress Bar
bigboydiamonds May 15, 2024
f0d87d1
Refactor getSynapsePauseData
bigboydiamonds May 15, 2024
6c10f92
Clean
bigboydiamonds May 15, 2024
d85b82b
Fix bridge quote filter
bigboydiamonds May 15, 2024
f2700ff
Adjust text size for maintenance
bigboydiamonds May 15, 2024
b0eaafe
Add comments + clean
bigboydiamonds May 16, 2024
8a6c737
Update comment
bigboydiamonds May 16, 2024
d658ebd
Refresh data every hour
bigboydiamonds May 16, 2024
7ce4e22
Clean
bigboydiamonds May 16, 2024
816dde2
Add key to warning messages
bigboydiamonds May 16, 2024
81a66fe
Fix render issues, start move event countdown component directly to W…
bigboydiamonds May 16, 2024
dcc1b0f
Resolve hooks render issue with localized component
bigboydiamonds May 16, 2024
b5048c1
Progress bar renders when not isabled
bigboydiamonds May 16, 2024
c7e790b
Clean and simplify Maintenance components
bigboydiamonds May 16, 2024
0a297b4
getMaintenanceData
bigboydiamonds May 16, 2024
c1b1754
Organize back into useMaintenance hook
bigboydiamonds May 16, 2024
5369601
Clean / organize
bigboydiamonds May 16, 2024
97021c1
Use prod urls
bigboydiamonds May 16, 2024
a3e4bcb
Organizational updates
abtestingalpha May 17, 2024
fc8c79c
Fetch pause data every render, set fetching status flag
bigboydiamonds May 17, 2024
f785d10
Rm timestamp key
bigboydiamonds May 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/widget/src/components/BridgeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface BridgeButtonProps {
handleBridge: () => any
isApprovalPending: boolean
isBridgePending: boolean
isBridgePaused: boolean
bigboydiamonds marked this conversation as resolved.
Show resolved Hide resolved
}

export const BridgeButton = ({
Expand All @@ -23,6 +24,7 @@ export const BridgeButton = ({
handleBridge,
isApprovalPending,
isBridgePending,
isBridgePaused,
}: BridgeButtonProps) => {
const web3Context = useContext(Web3Context)

Expand Down Expand Up @@ -52,6 +54,14 @@ export const BridgeButton = ({

const tooltipPositionStyle = '-top-8'

if (isBridgePaused) {
return (
<button className={buttonClassName} style={buttonStyle} disabled>
Bridge paused
</button>
)
}

if (!provider || !connectedAddress) {
return (
<Tooltip hoverText="Connect Wallet" positionStyles={tooltipPositionStyle}>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
import { isNull } from 'lodash'
bigboydiamonds marked this conversation as resolved.
Show resolved Hide resolved

import { LinearAnimatedProgressBar } from './LinearAnimatedProgressBar'
import { useIntervalTimer } from '@/hooks/useIntervalTimer'

/**
* Hook to construct an Animated Progress Bar that displays
* the remaining time left based on given start / end time.
* Hook also provides status updates on whether Event is pending or complete.
* If end date is null, progress bar will display an indefinite status.
*
* @param eventLabel Message to display with animated progress bar
* @param startDate Start time of event to track
* @param endDate End time of event to track
*/
export const useEventCountdownProgressBar = (
eventLabel: string,
startDate: Date,
endDate: Date | null
): {
isPending: boolean
isComplete: boolean
EventCountdownProgressBar: JSX.Element
} => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useEventCountdownProgressBar hook is well-structured, but consider adding JSDoc comments to describe the hook and its parameters. This will improve code readability and maintainability.

+/**
+ * Hook to construct an Animated Progress Bar that displays
+ * the remaining time left based on given start / end time.
+ * Hook also provides status updates on whether Event is pending or complete.
+ * If end date is null, progress bar will display an indefinite status.
+ *
+ * @param eventLabel Message to display with animated progress bar
+ * @param startDate Start time of event to track
+ * @param endDate End time of event to track
+ * @returns An object containing the event status and the progress bar component.
+ */
export const useEventCountdownProgressBar = (
  eventLabel: string,
  startDate: Date,
  endDate: Date | null
): {
  isPending: boolean
  isComplete: boolean
  EventCountdownProgressBar: JSX.Element
} => {
  let status: 'idle' | 'pending' | 'complete'

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
export const useEventCountdownProgressBar = (
eventLabel: string,
startDate: Date,
endDate: Date | null
): {
isPending: boolean
isComplete: boolean
EventCountdownProgressBar: JSX.Element
} => {
/**
* Hook to construct an Animated Progress Bar that displays
* the remaining time left based on given start / end time.
* Hook also provides status updates on whether Event is pending or complete.
* If end date is null, progress bar will display an indefinite status.
*
* @param eventLabel Message to display with animated progress bar
* @param startDate Start time of event to track
* @param endDate End time of event to track
* @returns An object containing the event status and the progress bar component.
*/
export const useEventCountdownProgressBar = (
eventLabel: string,
startDate: Date,
endDate: Date | null
): {
isPending: boolean
isComplete: boolean
EventCountdownProgressBar: JSX.Element
} => {

let status: 'idle' | 'pending' | 'complete'

const { totalTimeRemainingInMinutes, hoursRemaining, isComplete, isPending } =
getCountdownTimeStatus(startDate, endDate)

useIntervalTimer(60000, isComplete)

const timeRemaining: string =
totalTimeRemainingInMinutes > 90
? `${hoursRemaining}h`
: `${totalTimeRemainingInMinutes}m`

if (isComplete) {
status = 'complete'
} else if (isPending) {
status = 'pending'
} else {
status = 'idle'
}

return {
isPending,
isComplete,
EventCountdownProgressBar: (
<EventCountdownProgressBar
eventLabel={eventLabel}
startDate={startDate}
endDate={endDate}
timeRemaining={timeRemaining}
status={status}
/>
),
}
}

export const EventCountdownProgressBar = ({
eventLabel,
startDate,
endDate,
timeRemaining,
status,
}: {
eventLabel: string
startDate: Date
endDate: Date | null
timeRemaining: string
status: 'idle' | 'pending' | 'complete'
}) => {
const isIndefinite = isNull(endDate)

if (status === 'pending') {
return (
<div
className={`
flex flex-col bg-[--synapse-surface]
border border-[--synapse-border] rounded-md
text-[--synapse-text] text-xs md:text-base
`}
>
<div className="flex justify-between px-3 py-2">
<div className="text-sm">{eventLabel}</div>
{isIndefinite ? null : <div>{timeRemaining} remaining</div>}
</div>
<div className="flex px-1">
<LinearAnimatedProgressBar
id="event-countdown-progress-bar"
startDate={startDate}
endDate={endDate}
/>
</div>
</div>
)
} else {
return null
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EventCountdownProgressBar component is well-structured, but consider adding JSDoc comments to describe the component and its props. This will improve code readability and maintainability.

+/**
+ * Component to display an animated progress bar for event countdown.
+ * @param eventLabel - The label for the event.
+ * @param startDate - The start date of the event.
+ * @param endDate - The end date of the event.
+ * @param timeRemaining - The remaining time for the event.
+ * @param status - The status of the event ('idle', 'pending', 'complete').
+ * @returns A JSX element representing the progress bar.
+ */
export const EventCountdownProgressBar = ({
  eventLabel,
  startDate,
  endDate,
  timeRemaining,
  status,
}: {
  eventLabel: string
  startDate: Date
  endDate: Date | null
  timeRemaining: string
  status: 'idle' | 'pending' | 'complete'
}) => {
  const isIndefinite = isNull(endDate)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
export const EventCountdownProgressBar = ({
eventLabel,
startDate,
endDate,
timeRemaining,
status,
}: {
eventLabel: string
startDate: Date
endDate: Date | null
timeRemaining: string
status: 'idle' | 'pending' | 'complete'
}) => {
const isIndefinite = isNull(endDate)
if (status === 'pending') {
return (
<div
className={`
flex flex-col bg-[--synapse-surface]
border border-[--synapse-border] rounded-md
text-[--synapse-text] text-xs md:text-base
`}
>
<div className="flex justify-between px-3 py-2">
<div className="text-sm">{eventLabel}</div>
{isIndefinite ? null : <div>{timeRemaining} remaining</div>}
</div>
<div className="flex px-1">
<LinearAnimatedProgressBar
id="event-countdown-progress-bar"
startDate={startDate}
endDate={endDate}
/>
</div>
</div>
)
} else {
return null
}
}
/**
* Component to display an animated progress bar for event countdown.
* @param eventLabel - The label for the event.
* @param startDate - The start date of the event.
* @param endDate - The end date of the event.
* @param timeRemaining - The remaining time for the event.
* @param status - The status of the event ('idle', 'pending', 'complete').
* @returns A JSX element representing the progress bar.
*/
export const EventCountdownProgressBar = ({
eventLabel,
startDate,
endDate,
timeRemaining,
status,
}: {
eventLabel: string
startDate: Date
endDate: Date | null
timeRemaining: string
status: 'idle' | 'pending' | 'complete'
}) => {
const isIndefinite = isNull(endDate)
if (status === 'pending') {
return (
<div
className={`
flex flex-col bg-[--synapse-surface]
border border-[--synapse-border] rounded-md
text-[--synapse-text] text-xs md:text-base
`}
>
<div className="flex justify-between px-3 py-2">
<div className="text-sm">{eventLabel}</div>
{isIndefinite ? null : <div>{timeRemaining} remaining</div>}
</div>
<div className="flex px-1">
<LinearAnimatedProgressBar
id="event-countdown-progress-bar"
startDate={startDate}
endDate={endDate}
/>
</div>
</div>
)
} else {
return null
}
}


export const getCountdownTimeStatus = (
startDate: Date,
endDate: Date | null
) => {
const currentDate = new Date()

const currentTimeInSeconds = Math.floor(currentDate.getTime() / 1000)
const startTimeInSeconds = Math.floor(startDate.getTime() / 1000)

const isStarted = currentTimeInSeconds >= startTimeInSeconds
const isIndefinite = isNull(endDate)

if (isIndefinite) {
return {
currentDate,
currentTimeInSeconds,
startTimeInSeconds,
endTimeInSeconds: null,
totalTimeInSeconds: null,
totalTimeElapsedInSeconds: null,
totalTimeRemainingInSeconds: null,
totalTimeRemainingInMinutes: null,
daysRemaining: null,
hoursRemaining: null,
minutesRemaining: null,
secondsRemaining: null,
isStarted,
isComplete: false,
isPending: isStarted,
}
}

const { daysRemaining, hoursRemaining, minutesRemaining, secondsRemaining } =
calculateTimeUntilTarget(endDate)

const endTimeInSeconds = Math.floor(endDate.getTime() / 1000)
const totalTimeInSeconds = endTimeInSeconds - startTimeInSeconds

const totalTimeElapsedInSeconds = currentTimeInSeconds - startTimeInSeconds
const totalTimeRemainingInSeconds = endTimeInSeconds - currentTimeInSeconds
const totalTimeRemainingInMinutes = Math.ceil(
totalTimeRemainingInSeconds / 60
)

const isComplete = totalTimeRemainingInSeconds <= 0
const isPending = isStarted && !isComplete

return {
currentDate,
currentTimeInSeconds,
startTimeInSeconds,
endTimeInSeconds,
totalTimeInSeconds,
totalTimeElapsedInSeconds,
totalTimeRemainingInSeconds,
totalTimeRemainingInMinutes,
daysRemaining,
hoursRemaining,
minutesRemaining,
secondsRemaining,
isStarted,
isComplete,
isPending,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getCountdownTimeStatus function is well-structured, but consider adding JSDoc comments to describe the function and its parameters. This will improve code readability and maintainability.

+/**
+ * Calculates the status and remaining time for an event countdown.
+ * @param startDate - The start date of the event.
+ * @param endDate - The end date of the event.
+ * @returns An object containing the current date, time status, and event status.
+ */
export const getCountdownTimeStatus = (
  startDate: Date,
  endDate: Date | null
) => {
  const currentDate = new Date()

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
export const getCountdownTimeStatus = (
startDate: Date,
endDate: Date | null
) => {
const currentDate = new Date()
const currentTimeInSeconds = Math.floor(currentDate.getTime() / 1000)
const startTimeInSeconds = Math.floor(startDate.getTime() / 1000)
const isStarted = currentTimeInSeconds >= startTimeInSeconds
const isIndefinite = isNull(endDate)
if (isIndefinite) {
return {
currentDate,
currentTimeInSeconds,
startTimeInSeconds,
endTimeInSeconds: null,
totalTimeInSeconds: null,
totalTimeElapsedInSeconds: null,
totalTimeRemainingInSeconds: null,
totalTimeRemainingInMinutes: null,
daysRemaining: null,
hoursRemaining: null,
minutesRemaining: null,
secondsRemaining: null,
isStarted,
isComplete: false,
isPending: isStarted,
}
}
const { daysRemaining, hoursRemaining, minutesRemaining, secondsRemaining } =
calculateTimeUntilTarget(endDate)
const endTimeInSeconds = Math.floor(endDate.getTime() / 1000)
const totalTimeInSeconds = endTimeInSeconds - startTimeInSeconds
const totalTimeElapsedInSeconds = currentTimeInSeconds - startTimeInSeconds
const totalTimeRemainingInSeconds = endTimeInSeconds - currentTimeInSeconds
const totalTimeRemainingInMinutes = Math.ceil(
totalTimeRemainingInSeconds / 60
)
const isComplete = totalTimeRemainingInSeconds <= 0
const isPending = isStarted && !isComplete
return {
currentDate,
currentTimeInSeconds,
startTimeInSeconds,
endTimeInSeconds,
totalTimeInSeconds,
totalTimeElapsedInSeconds,
totalTimeRemainingInSeconds,
totalTimeRemainingInMinutes,
daysRemaining,
hoursRemaining,
minutesRemaining,
secondsRemaining,
isStarted,
isComplete,
isPending,
}
}
/**
* Calculates the status and remaining time for an event countdown.
* @param startDate - The start date of the event.
* @param endDate - The end date of the event.
* @returns An object containing the current date, time status, and event status.
*/
export const getCountdownTimeStatus = (
startDate: Date,
endDate: Date | null
) => {
const currentDate = new Date()


const calculateTimeUntilTarget = (targetDate: Date) => {
const currentDate = new Date()

const timeDifference = targetDate.getTime() - currentDate.getTime()

const isComplete = timeDifference <= 0

const daysRemaining = Math.floor(timeDifference / (1000 * 60 * 60 * 24))
const hoursRemaining = Math.ceil(
(timeDifference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)
)
const minutesRemaining = Math.floor(
(timeDifference % (1000 * 60 * 60)) / (1000 * 60)
)
const secondsRemaining = Math.floor((timeDifference % (1000 * 60)) / 1000)

return {
daysRemaining,
hoursRemaining,
minutesRemaining,
secondsRemaining,
isComplete,
}
}
bigboydiamonds marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading