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
3db9e1b9
Unverified
Commit
3db9e1b9
authored
Jun 14, 2023
by
eddie
Committed by
GitHub
Jun 14, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: rename permit2 variables for clarity (#6728)
* feat: rename permit2 variables for clarity * fix: types
parent
79a72d6f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
19 deletions
+19
-19
ConfirmSwapModal.tsx
src/components/swap/ConfirmSwapModal.tsx
+7
-7
usePermit2Allowance.ts
src/hooks/usePermit2Allowance.ts
+6
-6
BagFooter.test.tsx
src/nft/components/bag/BagFooter.test.tsx
+6
-6
No files found.
src/components/swap/ConfirmSwapModal.tsx
View file @
3db9e1b9
...
@@ -73,10 +73,10 @@ function useConfirmModalState({
...
@@ -73,10 +73,10 @@ function useConfirmModalState({
// at the bottom of the modal, even after they complete steps 1 and 2.
// at the bottom of the modal, even after they complete steps 1 and 2.
const
prepareSwapFlow
=
useCallback
(()
=>
{
const
prepareSwapFlow
=
useCallback
(()
=>
{
const
steps
:
PendingConfirmModalState
[]
=
[]
const
steps
:
PendingConfirmModalState
[]
=
[]
if
(
allowance
.
state
===
AllowanceState
.
REQUIRED
&&
allowance
.
needs
Permit2
Approval
)
{
if
(
allowance
.
state
===
AllowanceState
.
REQUIRED
&&
allowance
.
needs
Setup
Approval
)
{
steps
.
push
(
ConfirmModalState
.
APPROVING_TOKEN
)
steps
.
push
(
ConfirmModalState
.
APPROVING_TOKEN
)
}
}
if
(
allowance
.
state
===
AllowanceState
.
REQUIRED
&&
allowance
.
needsSignature
)
{
if
(
allowance
.
state
===
AllowanceState
.
REQUIRED
&&
allowance
.
needs
Permit
Signature
)
{
steps
.
push
(
ConfirmModalState
.
PERMITTING
)
steps
.
push
(
ConfirmModalState
.
PERMITTING
)
}
}
steps
.
push
(
ConfirmModalState
.
PENDING_CONFIRMATION
)
steps
.
push
(
ConfirmModalState
.
PENDING_CONFIRMATION
)
...
@@ -92,7 +92,7 @@ function useConfirmModalState({
...
@@ -92,7 +92,7 @@ function useConfirmModalState({
if
(
allowance
.
state
===
AllowanceState
.
REQUIRED
)
{
if
(
allowance
.
state
===
AllowanceState
.
REQUIRED
)
{
// Starts the approval process, by triggering either the Token Approval or the Permit signature.
// Starts the approval process, by triggering either the Token Approval or the Permit signature.
try
{
try
{
if
(
allowance
.
needs
Permit2
Approval
)
{
if
(
allowance
.
needs
Setup
Approval
)
{
setConfirmModalState
(
ConfirmModalState
.
APPROVING_TOKEN
)
setConfirmModalState
(
ConfirmModalState
.
APPROVING_TOKEN
)
await
allowance
.
approve
()
await
allowance
.
approve
()
sendAnalyticsEvent
(
InterfaceEventName
.
APPROVE_TOKEN_TXN_SUBMITTED
,
{
sendAnalyticsEvent
(
InterfaceEventName
.
APPROVE_TOKEN_TXN_SUBMITTED
,
{
...
@@ -112,7 +112,7 @@ function useConfirmModalState({
...
@@ -112,7 +112,7 @@ function useConfirmModalState({
}
}
console
.
error
(
e
)
console
.
error
(
e
)
setApprovalError
(
setApprovalError
(
allowance
.
needs
Permit2
Approval
?
PendingModalError
.
TOKEN_APPROVAL_ERROR
:
PendingModalError
.
PERMIT_ERROR
allowance
.
needs
Setup
Approval
?
PendingModalError
.
TOKEN_APPROVAL_ERROR
:
PendingModalError
.
PERMIT_ERROR
)
)
}
}
}
else
{
}
else
{
...
@@ -122,14 +122,14 @@ function useConfirmModalState({
...
@@ -122,14 +122,14 @@ function useConfirmModalState({
},
[
allowance
,
chainId
,
maximumAmountIn
?.
currency
.
address
,
maximumAmountIn
?.
currency
.
symbol
,
onSwap
,
trace
])
},
[
allowance
,
chainId
,
maximumAmountIn
?.
currency
.
address
,
maximumAmountIn
?.
currency
.
symbol
,
onSwap
,
trace
])
const
previousPermitNeeded
=
usePrevious
(
const
previousPermitNeeded
=
usePrevious
(
allowance
.
state
===
AllowanceState
.
REQUIRED
?
allowance
.
needs
Permit2
Approval
:
undefined
allowance
.
state
===
AllowanceState
.
REQUIRED
?
allowance
.
needs
Setup
Approval
:
undefined
)
)
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
if
(
allowance
.
state
===
AllowanceState
.
REQUIRED
&&
allowance
.
state
===
AllowanceState
.
REQUIRED
&&
allowance
.
needsSignature
&&
allowance
.
needs
Permit
Signature
&&
// If the token approval switched from missing to fulfilled, trigger the next step (permit2 signature).
// If the token approval switched from missing to fulfilled, trigger the next step (permit2 signature).
!
allowance
.
needs
Permit2
Approval
&&
!
allowance
.
needs
Setup
Approval
&&
previousPermitNeeded
previousPermitNeeded
)
{
)
{
startSwapFlow
()
startSwapFlow
()
...
...
src/hooks/usePermit2Allowance.ts
View file @
3db9e1b9
...
@@ -30,8 +30,8 @@ interface AllowanceRequired {
...
@@ -30,8 +30,8 @@ interface AllowanceRequired {
approve
:
()
=>
Promise
<
void
>
approve
:
()
=>
Promise
<
void
>
permit
:
()
=>
Promise
<
void
>
permit
:
()
=>
Promise
<
void
>
revoke
:
()
=>
Promise
<
void
>
revoke
:
()
=>
Promise
<
void
>
needs
Permit2
Approval
:
boolean
needs
Setup
Approval
:
boolean
needsSignature
:
boolean
needs
Permit
Signature
:
boolean
allowedAmount
:
CurrencyAmount
<
Token
>
allowedAmount
:
CurrencyAmount
<
Token
>
}
}
...
@@ -137,8 +137,8 @@ export default function usePermit2Allowance(amount?: CurrencyAmount<Token>, spen
...
@@ -137,8 +137,8 @@ export default function usePermit2Allowance(amount?: CurrencyAmount<Token>, spen
approve
,
approve
,
permit
:
updatePermitAllowance
,
permit
:
updatePermitAllowance
,
revoke
,
revoke
,
needs
Permit2
Approval
:
!
isApproved
,
needs
Setup
Approval
:
!
isApproved
,
needsSignature
:
shouldRequestSignature
,
needs
Permit
Signature
:
shouldRequestSignature
,
allowedAmount
:
tokenAllowance
,
allowedAmount
:
tokenAllowance
,
}
}
}
else
if
(
!
isApproved
)
{
}
else
if
(
!
isApproved
)
{
...
@@ -152,8 +152,8 @@ export default function usePermit2Allowance(amount?: CurrencyAmount<Token>, spen
...
@@ -152,8 +152,8 @@ export default function usePermit2Allowance(amount?: CurrencyAmount<Token>, spen
approve
,
approve
,
permit
:
updatePermitAllowance
,
permit
:
updatePermitAllowance
,
revoke
,
revoke
,
needs
Permit2
Approval
:
true
,
needs
Setup
Approval
:
true
,
needsSignature
:
shouldRequestSignature
,
needs
Permit
Signature
:
shouldRequestSignature
,
allowedAmount
:
tokenAllowance
,
allowedAmount
:
tokenAllowance
,
}
}
}
}
...
...
src/nft/components/bag/BagFooter.test.tsx
View file @
3db9e1b9
...
@@ -348,8 +348,8 @@ describe('BagFooter.tsx', () => {
...
@@ -348,8 +348,8 @@ describe('BagFooter.tsx', () => {
approve
:
()
=>
Promise
.
resolve
(),
approve
:
()
=>
Promise
.
resolve
(),
permit
:
()
=>
Promise
.
resolve
(),
permit
:
()
=>
Promise
.
resolve
(),
revoke
:
()
=>
Promise
.
resolve
(),
revoke
:
()
=>
Promise
.
resolve
(),
needs
Permit2
Approval
:
false
,
needs
Setup
Approval
:
false
,
needsSignature
:
false
,
needs
Permit
Signature
:
false
,
isRevocationPending
:
false
,
isRevocationPending
:
false
,
allowedAmount
:
CurrencyAmount
.
fromRawAmount
(
TEST_TOKEN_1
,
0
),
allowedAmount
:
CurrencyAmount
.
fromRawAmount
(
TEST_TOKEN_1
,
0
),
},
},
...
@@ -376,8 +376,8 @@ describe('BagFooter.tsx', () => {
...
@@ -376,8 +376,8 @@ describe('BagFooter.tsx', () => {
approve
:
()
=>
Promise
.
resolve
(),
approve
:
()
=>
Promise
.
resolve
(),
permit
:
()
=>
Promise
.
resolve
(),
permit
:
()
=>
Promise
.
resolve
(),
revoke
:
()
=>
Promise
.
resolve
(),
revoke
:
()
=>
Promise
.
resolve
(),
needs
Permit2
Approval
:
false
,
needs
Setup
Approval
:
false
,
needsSignature
:
false
,
needs
Permit
Signature
:
false
,
isRevocationPending
:
false
,
isRevocationPending
:
false
,
allowedAmount
:
CurrencyAmount
.
fromRawAmount
(
TEST_TOKEN_1
,
0
),
allowedAmount
:
CurrencyAmount
.
fromRawAmount
(
TEST_TOKEN_1
,
0
),
},
},
...
@@ -404,8 +404,8 @@ describe('BagFooter.tsx', () => {
...
@@ -404,8 +404,8 @@ describe('BagFooter.tsx', () => {
approve
:
()
=>
Promise
.
resolve
(),
approve
:
()
=>
Promise
.
resolve
(),
permit
:
()
=>
Promise
.
resolve
(),
permit
:
()
=>
Promise
.
resolve
(),
revoke
:
()
=>
Promise
.
resolve
(),
revoke
:
()
=>
Promise
.
resolve
(),
needs
Permit2
Approval
:
false
,
needs
Setup
Approval
:
false
,
needsSignature
:
false
,
needs
Permit
Signature
:
false
,
isRevocationPending
:
false
,
isRevocationPending
:
false
,
allowedAmount
:
CurrencyAmount
.
fromRawAmount
(
TEST_TOKEN_1
,
0
),
allowedAmount
:
CurrencyAmount
.
fromRawAmount
(
TEST_TOKEN_1
,
0
),
},
},
...
...
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