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
116a7f38
Commit
116a7f38
authored
Nov 21, 2019
by
Ian Lapham
Committed by
Noah Zinsmeister
Nov 21, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug with a try catch on approval (#516)
parent
04a918ed
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
7 deletions
+25
-7
index.js
src/components/CurrencyInputPanel/index.js
+24
-7
AddLiquidity.js
src/pages/Pool/AddLiquidity.js
+1
-0
No files found.
src/components/CurrencyInputPanel/index.js
View file @
116a7f38
...
@@ -20,6 +20,7 @@ import TokenLogo from '../TokenLogo'
...
@@ -20,6 +20,7 @@ import TokenLogo from '../TokenLogo'
import
SearchIcon
from
'
../../assets/images/magnifying-glass.svg
'
import
SearchIcon
from
'
../../assets/images/magnifying-glass.svg
'
import
{
useTransactionAdder
,
usePendingApproval
}
from
'
../../contexts/Transactions
'
import
{
useTransactionAdder
,
usePendingApproval
}
from
'
../../contexts/Transactions
'
import
{
useTokenDetails
,
useAllTokenDetails
}
from
'
../../contexts/Tokens
'
import
{
useTokenDetails
,
useAllTokenDetails
}
from
'
../../contexts/Tokens
'
import
{
useAddressBalance
}
from
'
../../contexts/Balances
'
import
{
ReactComponent
as
Close
}
from
'
../../assets/images/x.svg
'
import
{
ReactComponent
as
Close
}
from
'
../../assets/images/x.svg
'
import
{
transparentize
}
from
'
polished
'
import
{
transparentize
}
from
'
polished
'
import
{
Spinner
}
from
'
../../theme
'
import
{
Spinner
}
from
'
../../theme
'
...
@@ -296,6 +297,10 @@ export default function CurrencyInputPanel({
...
@@ -296,6 +297,10 @@ export default function CurrencyInputPanel({
const
allTokens
=
useAllTokenDetails
()
const
allTokens
=
useAllTokenDetails
()
const
{
account
}
=
useWeb3Context
()
const
userTokenBalance
=
useAddressBalance
(
account
,
selectedTokenAddress
)
function
renderUnlockButton
()
{
function
renderUnlockButton
()
{
if
(
disableUnlock
||
!
showUnlock
||
selectedTokenAddress
===
'
ETH
'
||
!
selectedTokenAddress
)
{
if
(
disableUnlock
||
!
showUnlock
||
selectedTokenAddress
===
'
ETH
'
||
!
selectedTokenAddress
)
{
return
null
return
null
...
@@ -304,14 +309,26 @@ export default function CurrencyInputPanel({
...
@@ -304,14 +309,26 @@ export default function CurrencyInputPanel({
return
(
return
(
<
SubCurrencySelect
<
SubCurrencySelect
onClick
=
{
async
()
=>
{
onClick
=
{
async
()
=>
{
const
estimatedGas
=
await
tokenContract
.
estimate
.
approve
(
let
estimatedGas
selectedTokenExchangeAddress
,
let
useUserBalance
=
false
ethers
.
constants
.
MaxUint256
estimatedGas
=
await
tokenContract
.
estimate
)
.
approve
(
selectedTokenExchangeAddress
,
ethers
.
constants
.
MaxUint256
)
tokenContract
.
catch
(
e
=>
{
.
approve
(
selectedTokenExchangeAddress
,
ethers
.
constants
.
MaxUint256
,
{
console
.
log
(
'
Error setting max token approval.
'
)
gasLimit
:
calculateGasMargin
(
estimatedGas
,
GAS_MARGIN
)
})
})
if
(
!
estimatedGas
)
{
// general fallback for tokens who restrict approval amounts
estimatedGas
=
await
tokenContract
.
estimate
.
approve
(
selectedTokenExchangeAddress
,
userTokenBalance
)
useUserBalance
=
true
}
tokenContract
.
approve
(
selectedTokenExchangeAddress
,
useUserBalance
?
userTokenBalance
:
ethers
.
constants
.
MaxUint256
,
{
gasLimit
:
calculateGasMargin
(
estimatedGas
,
GAS_MARGIN
)
}
)
.
then
(
response
=>
{
.
then
(
response
=>
{
addTransaction
(
response
,
{
approval
:
selectedTokenAddress
})
addTransaction
(
response
,
{
approval
:
selectedTokenAddress
})
})
})
...
...
src/pages/Pool/AddLiquidity.js
View file @
116a7f38
...
@@ -551,6 +551,7 @@ export default function AddLiquidity({ params }) {
...
@@ -551,6 +551,7 @@ export default function AddLiquidity({ params }) {
},
[
inputValueParsed
,
inputBalance
,
outputValueMax
,
outputBalance
,
t
])
},
[
inputValueParsed
,
inputBalance
,
outputValueMax
,
outputBalance
,
t
])
const
allowance
=
useAddressAllowance
(
account
,
outputCurrency
,
exchangeAddress
)
const
allowance
=
useAddressAllowance
(
account
,
outputCurrency
,
exchangeAddress
)
const
[
showUnlock
,
setShowUnlock
]
=
useState
(
false
)
const
[
showUnlock
,
setShowUnlock
]
=
useState
(
false
)
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
outputValueParsed
&&
allowance
)
{
if
(
outputValueParsed
&&
allowance
)
{
...
...
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