-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from dmccartney/daniel-ongoing
feat: display ongoing rewards from s3
- Loading branch information
Showing
6 changed files
with
176 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { useAccount, useDisconnect } from "wagmi"; | ||
import { useThemeMode } from "../theme"; | ||
import useSetting from "../hooks/useSetting"; | ||
import { useRef } from "react"; | ||
import { | ||
Button, | ||
ButtonGroup, | ||
Grid, | ||
List, | ||
ListItem, | ||
ListItemText, | ||
Stack, | ||
TextField, | ||
Tooltip, | ||
} from "@mui/material"; | ||
|
||
export default function SettingsList() { | ||
let { isConnected } = useAccount(); | ||
let { disconnectAsync } = useDisconnect(); | ||
let { mode, setMode } = useThemeMode(); | ||
let [ipfsBase, setIpfsBase, defaultIpfsBase] = useSetting("ipfs.base"); | ||
let [rewardsOngoingBase] = useSetting("rewards.ongoing.base"); | ||
let ipfsRef = useRef(); | ||
return ( | ||
<List> | ||
{isConnected && ( | ||
<ListItem> | ||
<ListItemText primary="Wallet" /> | ||
<Button | ||
size="small" | ||
onClick={() => | ||
disconnectAsync().catch((e) => | ||
console.log("failure disconnecting", e) | ||
) | ||
} | ||
> | ||
Disconnect | ||
</Button> | ||
</ListItem> | ||
)} | ||
<ListItem> | ||
<ListItemText primary="Theme" /> | ||
<ButtonGroup> | ||
{["auto", "light", "dark"].map((m) => ( | ||
<Button | ||
key={`mode-${m}`} | ||
variant={mode === m ? "contained" : "outlined"} | ||
size="small" | ||
onClick={() => setMode(m)} | ||
> | ||
{m} | ||
</Button> | ||
))} | ||
</ButtonGroup> | ||
</ListItem> | ||
<ListItem> | ||
<ListItemText primary="Ethereum RPC" /> | ||
<Tooltip arrow title="TODO: make Ethereum RPC configurable"> | ||
<Stack direction="column" alignItems="flex-end"> | ||
<ButtonGroup disabled size="small"> | ||
<Button variant="contained">Default</Button> | ||
<Button variant="outlined">Custom</Button> | ||
</ButtonGroup> | ||
</Stack> | ||
</Tooltip> | ||
</ListItem> | ||
<ListItem> | ||
<ListItemText primary="IPFS Gateway" /> | ||
<Stack direction="column" alignItems="flex-end"> | ||
<ButtonGroup size="small"> | ||
<Button | ||
onClick={() => setIpfsBase(defaultIpfsBase)} | ||
variant={ipfsBase === defaultIpfsBase ? "contained" : "outlined"} | ||
> | ||
default | ||
</Button> | ||
<Button | ||
onClick={() => { | ||
setIpfsBase(""); | ||
setTimeout(() => ipfsRef.current?.focus(), 50); | ||
}} | ||
variant={ipfsBase === defaultIpfsBase ? "outlined" : "contained"} | ||
> | ||
custom | ||
</Button> | ||
</ButtonGroup> | ||
</Stack> | ||
</ListItem> | ||
<Grid container sx={{ mb: 1, pr: 2 }}> | ||
<Grid item xs={4} /> | ||
<Grid item xs={8}> | ||
<TextField | ||
inputRef={ipfsRef} | ||
disabled={ipfsBase === defaultIpfsBase} | ||
fullWidth | ||
size="small" | ||
placeholder="https://..." | ||
onChange={(e) => setIpfsBase(e.target.value)} | ||
value={ipfsBase} | ||
/> | ||
</Grid> | ||
</Grid> | ||
<ListItem> | ||
<ListItemText primary="Ongoing Rewards" /> | ||
<Tooltip arrow title="TODO: make Ongoing Rewards configurable"> | ||
<Stack direction="column" alignItems="flex-end"> | ||
<ButtonGroup disabled size="small"> | ||
<Button variant="contained">Default</Button> | ||
<Button variant="outlined">Custom</Button> | ||
</ButtonGroup> | ||
</Stack> | ||
</Tooltip> | ||
</ListItem> | ||
<Grid container sx={{ mb: 1, pr: 2 }}> | ||
<Grid item xs={4} /> | ||
<Grid item xs={8}> | ||
<TextField | ||
disabled | ||
fullWidth | ||
size="small" | ||
value={rewardsOngoingBase} | ||
/> | ||
</Grid> | ||
</Grid> | ||
</List> | ||
); | ||
} |
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,6 +1,28 @@ | ||
import useSetting from "./useSetting"; | ||
import { useQuery } from "react-query"; | ||
|
||
const minuteMs = 1000 * 60; | ||
|
||
export default function useOngoingRewardSnapshot({ | ||
rewardIndex, | ||
network = "mainnet", | ||
}) { | ||
return null; // TODO: pull from s3 | ||
let [ongoingRewardsBaseUrl] = useSetting("rewards.ongoing.base"); | ||
let url = `${ongoingRewardsBaseUrl}/rp-rewards-${network}-${rewardIndex}.json`; | ||
let { data: result } = useQuery( | ||
["ongoingRewardSnapshot", url], | ||
async () => { | ||
let res = await fetch(url); | ||
if (!res.ok) { | ||
throw new Error(`failure fetching ongoing reward JSON from ${url}`); | ||
} | ||
return res.json(); | ||
}, | ||
{ | ||
enabled: !!ongoingRewardsBaseUrl && !!rewardIndex, | ||
cacheTime: 120 * minuteMs, | ||
staleTime: 60 * minuteMs, | ||
} | ||
); | ||
return result; | ||
} |
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