Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

[Claim] Approve flow - GNO approve #2130

Merged
merged 6 commits into from
Jan 13, 2022
Merged

[Claim] Approve flow - GNO approve #2130

merged 6 commits into from
Jan 13, 2022

Conversation

W3stside
Copy link
Contributor

@W3stside W3stside commented Jan 13, 2022

Summary

Part of #2087 [approval]

Approve GNO for investing.

Screenshots

Approving
Screenshot 2022-01-13 at 10 16 46

Approved
image

To Test

  1. Head into claim using a PK from the list
  2. click a row
  3. click into approve tokens
  4. approve GNO
  5. should see what the screenshots show

Incoming

  • USDC approve
  • more styles i guess
  • balances

@W3stside W3stside marked this pull request as draft January 13, 2022 12:31
@github-actions
Copy link
Contributor

  • 🔭 GP Swap: Gnosis Protocol v2 Swap UI

@@ -30,3 +31,16 @@ export function useApproveCallbackFromTrade(

return useApproveCallback(openTransactionConfirmationModal, closeModals, amountToApprove, vaultRelayer)
}

export function useApproveCallbackFromClaim(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claim functionalty's useApproveCallback - opted NOT to hardcode MAX GNO uint256 here and instead allow passing in values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine with me, we might even need this if users start to complaint for using MAX on their investments

@@ -0,0 +1,38 @@
import { useMemo } from 'react'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

originally coded this because I thought we were approving only investing amount but it is no longer in use (as we use max unit256) - figured I'd leave it as it's useful for if we switch to this and/or can use in other parts of the app if we want to do exact approvals (it calcs current approved vs amount requested)

happy to remove.

@@ -0,0 +1,40 @@
import { useState, useCallback } from 'react'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simply extrapolated out of swapmod where it was being used for approvals.

it hasnt been used in SwapMod - only in Claiming - as i figured it's out of scope of this PR (this kinda is too but hey whatever it's way nicer this way)

@W3stside W3stside requested review from anxolin and a team January 13, 2022 16:20
@W3stside W3stside marked this pull request as ready for review January 13, 2022 16:21
@W3stside W3stside changed the title [Claim] Approve flow - draft [Claim] Approve flow - GNO approve Jan 13, 2022
Copy link
Contributor

@anxolin anxolin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR!

@@ -30,3 +31,16 @@ export function useApproveCallbackFromTrade(

return useApproveCallback(openTransactionConfirmationModal, closeModals, amountToApprove, vaultRelayer)
}

export function useApproveCallbackFromClaim(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine with me, we might even need this if users start to complaint for using MAX on their investments

@@ -30,3 +31,16 @@ export function useApproveCallbackFromTrade(

return useApproveCallback(openTransactionConfirmationModal, closeModals, amountToApprove, vaultRelayer)
}

export function useApproveCallbackFromClaim(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if the two hooks belong in the same file, but just nitpicking

* @description returns allowance of a token against a spender
* and the remaining allowance IF allowance > remaining. Else is null
*/
export default function useRemainingAllowanceToApprove({ amountToApprove, spender }: Params) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be good to add a return type?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like you did this hook, I like sugar


return {
allowance,
needsApproval: !allowance || amountToApprove?.greaterThan(allowance),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or remainingAllowanceToApprove greater than ZERO. but yours is good too

import { useOpenModal, useCloseModals, useModalOpen } from 'state/application/hooks'
import { ApplicationModal } from 'state/application/reducer'

export default function useTransactionConfirmationModal(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is just to use this hook, and allow to open the confirmation with different operation types and messages for the same component?

im kind of ok, although i don't see completly the point since you only used it with one type, so probably using TransactionConfirmationModal would be not that bad

Copy link
Contributor Author

@W3stside W3stside Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah the code inside SwapMod, lines 150 - 167 + the modal component are identical in claim. and likely anywhere else with approve/transaction modal stuff

@W3stside
Copy link
Contributor Author

merging now to clean up, can re-visit this later

@W3stside W3stside merged commit 2deafd3 into claim Jan 13, 2022
@alfetopito alfetopito deleted the claim-approve branch January 13, 2022 17:35
import Row from 'components/Row'

// Max approve amount
const MAX_GNO_UINT256 = CurrencyAmount.fromRawAmount(GNO[SupportedChainId.RINKEBY], MaxUint256)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to hard code for each token that'll be approved?
Also, you are relying on rinkeby's GNO. Won't that be a problem?
I know, I know, not likely a problem.

I just thought this would work like approval for any other token before trading

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, it will be an issue on another network..

OperationType.APPROVE_TOKEN
)

const [approveState, approveCallback] = useApproveCallbackFromClaim(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully get it. Why do you need a special approval callback for claims?
Isn't it like regular approvals (approve max always)?

Copy link
Contributor Author

@W3stside W3stside Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guess it doesn't really, @anxolin made a similar comment about it. I'll look into reverting youre right

@elena-zh
Copy link

I was able to approve GNO.
I reported a separate issue #2151 to add a 'pending' TX state when a token approval TX is pending.
Also, I did some tests on a partial token approval (approved 1 token spend only), but the app showed me that the token is not approved. I believe, that this is not implemented yet.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants