-
Notifications
You must be signed in to change notification settings - Fork 128
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
sim
committed
Dec 30, 2021
1 parent
7bde688
commit ce8ebaf
Showing
14 changed files
with
127 additions
and
33 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,11 @@ | ||
import { fromPairs } from "ramda" | ||
import { WalletControllerChainOptions } from "@terra-money/wallet-provider" | ||
import createContext from "utils/createContext" | ||
|
||
export const [useNetworks, NetworksProvider] = | ||
createContext<TerraNetworks>("useNetworks") | ||
|
||
export const convert = (options: WalletControllerChainOptions) => { | ||
const { walletConnectChainIds: ids } = options | ||
return fromPairs(Object.values(ids).map((item) => [item.name, item])) | ||
} |
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,31 @@ | ||
import SettingsIcon from "@mui/icons-material/Settings" | ||
import { RadioGroup } from "components/form" | ||
import { Popover } from "components/display" | ||
import HeaderIconButton from "../components/HeaderIconButton" | ||
import { useNetworkOptions, useNetworkState } from "data/wallet" | ||
|
||
const SelectNetwork = () => { | ||
const [network, setNetwork] = useNetworkState() | ||
const networkOptions = useNetworkOptions() | ||
|
||
if (!networkOptions) return null | ||
|
||
return ( | ||
<Popover | ||
content={ | ||
<RadioGroup | ||
options={networkOptions} | ||
value={network} | ||
onChange={setNetwork} | ||
/> | ||
} | ||
placement="bottom" | ||
> | ||
<HeaderIconButton> | ||
<SettingsIcon style={{ fontSize: 18 }} /> | ||
</HeaderIconButton> | ||
</Popover> | ||
) | ||
} | ||
|
||
export default SelectNetwork |
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,49 @@ | ||
import { atom, useRecoilState, useRecoilValue } from "recoil" | ||
import { useWallet } from "@terra-money/wallet-provider" | ||
import { useNetworks } from "app/NetworksProvider" | ||
import { electron } from "../scripts/env" | ||
import { getStoredNetwork, storeNetwork } from "../scripts/network" | ||
|
||
const networkState = atom({ | ||
key: "network", | ||
default: getStoredNetwork(), | ||
}) | ||
|
||
export const useNetworkState = () => { | ||
const [network, setNetwork] = useRecoilState(networkState) | ||
|
||
const changeNetwork = (network: NetworkName) => { | ||
setNetwork(network) | ||
storeNetwork(network) | ||
} | ||
|
||
return [network, changeNetwork] as const | ||
} | ||
|
||
/* helpers */ | ||
export const useNetworkOptions = () => { | ||
const networks = useNetworks() | ||
|
||
if (!electron) return | ||
|
||
return Object.values(networks).map(({ name }) => { | ||
return { value: name, label: name } | ||
}) | ||
} | ||
|
||
export const useNetwork = () => { | ||
const networks = useNetworks() | ||
const network = useRecoilValue(networkState) | ||
const wallet = useWallet() | ||
return electron ? networks[network] : wallet.network | ||
} | ||
|
||
export const useNetworkName = () => { | ||
const { name } = useNetwork() | ||
return name | ||
} | ||
|
||
export const useChainID = () => { | ||
const { chainID } = useNetwork() | ||
return chainID | ||
} |
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,3 +1 @@ | ||
export { default as useAuth } from "./hooks/useAuth" | ||
export { default as useAddress } from "./hooks/useAddress" | ||
export * from "./hooks/useAddress" |
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,7 @@ | ||
export const getStoredNetwork = () => { | ||
return localStorage.getItem("network") ?? "mainnet" | ||
} | ||
|
||
export const storeNetwork = (network: NetworkName) => { | ||
localStorage.setItem("network", network) | ||
} |
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 |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
.list { | ||
max-height: 360px; | ||
overflow-y: auto; | ||
padding-top: 12px; | ||
} | ||
|
||
.item { | ||
|
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,17 +1,2 @@ | ||
import { useWallet } from "@terra-money/wallet-provider" | ||
export { useAddress } from "auth" | ||
|
||
export const useNetwork = () => { | ||
const { network } = useWallet() | ||
return network | ||
} | ||
|
||
export const useNetworkName = () => { | ||
const { network } = useWallet() | ||
return network.name | ||
} | ||
|
||
export const useChainID = () => { | ||
const { network } = useWallet() | ||
return network.chainID | ||
} | ||
export * from "auth/hooks/useNetwork" | ||
export { default as useAddress } from "auth/hooks/useAddress" |
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,8 @@ | ||
type NetworkName = string | ||
type TerraNetworks = Record<NetworkName, TerraNetwork> | ||
|
||
interface TerraNetwork { | ||
name: NetworkName | ||
chainID: string | ||
lcd: 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