Commit 904d1835 authored by Vignesh Mohankumar's avatar Vignesh Mohankumar Committed by GitHub

style: rename library to provider (#4038)

parent 77366bf8
...@@ -40,12 +40,12 @@ interface FailedCall extends SwapCallEstimate { ...@@ -40,12 +40,12 @@ interface FailedCall extends SwapCallEstimate {
export default function useSendSwapTransaction( export default function useSendSwapTransaction(
account: string | null | undefined, account: string | null | undefined,
chainId: number | undefined, chainId: number | undefined,
library: JsonRpcProvider | undefined, provider: JsonRpcProvider | undefined,
trade: AnyTrade | undefined, // trade to execute, required trade: AnyTrade | undefined, // trade to execute, required
swapCalls: SwapCall[] swapCalls: SwapCall[]
): { callback: null | (() => Promise<TransactionResponse>) } { ): { callback: null | (() => Promise<TransactionResponse>) } {
return useMemo(() => { return useMemo(() => {
if (!trade || !library || !account || !chainId) { if (!trade || !provider || !account || !chainId) {
return { callback: null } return { callback: null }
} }
return { return {
...@@ -64,7 +64,7 @@ export default function useSendSwapTransaction( ...@@ -64,7 +64,7 @@ export default function useSendSwapTransaction(
value, value,
} }
return library return provider
.estimateGas(tx) .estimateGas(tx)
.then((gasEstimate) => { .then((gasEstimate) => {
return { return {
...@@ -75,7 +75,7 @@ export default function useSendSwapTransaction( ...@@ -75,7 +75,7 @@ export default function useSendSwapTransaction(
.catch((gasError) => { .catch((gasError) => {
console.debug('Gas estimate failed, trying eth_call to extract error', call) console.debug('Gas estimate failed, trying eth_call to extract error', call)
return library return provider
.call(tx) .call(tx)
.then((result) => { .then((result) => {
console.debug('Unexpected successful call after failed estimate gas', call, gasError, result) console.debug('Unexpected successful call after failed estimate gas', call, gasError, result)
...@@ -110,7 +110,7 @@ export default function useSendSwapTransaction( ...@@ -110,7 +110,7 @@ export default function useSendSwapTransaction(
call: { address, calldata, value }, call: { address, calldata, value },
} = bestCallOption } = bestCallOption
return library return provider
.getSigner() .getSigner()
.sendTransaction({ .sendTransaction({
from: account, from: account,
...@@ -136,5 +136,5 @@ export default function useSendSwapTransaction( ...@@ -136,5 +136,5 @@ export default function useSendSwapTransaction(
}) })
}, },
} }
}, [account, chainId, library, swapCalls, trade]) }, [account, chainId, provider, swapCalls, trade])
} }
...@@ -25,22 +25,22 @@ export function shortenAddress(address: string, chars = 4): string { ...@@ -25,22 +25,22 @@ export function shortenAddress(address: string, chars = 4): string {
} }
// account is not optional // account is not optional
function getSigner(library: JsonRpcProvider, account: string): JsonRpcSigner { function getSigner(provider: JsonRpcProvider, account: string): JsonRpcSigner {
return library.getSigner(account).connectUnchecked() return provider.getSigner(account).connectUnchecked()
} }
// account is optional // account is optional
function getProviderOrSigner(library: JsonRpcProvider, account?: string): JsonRpcProvider | JsonRpcSigner { function getProviderOrSigner(provider: JsonRpcProvider, account?: string): JsonRpcProvider | JsonRpcSigner {
return account ? getSigner(library, account) : library return account ? getSigner(provider, account) : provider
} }
// account is optional // account is optional
export function getContract(address: string, ABI: any, library: JsonRpcProvider, account?: string): Contract { export function getContract(address: string, ABI: any, provider: JsonRpcProvider, account?: string): Contract {
if (!isAddress(address) || address === AddressZero) { if (!isAddress(address) || address === AddressZero) {
throw Error(`Invalid 'address' parameter '${address}'.`) throw Error(`Invalid 'address' parameter '${address}'.`)
} }
return new Contract(address, ABI, getProviderOrSigner(library, account) as any) return new Contract(address, ABI, getProviderOrSigner(provider, account) as any)
} }
export function escapeRegExp(string: string): string { export function escapeRegExp(string: string): string {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment