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
43931dd6
Unverified
Commit
43931dd6
authored
Feb 03, 2022
by
Zach Pomerantz
Committed by
GitHub
Feb 03, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: chain-specific ttls (#3228)
parent
efa3d552
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
23 deletions
+29
-23
TransactionTtlInput.tsx
src/lib/components/Swap/Settings/TransactionTtlInput.tsx
+7
-8
useTransactionDeadline.ts
src/lib/hooks/useTransactionDeadline.ts
+21
-10
settings.ts
src/lib/state/settings.ts
+1
-5
No files found.
src/lib/components/Swap/Settings/TransactionTtlInput.tsx
View file @
43931dd6
import
{
Trans
}
from
'
@lingui/macro
'
import
{
useAtom
}
from
'
jotai
'
import
{
TRANSACTION_TTL_DEFAULT
,
transactionTtlAtom
}
from
'
lib/state/settings
'
import
{
useDefaultTransactionTtl
,
useTransactionTtl
}
from
'
lib/hooks/useTransactionDeadline
'
import
styled
,
{
ThemedText
}
from
'
lib/theme
'
import
{
useRef
}
from
'
react
'
...
...
@@ -11,14 +10,14 @@ import { Label } from './components'
const
tooltip
=
<
Trans
>
Your transaction will revert if it has been pending for longer than this period of time.
</
Trans
>
const
placeholder
=
TRANSACTION_TTL_DEFAULT
.
toString
()
const
Input
=
styled
(
Row
)
`
${
inputCss
}
`
export
default
function
TransactionTtlInput
()
{
const
[
transactionTtl
,
setTransactionTtl
]
=
useAtom
(
transactionTtlAtom
)
const
[
ttl
,
setTtl
]
=
useTransactionTtl
()
const
defaultTtl
=
useDefaultTransactionTtl
()
const
placeholder
=
defaultTtl
.
toString
()
const
input
=
useRef
<
HTMLInputElement
>
(
null
)
return
(
<
Column
gap=
{
0.75
}
>
...
...
@@ -27,9 +26,9 @@ export default function TransactionTtlInput() {
<
Input
justify=
"start"
onClick=
{
()
=>
input
.
current
?.
focus
()
}
>
<
IntegerInput
placeholder=
{
placeholder
}
value=
{
t
ransactionT
tl
?.
toString
()
??
''
}
onChange=
{
(
value
)
=>
setT
ransactionT
tl
(
value
?
parseFloat
(
value
)
:
0
)
}
size=
{
Math
.
max
(
t
ransactionT
tl
?.
toString
().
length
||
0
,
placeholder
.
length
)
}
value=
{
ttl
?.
toString
()
??
''
}
onChange=
{
(
value
)
=>
setTtl
(
value
?
parseFloat
(
value
)
:
0
)
}
size=
{
Math
.
max
(
ttl
?.
toString
().
length
||
0
,
placeholder
.
length
)
}
ref=
{
input
}
/>
<
Trans
>
minutes
</
Trans
>
...
...
src/lib/hooks/useTransactionDeadline.ts
View file @
43931dd6
import
{
BigNumber
}
from
'
@ethersproject/bignumber
'
import
{
L2_CHAIN_IDS
}
from
'
constants/chains
'
import
{
L2_DEADLINE_FROM_NOW
}
from
'
constants/misc
'
import
{
DEFAULT_DEADLINE_FROM_NOW
,
L2_DEADLINE_FROM_NOW
}
from
'
constants/misc
'
import
useCurrentBlockTimestamp
from
'
hooks/useCurrentBlockTimestamp
'
import
{
useAtom
Value
}
from
'
jotai/utils
'
import
{
TRANSACTION_TTL_DEFAULT
,
transactionTtlAtom
}
from
'
lib/state/settings
'
import
{
useAtom
}
from
'
jotai
'
import
{
transactionTtlAtom
}
from
'
lib/state/settings
'
import
{
useMemo
}
from
'
react
'
import
useActiveWeb3React
from
'
./useActiveWeb3React
'
/** Returns the default transaction TTL for the chain, in minutes. */
export
function
useDefaultTransactionTtl
():
number
{
const
{
chainId
}
=
useActiveWeb3React
()
if
(
chainId
&&
L2_CHAIN_IDS
.
includes
(
chainId
))
return
L2_DEADLINE_FROM_NOW
/
60
return
DEFAULT_DEADLINE_FROM_NOW
/
60
}
/** Returns the user-inputted transaction TTL, in minutes. */
export
function
useTransactionTtl
():
[
number
|
undefined
,
(
ttl
?:
number
)
=>
void
]
{
return
useAtom
(
transactionTtlAtom
)
}
// combines the block timestamp with the user setting to give the deadline that should be used for any submitted transaction
export
default
function
useTransactionDeadline
():
BigNumber
|
undefined
{
const
{
chainId
}
=
useActiveWeb3React
()
const
userDeadline
:
number
=
useAtomValue
(
transactionTtlAtom
)
||
TRANSACTION_TTL_DEFAULT
const
[
ttl
]
=
useTransactionTtl
()
const
defaultTtl
=
useDefaultTransactionTtl
()
const
blockTimestamp
=
useCurrentBlockTimestamp
()
return
useMemo
(()
=>
{
if
(
blockTimestamp
&&
chainId
&&
L2_CHAIN_IDS
.
includes
(
chainId
))
return
blockTimestamp
.
add
(
L2_DEADLINE_FROM_NOW
)
//@TODO(ianlapham): update this to be stored as seconds
if
(
blockTimestamp
&&
userDeadline
)
return
blockTimestamp
.
add
(
userDeadline
*
60
)
// adjust for seconds
return
undefined
},
[
blockTimestamp
,
chainId
,
userDeadline
])
if
(
!
blockTimestamp
)
return
undefined
return
blockTimestamp
.
add
((
ttl
||
defaultTtl
)
/* in seconds */
*
60
)
},
[
blockTimestamp
,
defaultTtl
,
ttl
])
}
src/lib/state/settings.ts
View file @
43931dd6
...
...
@@ -6,13 +6,9 @@ import { pickAtom, setTogglable } from './atoms'
export
const
MAX_VALID_SLIPPAGE
=
new
Percent
(
1
,
2
)
export
const
MIN_HIGH_SLIPPAGE
=
new
Percent
(
1
,
100
)
// transaction deadline in minutes, needs to be adjusted to seconds before use
// @TODO(ianlapham): update this to be stored as seconds
export
const
TRANSACTION_TTL_DEFAULT
=
30
interface
Settings
{
maxSlippage
:
Percent
|
'
auto
'
// auto will cause slippage to resort to default calculation
transactionTtl
:
number
|
undefined
transactionTtl
:
number
|
undefined
// transaction ttl in minutes
integratorFee
:
number
|
undefined
mockTogglable
:
boolean
clientSideRouter
:
boolean
// whether to use the client-side router or query the remote API
...
...
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