-
Notifications
You must be signed in to change notification settings - Fork 5
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
display network notices #94
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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
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,56 @@ | ||
import { FiX } from 'react-icons/fi'; | ||
import { GrAnnounce } from 'react-icons/gr'; | ||
import { motion, AnimatePresence } from 'framer-motion'; | ||
import { useState } from 'react'; | ||
import { activeNotices } from 'utils/networkConfig'; | ||
import { useAtomValue } from 'jotai'; | ||
import { networkConfigPAtom } from 'store/app'; | ||
import { loadable } from 'jotai/utils'; | ||
|
||
const NoticeBanner = () => { | ||
const [isDismissed, setIsDismissed] = useState(false); | ||
const config = useAtomValue(loadable(networkConfigPAtom)); | ||
const bannerContent = | ||
config.state === 'hasData' && activeNotices(config.data).join(' • '); | ||
const isVisible = | ||
!isDismissed && bannerContent && bannerContent.trim().length; | ||
|
||
return ( | ||
<AnimatePresence initial={false}> | ||
{isVisible && ( | ||
<motion.div | ||
initial="open" | ||
animate="open" | ||
exit="collapsed" | ||
variants={{ | ||
open: { height: 'auto' }, | ||
collapsed: { height: 0 }, | ||
}} | ||
className="bg-yellow-400 overflow-hidden" | ||
> | ||
<motion.div className="mx-auto max-w-7xl py-3 px-3 sm:px-6 lg:px-8"> | ||
<motion.div className="flex flex-wrap items-center justify-between"> | ||
<motion.div className="flex w-0 flex-1 items-center"> | ||
<span className="flex rounded-lgp-2"> | ||
<GrAnnounce className="h-6 w-6" aria-hidden="true" /> | ||
</span> | ||
<p className="ml-3 font-medium text-black">{bannerContent}</p> | ||
</motion.div> | ||
<motion.div className="order-2 flex-shrink-0 sm:order-3 sm:ml-3"> | ||
<button | ||
onClick={() => setIsDismissed(true)} | ||
type="button" | ||
className="-mr-1 flex rounded-md p-2 hover:bg-black hover:bg-opacity-10 focus:outline-none focus:ring-2 focus:ring-white sm:-mr-2" | ||
> | ||
<FiX className="h-6 w-6" /> | ||
</button> | ||
</motion.div> | ||
</motion.div> | ||
</motion.div> | ||
</motion.div> | ||
)} | ||
</AnimatePresence> | ||
); | ||
}; | ||
|
||
export default NoticeBanner; |
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,4 +1,34 @@ | ||
type MinimalNetworkConfig = { rpcAddrs: string[]; chainName: string }; | ||
type NetworkNotice = { | ||
start: string; | ||
// In the future this might be optional to indicate that it's user-dismissable. | ||
// In that case the client would need some persistent state, perhaps keyed by `message`. | ||
end: string; | ||
message: string; | ||
}; | ||
|
||
export type MinimalNetworkConfig = { | ||
rpcAddrs: string[]; | ||
chainName: string; | ||
notices?: NetworkNotice[]; | ||
}; | ||
|
||
export const loadNetworkConfig = (url: string): Promise<MinimalNetworkConfig> => | ||
fetch(url).then(res => res.json()); | ||
|
||
export const activeNotices = ( | ||
config: Pick<MinimalNetworkConfig, 'notices'> | ||
) => { | ||
const { notices } = config; | ||
if (!notices) return []; | ||
|
||
const now = Date.now(); | ||
const active = notices.filter(n => { | ||
const startD = Date.parse(n.start); | ||
if (startD > now) { | ||
return false; | ||
} | ||
const endD = Date.parse(n.end); | ||
return startD < endD; | ||
}); | ||
return active.map(n => n.message); | ||
}; |
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,40 @@ | ||
import { expect, it, describe } from 'vitest'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yay tests |
||
|
||
import { activeNotices } from '../../src/utils/networkConfig'; | ||
|
||
describe('activeNotices', () => { | ||
it('handles empty', () => { | ||
const notices = []; | ||
expect(activeNotices({ notices })).toEqual([]); | ||
}); | ||
it('handles future', () => { | ||
const notices = [ | ||
{ | ||
start: '2030-01-01', | ||
end: '2040-01-01', | ||
message: 'hello from the future', | ||
}, | ||
]; | ||
expect(activeNotices({ notices })).toEqual([]); | ||
}); | ||
it('handles past', () => { | ||
const notices = [ | ||
{ | ||
start: '2000-01-01', | ||
end: '2000-01-01', | ||
message: 'hello from the past', | ||
}, | ||
]; | ||
expect(activeNotices({ notices })).toEqual([]); | ||
}); | ||
it('handles started', () => { | ||
const notices = [ | ||
{ | ||
start: '2020-01-01', | ||
end: '2040-01-01', | ||
message: 'hello now', | ||
}, | ||
]; | ||
expect(activeNotices({ notices })).toEqual(['hello now']); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to have separate notices for PSM and Vaults?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we do I think that has to go somewhere else. this is config for the network. appropriate for things like pending upgrades.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense