-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
663 additions
and
537 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 29 additions & 28 deletions
57
src/app/collective-rewards/allocations/components/BuilderAllocation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
import { formatBalanceToHuman } from '@/app/user/Balances/balanceUtils' | ||
import { Input } from '@/components/Input' | ||
import { Slider } from '@/components/Slider' | ||
import { Label } from '@/components/Typography' | ||
import { useState } from 'react' | ||
import { useContext } from 'react' | ||
import { formatEther, parseEther } from 'viem' | ||
import { AllocationsContext } from '@/app/collective-rewards/allocations/context' | ||
import { BuilderAllocationHeader, BuilderAllocationHeaderProps } from './BuilderAllocationHeader' | ||
import { Address } from 'viem' | ||
import { BuilderStatusShown } from '../../types' | ||
import { BuilderInfo } from '@/app/collective-rewards/types' | ||
|
||
export type BuilderStatus = BuilderStatusShown | 'Paused' | 'Deactivated' | ||
|
||
export type BuilderAllocationProps = BuilderAllocationHeaderProps & { | ||
allocationLeft: BigInt | ||
// TODO: what's the value we expect here? (e.g. 8% or 8.123456%) | ||
backerRewards: number | ||
currentAllocation: number | ||
} | ||
export type BuilderAllocationProps = BuilderAllocationHeaderProps & | ||
Pick<BuilderInfo, 'kickback'> & { | ||
index: number | ||
currentAllocation: bigint | ||
} | ||
|
||
export const BuilderAllocation = (builder: BuilderAllocationProps) => { | ||
const [sliderValue, setSliderValue] = useState<number>(builder.currentAllocation) | ||
/* TODO: when the cumulative amount exceeds the balance | ||
* - hint is changed | ||
* - Slider is hidden | ||
*/ | ||
const hint = `Allocation left ${formatBalanceToHuman(builder.allocationLeft.toString())} stRIF` | ||
// const hint = <StakeHint /> | ||
const onInputChange = () => { | ||
/* TODO: | ||
* - reset all the sliders to 0 when the user changes the input | ||
* - update the cumulative amount | ||
* - if the cumulative amount exceeds the total allocation, show an error message in the current input | ||
*/ | ||
const { | ||
state: { | ||
backer: { totalAllocation, cumulativeAllocation }, | ||
}, | ||
actions: { updateAllocation }, | ||
} = useContext(AllocationsContext) | ||
const allocationLeft = totalAllocation - cumulativeAllocation | ||
const { currentAllocation, kickback, address } = builder | ||
const onInputChange = (value: string) => { | ||
updateAllocation(builder.index, parseEther(value)) | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col py-4 px-2 gap-6 shrink-0 bg-foreground min-w-[calc(25%-1rem)] max-w-[calc(25%-1rem)]"> | ||
<BuilderAllocationHeader {...builder} /> | ||
<Label className="font-bold">Backer rewards {builder.backerRewards}% </Label> | ||
<Input type="number" name={`allocation-${builder.address}`} hint={hint} onChange={onInputChange} /> | ||
<Slider value={[sliderValue]} /> | ||
<Label className="font-bold">Backer rewards {kickback}% </Label> | ||
<Input | ||
type="number" | ||
name={`allocation-${address}`} | ||
hint={`Allocation left ${allocationLeft > 0 ? formatEther(allocationLeft) : '0'} stRIF`} | ||
onChange={onInputChange} | ||
value={formatEther(currentAllocation)} | ||
/> | ||
<Slider value={[(Number(currentAllocation) / Number(totalAllocation)) * 100]} /> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from './AllocationAmount' | ||
export * from './AllocationMetrics' | ||
export * from './BuilderAllocation' | ||
export * from './Header' | ||
export * from './StakeHint' |
43 changes: 0 additions & 43 deletions
43
src/app/collective-rewards/allocations/context/Action.d.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.