-
Notifications
You must be signed in to change notification settings - Fork 2
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 #18 from oasisprotocol/ml/estimate-gas-price-via-p…
…rovider Estimate gas price via provider
- Loading branch information
Showing
11 changed files
with
178 additions
and
83 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,18 @@ | ||
import { useEffect, useRef } from 'react' | ||
|
||
export const useInterval = (cb: () => void, delay: number) => { | ||
const cbRef = useRef(() => { | ||
}) | ||
|
||
useEffect(() => { | ||
cbRef.current = cb | ||
}, [cb]) | ||
|
||
useEffect(() => { | ||
const id = setInterval(() => cbRef.current(), delay) | ||
|
||
return () => { | ||
clearInterval(id) | ||
} | ||
}, [delay]) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { createContext } from 'react' | ||
import { BigNumber, ethers } from 'ethers' | ||
import * as sapphire from '@oasisprotocol/sapphire-paratime' | ||
import { TransactionResponse } from '@ethersproject/abstract-provider' | ||
|
||
export interface Web3ProviderState { | ||
isConnected: boolean | ||
ethProvider: ethers.providers.Web3Provider | null | ||
sapphireEthProvider: (ethers.providers.Web3Provider & sapphire.SapphireAnnex) | null | ||
wRoseContractAddress: string | null | ||
wRoseContract: ethers.Contract | null | ||
account: string | null | ||
explorerBaseUrl: string | null | ||
networkName: string | null | ||
} | ||
|
||
export interface Web3ProviderContext { | ||
readonly state: Web3ProviderState | ||
wrap: (amount: string, gasPrice: BigNumber) => Promise<TransactionResponse> | ||
unwrap: (amount: string, gasPrice: BigNumber) => Promise<TransactionResponse> | ||
isMetaMaskInstalled: () => Promise<boolean> | ||
connectWallet: () => Promise<void> | ||
switchNetwork: () => Promise<void> | ||
getBalance: () => Promise<BigNumber> | ||
getBalanceOfWROSE: () => Promise<BigNumber> | ||
getTransaction: (txHash: string) => Promise<TransactionResponse> | ||
addTokenToWallet: () => Promise<void> | ||
getGasPrice: () => Promise<BigNumber> | ||
} | ||
|
||
export const Web3Context = createContext<Web3ProviderContext>({} as Web3ProviderContext) |
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,26 @@ | ||
import { createContext } from 'react' | ||
import { BigNumber, BigNumberish } from 'ethers' | ||
import { TransactionResponse } from '@ethersproject/abstract-provider' | ||
import { WrapFormType } from '../utils/types' | ||
|
||
export interface WrapFormProviderState { | ||
isLoading: boolean | ||
amount: BigNumber | null | ||
formType: WrapFormType | ||
balance: BigNumber | ||
wRoseBalance: BigNumber | ||
estimatedFee: BigNumber | ||
estimatedGasPrice: BigNumber | ||
} | ||
|
||
export interface WrapFormProviderContext { | ||
readonly state: WrapFormProviderState | ||
init: () => void | ||
setAmount: (amount: BigNumberish) => void | ||
toggleFormType: (amount: BigNumber | null) => void | ||
submit: (amount: BigNumber) => Promise<TransactionResponse> | ||
setFeeAmount: () => Promise<void> | ||
debounceLeadingSetFeeAmount: (fn?: () => Promise<void>, timeout?: number) => () => void | ||
} | ||
|
||
export const WrapFormContext = createContext<WrapFormProviderContext>({} as WrapFormProviderContext) |
Oops, something went wrong.