-
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.
feat(cr): add allocation context (#374)
back to state pagination and safer context return chore: review allocations fix: make builder context global
- Loading branch information
Showing
34 changed files
with
769 additions
and
278 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
93 changes: 0 additions & 93 deletions
93
src/app/collective-rewards/allocations/AllocationMetrics.tsx
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
src/app/collective-rewards/allocations/BuilderAllocation.tsx
This file was deleted.
Oops, something went wrong.
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
68 changes: 68 additions & 0 deletions
68
src/app/collective-rewards/allocations/components/AllocationMetrics.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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use client' | ||
|
||
import { Paragraph } from '@/components/Typography' | ||
import { useContext } from 'react' | ||
import { formatEther } from 'viem' | ||
import { AllocationsContext } from '@/app/collective-rewards/allocations/context' | ||
|
||
type ValueProps = { | ||
value: string | ||
} | ||
|
||
type MetricsProps = ValueProps & { | ||
name: string | ||
} | ||
|
||
const Metric = ({ name, value }: MetricsProps) => { | ||
return ( | ||
<div className="flex flex-col items-start gap-[10px]"> | ||
<Paragraph className="font-bold tracking-[-0.28px] text-[14px]">{name}</Paragraph> | ||
<Paragraph className="font-kk-topo text-[48px] text-primary">{value}</Paragraph> | ||
</div> | ||
) | ||
} | ||
|
||
const Column = ({ children }: { children: React.ReactNode }) => { | ||
return <div className="flex flex-col items-start gap-[10px] min-w-[200px] max-w-[20%]">{children}</div> | ||
} | ||
|
||
const Balance = ({ value }: ValueProps) => { | ||
return <Metric name="Balance" value={value} /> | ||
} | ||
|
||
const AllocatedAmount = ({ value }: ValueProps) => { | ||
return <Metric name="Allocated amount" value={value} /> | ||
} | ||
|
||
const UnallocatedAmount = ({ value }: ValueProps) => { | ||
return <Metric name="Unallocated amount" value={value} /> | ||
} | ||
|
||
export const AllocationMetrics = () => { | ||
const { | ||
initialState: { | ||
backer: { totalAllocation, balance }, | ||
}, | ||
} = useContext(AllocationsContext) | ||
|
||
const balanceValue = `${formatEther(balance)} stRIF` | ||
|
||
const allocatedAmountValue = `${formatEther(totalAllocation)} stRIF` | ||
|
||
const unallocatedAmount = formatEther(balance - totalAllocation) | ||
|
||
const unallocatedAmountValue = `${unallocatedAmount} stRIF` | ||
return ( | ||
<div className="flex items-start gap-6 w-full"> | ||
<Column> | ||
<Balance value={balanceValue} /> | ||
</Column> | ||
<Column> | ||
<AllocatedAmount value={allocatedAmountValue} /> | ||
</Column> | ||
<Column> | ||
<UnallocatedAmount value={unallocatedAmountValue} /> | ||
</Column> | ||
</div> | ||
) | ||
} |
51 changes: 51 additions & 0 deletions
51
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { AllocationsContext } from '@/app/collective-rewards/allocations/context' | ||
import { Builder } from '@/app/collective-rewards/types' | ||
import { Input } from '@/components/Input' | ||
import { Slider } from '@/components/Slider' | ||
import { Label } from '@/components/Typography' | ||
import { useContext } from 'react' | ||
import { formatEther, parseEther } from 'viem' | ||
import { BuilderAllocationHeader, BuilderAllocationHeaderProps } from './BuilderAllocationHeader' | ||
|
||
export type BuilderAllocationProps = BuilderAllocationHeaderProps & | ||
Pick<Builder, 'kickback'> & { | ||
index: number | ||
currentAllocation: bigint | ||
} | ||
|
||
export const BuilderAllocation = (builder: BuilderAllocationProps) => { | ||
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)) | ||
} | ||
|
||
const onSliderValueChange = (value: number[]) => { | ||
updateAllocation(builder.index, BigInt(value[0])) | ||
} | ||
|
||
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)] rounded-[8px]"> | ||
<BuilderAllocationHeader {...builder} /> | ||
<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)]} | ||
max={Number(totalAllocation)} | ||
onValueChange={onSliderValueChange} | ||
/> | ||
</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
File renamed without changes.
File renamed without changes.
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' |
Oops, something went wrong.