-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
2,136 additions
and
1,856 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
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'; | ||
|
||
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.