Skip to content

Commit

Permalink
Resolve hooks render issue with localized component
Browse files Browse the repository at this point in the history
  • Loading branch information
bigboydiamonds committed May 16, 2024
1 parent 81a66fe commit dcc1b0f
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 27 deletions.
Empty file.
44 changes: 22 additions & 22 deletions packages/widget/src/components/Maintenance/Maintenance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ interface ChainPause {
pausedToChains: number[]
pauseBridge: boolean
startTimePauseChain: Date
endTimePauseChain: Date | null // If null, pause chain indefinitely
inputWarningMessage: JSX.Element
progressBarMessage: JSX.Element
endTimePauseChain: Date | null
inputWarningMessage: string
progressBarMessage: string
disableWarning: boolean
disableCountdown: boolean
}

interface BridgeModulePause {
chainId?: number // If undefined, pause module for all chains
chainId: number | undefined
bridgeModuleName: 'SynapseBridge' | 'SynapseRFQ' | 'SynapseCCTP' | 'ALL'
}

Expand All @@ -33,8 +33,8 @@ export const useMaintenanceComponents = (
endTimePauseChain: pause.endTimePauseChain
? new Date(pause.endTimePauseChain)
: null,
inputWarningMessage: <div>{pause.inputWarningMessage}</div>,
progressBarMessage: <div>{pause.progressBarMessage}</div>,
inputWarningMessage: pause.inputWarningMessage,
progressBarMessage: pause.progressBarMessage,
}
})
: []
Expand Down Expand Up @@ -80,27 +80,27 @@ export const useMaintenanceComponents = (
)
}

const useMaintenanceCountdownProgresses = () => {
const { originChainId, destinationChainId } = useBridgeState()
// const useMaintenanceCountdownProgresses = () => {
// const { originChainId, destinationChainId } = useBridgeState()

return pausedChainsList?.map((event) => {
return useMaintenanceCountdownProgress({
originChainId,
destinationChainId,
startDate: event.startTimePauseChain,
endDate: event.endTimePauseChain,
pausedFromChains: event.pausedFromChains,
pausedToChains: event.pausedToChains,
progressBarMessage: event.progressBarMessage,
disabled: event.disableCountdown,
})
})
}
// return pausedChainsList?.map((event) => {
// return useMaintenanceCountdownProgress({
// originChainId,
// destinationChainId,
// startDate: event.startTimePauseChain,
// endDate: event.endTimePauseChain,
// pausedFromChains: event.pausedFromChains,
// pausedToChains: event.pausedToChains,
// progressBarMessage: event.progressBarMessage,
// disabled: event.disableCountdown,
// })
// })
// }

return {
pausedChains: pausedChainsList,
pausedModules: pausedModulesList,
MaintenanceWarningMessages,
useMaintenanceCountdownProgresses,
// useMaintenanceCountdownProgresses,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useEventCountdownProgressBar } from './hooks/useEventCountdownProgressBar'
import { isChainIncluded } from '@/utils/isChainIncluded'

export const MaintenanceCountdownProgress = ({
originChainId,
destinationChainId,
startDate,
endDate,
pausedFromChains,
pausedToChains,
progressBarMessage,
disabled = false,
}: {
originChainId: number
destinationChainId: number
startDate: Date
endDate: Date | null
pausedFromChains: number[]
pausedToChains: number[]
progressBarMessage: any
disabled?: boolean
}) => {
const isCurrentChain =
isChainIncluded([originChainId], pausedFromChains) ||
isChainIncluded([destinationChainId], pausedToChains)

const {
isPending: isMaintenancePending,
EventCountdownProgressBar: MaintenanceCountdownProgressBar,
} = useEventCountdownProgressBar(progressBarMessage, startDate, endDate)

return MaintenanceCountdownProgressBar
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
import { isNull } from 'lodash'

export const getCountdownTimeStatus = (
startDate: Date,
startDate: Date | null,
endDate: Date | null
) => {
if (!startDate && !endDate) {
return {
currentDate: null,
currentTimeInSeconds: null,
startTimeInSeconds: null,
endTimeInSeconds: null,
totalTimeInSeconds: null,
totalTimeElapsedInSeconds: null,
totalTimeRemainingInSeconds: null,
totalTimeRemainingInMinutes: null,
daysRemaining: null,
hoursRemaining: null,
minutesRemaining: null,
secondsRemaining: null,
isStarted: false,
isComplete: false,
isPending: false,
}
}

const currentDate = new Date()

const currentTimeInSeconds = Math.floor(currentDate.getTime() / 1000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const useEventCountdownProgressBar = (
const { totalTimeRemainingInMinutes, hoursRemaining, isComplete, isPending } =
getCountdownTimeStatus(startDate, endDate)

useIntervalTimer(60000, isComplete)
useIntervalTimer(60000, isComplete || !startDate)

const timeRemaining: string =
totalTimeRemainingInMinutes > 90
Expand Down
27 changes: 24 additions & 3 deletions packages/widget/src/components/Widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ import { findTokenByRouteSymbol } from '@/utils/findTokenByRouteSymbol'
import { useMaintenanceComponents } from './Maintenance/Maintenance'
import { getSynapsePauseData } from '@/utils/getSynapsePauseData'
import { isChainIncluded } from '@/utils/isChainIncluded'
import { MaintenanceCountdownProgress } from './Maintenance/MaintenanceCountdownProgress'
import { useEventCountdownProgressBar } from '@/components/Maintenance/hooks/useEventCountdownProgressBar'

interface WidgetProps {
customTheme: CustomThemeVariables
Expand Down Expand Up @@ -103,7 +105,7 @@ export const Widget = ({
pausedChains,
pausedModules,
MaintenanceWarningMessages,
useMaintenanceCountdownProgresses,
// useMaintenanceCountdownProgresses,
} = useMaintenanceComponents(chainPause, modulePause)

const currentChainPause = pausedChains.find((pauseData) => {
Expand All @@ -113,6 +115,15 @@ export const Widget = ({
)
})

const {
isPending: isBridgeDisabled,
EventCountdownProgressBar: MaintenanceCountdownProgressBar,
} = useEventCountdownProgressBar(
currentChainPause?.progressBarMessage,
currentChainPause?.startTimePauseChain,
currentChainPause?.endTimePauseChain
)

console.log('currentChainPause: ', currentChainPause)

// const maintenanceCountdownProgressInstances =
Expand Down Expand Up @@ -416,6 +427,16 @@ export const Widget = ({
{/* {maintenanceCountdownProgressInstances?.map((instance) => (
<>{instance.MaintenanceCountdownProgressBar}</>
))} */}
<MaintenanceCountdownProgress
originChainId={originChainId}
destinationChainId={destinationChainId}
startDate={currentChainPause?.startTimePauseChain}
endDate={currentChainPause?.endTimePauseChain}
pausedFromChains={currentChainPause?.pausedFromChains}
pausedToChains={currentChainPause?.pausedToChains}
progressBarMessage={currentChainPause?.progressBarMessage}
disabled={currentChainPause?.disableCountdown}
/>
<Transactions connectedAddress={connectedAddress} />
<section
className={cardStyle}
Expand Down Expand Up @@ -499,8 +520,8 @@ export const Widget = ({
approveTxnStatus === ApproveTransactionStatus.PENDING
}
isBridgePending={bridgeTxnStatus === BridgeTransactionStatus.PENDING}
// isBridgePaused={isBridgePaused}
isBridgePaused={false}
isBridgePaused={isBridgeDisabled}
// isBridgePaused={false}
/>
</div>
</div>
Expand Down

0 comments on commit dcc1b0f

Please sign in to comment.