-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description Describe the changes or additions included in this PR. ## Test plan How did you test the new or updated feature? --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: - [ ] REST API:
- Loading branch information
1 parent
e0b51bc
commit 773fd58
Showing
2 changed files
with
90 additions
and
0 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,88 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useFeatureValue } from '@growthbook/growthbook-react'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { Text } from '../shared/text'; | ||
import Close from './buynlarge/close.svg'; | ||
|
||
const STAKE_SEEN_KEY = 'stake-warning-seen'; | ||
|
||
type StakeWarningItem = { | ||
enabled: boolean; | ||
link: string; | ||
text: string; | ||
endDate: string; | ||
}; | ||
|
||
export function StakeWarning() { | ||
const [today, setToday] = useState(new Date()); | ||
const [seen, setSeen] = useState<boolean>(() => { | ||
const stored = localStorage.getItem(STAKE_SEEN_KEY); | ||
if (stored) { | ||
return JSON.parse(stored); | ||
} | ||
return false; | ||
}); | ||
|
||
const warning = useFeatureValue<StakeWarningItem | null>('wallet-stake-warning', null); | ||
|
||
useEffect(() => { | ||
// We update every minute to make sure the warning is removed after the end date | ||
const interval = setInterval(() => { | ||
setToday(new Date()); | ||
}, 1000 * 60); | ||
|
||
return () => clearInterval(interval); | ||
}, []); | ||
|
||
if ( | ||
seen || | ||
!warning || | ||
!warning.enabled || | ||
today.getTime() > new Date(warning.endDate).getTime() | ||
) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<a | ||
target="_blank" | ||
rel="noreferrer" | ||
href={warning.link} | ||
className="flex flex-row items-center rounded-xl px-4 py-3 gap-4 w-full no-underline" | ||
style={{ | ||
backgroundColor: '#211C35', | ||
}} | ||
> | ||
<div className="flex-1"> | ||
<Text variant="body" weight="medium" color="white"> | ||
{warning.text.replace( | ||
'{endDate}', | ||
new Date(warning.endDate).toLocaleString(undefined, { | ||
dateStyle: 'full', | ||
timeStyle: 'short', | ||
}), | ||
)} | ||
</Text> | ||
</div> | ||
|
||
<div> | ||
<button | ||
type="button" | ||
aria-label="Close" | ||
className="bg-transparent p-0 m-0 border-none" | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
localStorage.setItem(STAKE_SEEN_KEY, JSON.stringify(true)); | ||
setSeen(true); | ||
}} | ||
> | ||
<Close className="text-content-onColor" width={16} height={16} /> | ||
</button> | ||
</div> | ||
</a> | ||
); | ||
} |
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