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

[Claim refactor] - Split InvestmentFlow and minor slider impl. #2144

Merged
merged 6 commits into from
Jan 14, 2022

Conversation

W3stside
Copy link
Contributor

Splits InvestmentFlow and implements barebones slider implementation (for another PR)

  • InvestOption now mapped in Investment component

@nenadV91 please take over and finish this one, keep it small please!

@github-actions
Copy link
Contributor

  • 🔭 GP Swap: Gnosis Protocol v2 Swap UI

}

const handleStepChange = (value: number) => {
console.log(value)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

one thing here, if we decide to use this, is to make sure to debounce this


const amount = maxCost.greaterThan(balance) ? balance : maxCost
// store the value as a string to prevent unnecessary re-renders
const investAmount = formatUnits(amount.quotient.toString(), balance.currency.decimals)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

why aren't you saving it as atoms? (may be @alfetopito who did this) but question remains

especially since you're using it in other places to do maths and need to reconvert. We usually just formatSmart the thing from atoms or am I wrong?

Copy link
Contributor

Choose a reason for hiding this comment

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

Because it matches the input value, which won't be in atoms.

I was using atoms at first, but then the input start behaving very weird.

return
}

const investA = CurrencyAmount.fromRawAmount(token, parseUnits(investedAmount, token.decimals).toString())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

like here investedAmount could just be passed as a string from state (if it were saved as atoms)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, I was doing that before, but then I would need to convert this in other places anyway.
The biggest problem is the input

<b>Token approval</b>
<i>
{approveState === ApprovalState.NOT_APPROVED ? (
`${currencyAmount?.currency?.symbol} not approved`
Copy link
Contributor Author

@W3stside W3stside Jan 14, 2022

Choose a reason for hiding this comment

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

yeah i think we should create a type checking

function isDefinedCurrency(currency: Currency | undefined) currency is Required<Currency> { 
    ... 
}

to help remove these optional params hell

Copy link
Contributor Author

Choose a reason for hiding this comment

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

( I also didn't like adding another prop just for the name but maybe we should add that back in )

Copy link
Contributor

Choose a reason for hiding this comment

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

Nah, I have that on top as a nice and single symbol variable.
But I do like the idea of Required

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.

Are you refactoring or also changing code?

Cause if you are, is a bad idea for the reviewiewers (shows to many lines of code changes that are not relevant)

@@ -23,7 +23,7 @@ import ClaimAddress from './ClaimAddress'
import CanUserClaimMessage from './CanUserClaimMessage'
import ClaimingStatus from './ClaimingStatus'
import ClaimsTable from './ClaimsTable'
import InvestmentFlow from './InvestmentFlow'
import InvestmentFlow from './Investment'
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not calling the dir also InvestmentFlow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i did this, was tired, my bad

@@ -175,7 +175,7 @@ export default function Claim() {
// on account change
useEffect(() => {
if (!isSearchUsed && account) {
setActiveClaimAccount(account)
setActiveClaimAccount('0xD5e900280Eb1aDe4E583c2bF2414be247E298435')
Copy link
Contributor

Choose a reason for hiding this comment

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

why hardcoding this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed, just for development so I don't have to insert one while working on investment flow


<div>
<RangeSteps>
{[0, 25, 50, 75, 100].map((step: number) => (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this array should probably just be created outside the body

Copy link
Contributor

Choose a reason for hiding this comment

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

You can leave this part out, there's a component (semi-)ready coming from Protofire


const updateInvestAmount = useCallback(
(idx: number, investedAmount: string) => {
console.log(idx, investedAmount)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

make TODO to remove and/or change log to be more descriptive plz

))}

<InvestTokenSubtotal>
{activeClaimAccount} will receive: 4,054,671.28 vCOW based on investment(s)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

add TODO to change this

</span>
<label>
<b>{currencyAmount?.currency?.symbol}</b>
<input disabled placeholder="0" value={investedAmount} max={formatSmart(currencyAmount)} />
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually the max might be different than currencyAmout. Maybe we could export the logic from onMaxClick to be re-used here

@W3stside W3stside marked this pull request as ready for review January 14, 2022 15:43
@W3stside
Copy link
Contributor Author

to be merged in this state - next PRs will tackle logic changes.

@W3stside W3stside merged commit 84a384d into claim Jan 14, 2022
}

const amount = maxCost.greaterThan(balance) ? balance : maxCost
// store the value as a string to prevent unnecessary re-renders
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be a dumb reason and not really apply, as we depend on other stuff that are object instances.
I started with this but did not get around to clear it.

One reason to keep it though is to be closer to the input, not a lot of conversions on every keystroke

@alfetopito alfetopito deleted the claim-split-investment-flow branch January 14, 2022 15:49
@alfetopito alfetopito mentioned this pull request Jan 14, 2022
7 tasks
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