-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into devx/fix-ctf-css
- Loading branch information
Showing
111 changed files
with
1,362 additions
and
545 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
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './KioskClientProvider'; | ||
|
||
export * from './coin'; | ||
export * from './icon'; | ||
export * from './Inputs'; | ||
export * from './QR'; | ||
|
||
export * from './providers'; |
File renamed without changes.
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,51 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { PropsWithChildren, useState, useEffect, useCallback } from 'react'; | ||
import { Theme } from '../../enums'; | ||
import { ThemeContext } from '../../contexts'; | ||
|
||
interface ThemeProviderProps { | ||
appId: string; | ||
} | ||
|
||
export function ThemeProvider({ children, appId }: PropsWithChildren<ThemeProviderProps>) { | ||
const storageKey = `theme_${appId}`; | ||
|
||
const getSystemTheme = () => | ||
window.matchMedia('(prefers-color-scheme: dark)').matches ? Theme.Dark : Theme.Light; | ||
|
||
const getInitialTheme = () => { | ||
if (typeof window === 'undefined') { | ||
return Theme.System; | ||
} else { | ||
const storedTheme = localStorage?.getItem(storageKey); | ||
return storedTheme ? (storedTheme as Theme) : Theme.System; | ||
} | ||
}; | ||
|
||
const [theme, setTheme] = useState<Theme>(getInitialTheme); | ||
|
||
const applyTheme = useCallback((currentTheme: Theme) => { | ||
const selectedTheme = currentTheme === Theme.System ? getSystemTheme() : currentTheme; | ||
const documentElement = document.documentElement.classList; | ||
documentElement.toggle(Theme.Dark, selectedTheme === Theme.Dark); | ||
documentElement.toggle(Theme.Light, selectedTheme === Theme.Light); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (typeof window === 'undefined') return; | ||
|
||
localStorage.setItem(storageKey, theme); | ||
applyTheme(theme); | ||
|
||
if (theme === Theme.System) { | ||
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)'); | ||
const handleSystemThemeChange = () => applyTheme(Theme.System); | ||
systemTheme.addEventListener('change', handleSystemThemeChange); | ||
return () => systemTheme.removeEventListener('change', handleSystemThemeChange); | ||
} | ||
}, [theme, applyTheme, storageKey]); | ||
|
||
return <ThemeContext.Provider value={{ theme, setTheme }}>{children}</ThemeContext.Provider>; | ||
} |
3 changes: 2 additions & 1 deletion
3
.../components/Dialogs/StakeDetails/index.ts → apps/core/src/components/providers/index.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,4 +1,5 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './StakeDetailsDialog'; | ||
export * from './KioskClientProvider'; | ||
export * from './ThemeProvider'; |
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,15 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { createContext } from 'react'; | ||
import { Theme } from '../enums'; | ||
|
||
export interface ThemeContextType { | ||
theme: Theme; | ||
setTheme: (theme: Theme) => void; | ||
} | ||
|
||
export const ThemeContext = createContext<ThemeContextType>({ | ||
theme: Theme.Light, | ||
setTheme: () => {}, | ||
}); |
2 changes: 1 addition & 1 deletion
2
...board/components/Dialogs/Unstake/index.ts → apps/core/src/contexts/index.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,4 +1,4 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './views'; | ||
export * from './ThemeContext'; |
File renamed without changes.
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,4 +1,5 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './ExplorerLinkType'; | ||
export * from './theme.enums'; | ||
export * from './explorer-link-type.enums'; |
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,8 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export enum Theme { | ||
Light = 'light', | ||
Dark = 'dark', | ||
System = 'system', | ||
} |
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 |
---|---|---|
|
@@ -4,6 +4,5 @@ | |
export type TokenForm = { | ||
amount: string; | ||
to: string; | ||
isPayAllIota: boolean; | ||
gasBudgetEst: string; | ||
}; |
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,52 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { | ||
useGetTimeBeforeEpochNumber, | ||
useTimeAgo, | ||
TimeUnit, | ||
NUM_OF_EPOCH_BEFORE_STAKING_REWARDS_REDEEMABLE, | ||
NUM_OF_EPOCH_BEFORE_STAKING_REWARDS_STARTS, | ||
} from '../../'; | ||
|
||
export function useStakeTxnInfo(startEpoch?: string | number) { | ||
const startEarningRewardsEpoch = | ||
Number(startEpoch || 0) + NUM_OF_EPOCH_BEFORE_STAKING_REWARDS_STARTS; | ||
|
||
const redeemableRewardsEpoch = | ||
Number(startEpoch || 0) + NUM_OF_EPOCH_BEFORE_STAKING_REWARDS_REDEEMABLE; | ||
|
||
const { data: timeBeforeStakeRewardsStarts } = | ||
useGetTimeBeforeEpochNumber(startEarningRewardsEpoch); | ||
const timeBeforeStakeRewardsStartsAgo = useTimeAgo({ | ||
timeFrom: timeBeforeStakeRewardsStarts, | ||
shortedTimeLabel: false, | ||
shouldEnd: true, | ||
maxTimeUnit: TimeUnit.ONE_HOUR, | ||
}); | ||
const stakedRewardsStartEpoch = | ||
timeBeforeStakeRewardsStarts > 0 | ||
? `in ${timeBeforeStakeRewardsStartsAgo}` | ||
: startEpoch | ||
? `Epoch #${Number(startEarningRewardsEpoch)}` | ||
: '--'; | ||
|
||
const { data: timeBeforeStakeRewardsRedeemable } = | ||
useGetTimeBeforeEpochNumber(redeemableRewardsEpoch); | ||
const timeBeforeStakeRewardsRedeemableAgo = useTimeAgo({ | ||
timeFrom: timeBeforeStakeRewardsRedeemable, | ||
shortedTimeLabel: false, | ||
shouldEnd: true, | ||
maxTimeUnit: TimeUnit.ONE_HOUR, | ||
}); | ||
const timeBeforeStakeRewardsRedeemableAgoDisplay = | ||
timeBeforeStakeRewardsRedeemable > 0 | ||
? `in ${timeBeforeStakeRewardsRedeemableAgo}` | ||
: startEpoch | ||
? `Epoch #${Number(redeemableRewardsEpoch)}` | ||
: '--'; | ||
|
||
return { | ||
stakedRewardsStartEpoch, | ||
timeBeforeStakeRewardsRedeemableAgoDisplay, | ||
}; | ||
} |
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,50 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { useIotaClientQuery } from '@iota/dapp-kit'; | ||
import { useGetValidatorsApy } from '../'; | ||
|
||
export function useValidatorInfo({ validatorAddress }: { validatorAddress: string }) { | ||
const { | ||
data: system, | ||
isPending: isPendingValidators, | ||
isError: errorValidators, | ||
} = useIotaClientQuery('getLatestIotaSystemState'); | ||
const { data: rollingAverageApys } = useGetValidatorsApy(); | ||
|
||
const validatorSummary = | ||
system?.activeValidators.find((validator) => validator.iotaAddress === validatorAddress) || | ||
null; | ||
|
||
const currentEpoch = Number(system?.epoch || 0); | ||
|
||
const stakingPoolActivationEpoch = Number(validatorSummary?.stakingPoolActivationEpoch || 0); | ||
|
||
// flag as new validator if the validator was activated in the last epoch | ||
// for genesis validators, this will be false | ||
const newValidator = currentEpoch - stakingPoolActivationEpoch <= 1 && currentEpoch !== 0; | ||
|
||
// flag if the validator is at risk of being removed from the active set | ||
const isAtRisk = system?.atRiskValidators.some((item) => item[0] === validatorAddress); | ||
|
||
const { apy, isApyApproxZero } = rollingAverageApys?.[validatorAddress] ?? { | ||
apy: null, | ||
}; | ||
|
||
const commission = validatorSummary ? Number(validatorSummary.commissionRate) / 100 : 0; | ||
|
||
return { | ||
system, | ||
isPendingValidators, | ||
errorValidators, | ||
|
||
currentEpoch, | ||
validatorSummary, | ||
name: validatorSummary?.name || '', | ||
stakingPoolActivationEpoch, | ||
commission, | ||
newValidator, | ||
isAtRisk, | ||
apy, | ||
isApyApproxZero, | ||
}; | ||
} |
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,12 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { useContext } from 'react'; | ||
import { ThemeContext, ThemeContextType } from '../contexts'; | ||
|
||
export const useTheme = (): ThemeContextType => { | ||
const context = useContext(ThemeContext); | ||
if (!context) { | ||
throw new Error('useTheme must be used within a ThemeProvider'); | ||
} | ||
return context; | ||
}; |
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
Oops, something went wrong.