Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
0edb0fe5
Unverified
Commit
0edb0fe5
authored
Mar 11, 2022
by
Zach Pomerantz
Committed by
GitHub
Mar 11, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: memoize on-chain results (#3493)
* fix: memo-ize onchain results * fix: typeof omission
parent
496408b3
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
16 deletions
+15
-16
useCurrentBlockTimestamp.ts
src/hooks/useCurrentBlockTimestamp.ts
+6
-11
useGasPrice.ts
src/hooks/useGasPrice.ts
+2
-1
useIsArgentWallet.ts
src/hooks/useIsArgentWallet.ts
+1
-1
useTotalSupply.ts
src/hooks/useTotalSupply.ts
+6
-3
No files found.
src/hooks/useCurrentBlockTimestamp.ts
View file @
0edb0fe5
import
{
BigNumber
}
from
'
@ethersproject/bignumber
'
import
{
useSingleCallResult
}
from
'
lib/hooks/multicall
'
import
{
use
Effect
,
useState
}
from
'
react
'
import
{
use
Memo
}
from
'
react
'
import
{
useInterfaceMulticall
}
from
'
./useContract
'
// gets the current timestamp from the blockchain
export
default
function
useCurrentBlockTimestamp
():
BigNumber
|
undefined
{
const
[
lastBlock
,
setLastBlock
]
=
useState
<
BigNumber
|
undefined
>
()
const
multicall
=
useInterfaceMulticall
()
const
block
:
BigNumber
|
undefined
=
useSingleCallResult
(
multicall
,
'
getCurrentBlockTimestamp
'
)?.
result
?.[
0
]
useEffect
(()
=>
{
// If block xor lastBlock are undefined, or if block has progressed, then update lastBlock.
// This prevents updates when the block doesn't change, because the returned BigNumber will still be referentially unique.
if
(
Boolean
(
block
)
!==
Boolean
(
lastBlock
)
||
(
block
&&
lastBlock
&&
!
block
.
eq
(
lastBlock
)))
{
setLastBlock
(
block
)
}
},
[
block
,
lastBlock
])
return
lastBlock
const
resultStr
:
string
|
undefined
=
useSingleCallResult
(
multicall
,
'
getCurrentBlockTimestamp
'
)?.
result
?.[
0
]?.
toString
()
return
useMemo
(()
=>
(
typeof
resultStr
===
'
string
'
?
BigNumber
.
from
(
resultStr
)
:
undefined
),
[
resultStr
])
}
src/hooks/useGasPrice.ts
View file @
0edb0fe5
import
JSBI
from
'
jsbi
'
import
{
useSingleCallResult
}
from
'
lib/hooks/multicall
'
import
{
useMemo
}
from
'
react
'
import
{
useContract
}
from
'
./useContract
'
import
useENSAddress
from
'
./useENSAddress
'
...
...
@@ -22,5 +23,5 @@ export default function useGasPrice(): JSBI | undefined {
const
contract
=
useContract
(
address
??
undefined
,
CHAIN_DATA_ABI
,
false
)
const
resultStr
=
useSingleCallResult
(
contract
,
'
latestAnswer
'
).
result
?.[
0
]?.
toString
()
return
typeof
resultStr
===
'
string
'
?
JSBI
.
BigInt
(
resultStr
)
:
undefined
return
useMemo
(()
=>
(
typeof
resultStr
===
'
string
'
?
JSBI
.
BigInt
(
resultStr
)
:
undefined
),
[
resultStr
])
}
src/hooks/useIsArgentWallet.ts
View file @
0edb0fe5
...
...
@@ -9,5 +9,5 @@ export default function useIsArgentWallet(): boolean {
const
argentWalletDetector
=
useArgentWalletDetectorContract
()
const
inputs
=
useMemo
(()
=>
[
account
??
undefined
],
[
account
])
const
call
=
useSingleCallResult
(
argentWalletDetector
,
'
isArgentWallet
'
,
inputs
,
NEVER_RELOAD
)
return
call
?.
result
?.[
0
]
??
false
return
Boolean
(
call
?.
result
?.[
0
])
}
src/hooks/useTotalSupply.ts
View file @
0edb0fe5
import
{
BigNumber
}
from
'
@ethersproject/bignumber
'
import
{
Currency
,
CurrencyAmount
,
Token
}
from
'
@uniswap/sdk-core
'
import
{
useSingleCallResult
}
from
'
lib/hooks/multicall
'
import
{
useMemo
}
from
'
react
'
import
{
useTokenContract
}
from
'
./useContract
'
...
...
@@ -9,7 +9,10 @@ import { useTokenContract } from './useContract'
export
function
useTotalSupply
(
token
?:
Currency
):
CurrencyAmount
<
Token
>
|
undefined
{
const
contract
=
useTokenContract
(
token
?.
isToken
?
token
.
address
:
undefined
,
false
)
const
totalSupply
:
BigNumber
=
useSingleCallResult
(
contract
,
'
totalSupply
'
)?.
result
?.[
0
]
const
totalSupply
Str
:
string
|
undefined
=
useSingleCallResult
(
contract
,
'
totalSupply
'
)?.
result
?.[
0
]?.
toString
()
return
token
?.
isToken
&&
totalSupply
?
CurrencyAmount
.
fromRawAmount
(
token
,
totalSupply
.
toString
())
:
undefined
return
useMemo
(
()
=>
(
token
?.
isToken
&&
totalSupplyStr
?
CurrencyAmount
.
fromRawAmount
(
token
,
totalSupplyStr
)
:
undefined
),
[
token
,
totalSupplyStr
]
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment