-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from TalismanSociety/feat/vested-multisend
feat: vested multisend done
- Loading branch information
Showing
27 changed files
with
1,517 additions
and
614 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
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,67 @@ | ||
import { useApi } from '@domains/chains/pjs-api' | ||
import { useLatestBlockNumber } from '@domains/chains/useLatestBlockNumber' | ||
import { expectedBlockTime } from '@domains/common/substratePolyfills' | ||
import { VestingSchedule } from '@domains/multisig' | ||
import { useMemo } from 'react' | ||
import { Tooltip } from './ui/tooltip' | ||
import { secondsToDuration } from '@util/misc' | ||
import { cn } from '@util/tailwindcss' | ||
|
||
export const VestingDateRange: React.FC<{ | ||
chainGenesisHash: string | ||
vestingSchedule: VestingSchedule | ||
className?: string | ||
}> = ({ chainGenesisHash, className, vestingSchedule }) => { | ||
const { api } = useApi(chainGenesisHash) | ||
const blockNumber = useLatestBlockNumber(chainGenesisHash) | ||
const blockTime = useMemo(() => { | ||
if (!api) return | ||
return expectedBlockTime(api) | ||
}, [api]) | ||
|
||
const startDate = useMemo(() => { | ||
if (blockNumber === undefined || blockTime === undefined) return undefined | ||
|
||
const now = new Date() | ||
const blocksDiff = vestingSchedule.start - blockNumber | ||
const msDiff = blocksDiff * blockTime.toNumber() | ||
return new Date(now.getTime() + msDiff) | ||
}, [blockNumber, blockTime, vestingSchedule.start]) | ||
|
||
const endDate = useMemo(() => { | ||
if (blockNumber === undefined || blockTime === undefined) return undefined | ||
|
||
const now = new Date() | ||
const blocksDiff = vestingSchedule.start + vestingSchedule.period - blockNumber | ||
const msDiff = blocksDiff * blockTime.toNumber() | ||
return new Date(now.getTime() + msDiff) | ||
}, [blockNumber, blockTime, vestingSchedule.period, vestingSchedule.start]) | ||
|
||
const startDateString = startDate?.toLocaleDateString() | ||
const endDateString = endDate?.toLocaleDateString() | ||
const sameDay = startDateString === endDateString | ||
const duration = useMemo(() => { | ||
if (blockTime === undefined) return undefined | ||
return vestingSchedule.period * blockTime.toNumber() | ||
}, [blockTime, vestingSchedule.period]) | ||
|
||
return ( | ||
<Tooltip | ||
delayDuration={300} | ||
content={ | ||
<p className="text-[14px]"> | ||
{startDate?.toLocaleString()} → {endDate?.toLocaleString()} | ||
</p> | ||
} | ||
> | ||
<p className={cn('text-right text-offWhite text-[14px] cursor-default', className)}> | ||
{sameDay ? `${startDateString}, ` : ''} | ||
{sameDay ? `≈${startDate?.toLocaleTimeString()}` : startDateString} →{' '} | ||
{sameDay ? `≈${endDate?.toLocaleTimeString()}` : endDate?.toLocaleDateString()} | ||
{!!duration && ( | ||
<span className="text-right text-gray-200 text-[14px]"> (≈{secondsToDuration(duration)})</span> | ||
)} | ||
</p> | ||
</Tooltip> | ||
) | ||
} |
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,81 @@ | ||
import * as React from 'react' | ||
|
||
import { cn } from '@util/tailwindcss' | ||
|
||
const Table = React.forwardRef<HTMLTableElement, React.HTMLAttributes<HTMLTableElement>>( | ||
({ className, ...props }, ref) => ( | ||
<div className="relative w-full overflow-auto"> | ||
<table ref={ref} className={cn('w-full caption-bottom text-[16px]', className)} {...props} /> | ||
</div> | ||
) | ||
) | ||
Table.displayName = 'Table' | ||
|
||
const TableHeader = React.forwardRef<HTMLTableSectionElement, React.HTMLAttributes<HTMLTableSectionElement>>( | ||
({ className, ...props }, ref) => ( | ||
<thead ref={ref} className={cn('[&_tr]:border-b border-gray-500 bg-gray-800', className)} {...props} /> | ||
) | ||
) | ||
TableHeader.displayName = 'TableHeader' | ||
|
||
const TableBody = React.forwardRef<HTMLTableSectionElement, React.HTMLAttributes<HTMLTableSectionElement>>( | ||
({ className, ...props }, ref) => ( | ||
<tbody ref={ref} className={cn('[&_tr:last-child]:border-0 border-gray-500', className)} {...props} /> | ||
) | ||
) | ||
TableBody.displayName = 'TableBody' | ||
|
||
const TableFooter = React.forwardRef<HTMLTableSectionElement, React.HTMLAttributes<HTMLTableSectionElement>>( | ||
({ className, ...props }, ref) => ( | ||
<tfoot | ||
ref={ref} | ||
className={cn('border-t border-gray-500 bg-muted/50 font-medium [&>tr]:last:border-b-0', className)} | ||
{...props} | ||
/> | ||
) | ||
) | ||
TableFooter.displayName = 'TableFooter' | ||
|
||
const TableRow = React.forwardRef<HTMLTableRowElement, React.HTMLAttributes<HTMLTableRowElement>>( | ||
({ className, ...props }, ref) => ( | ||
<tr | ||
ref={ref} | ||
className={cn( | ||
'border-b border-gray-500 transition-colors hover:bg-gray-800/50 data-[state=selected]:bg-muted text-[14px]', | ||
className | ||
)} | ||
{...props} | ||
/> | ||
) | ||
) | ||
TableRow.displayName = 'TableRow' | ||
|
||
const TableHead = React.forwardRef<HTMLTableCellElement, React.ThHTMLAttributes<HTMLTableCellElement>>( | ||
({ className, ...props }, ref) => ( | ||
<th | ||
ref={ref} | ||
className={cn( | ||
'h-12 p-[8px] text-left align-middle font-medium text-gray-200 [&:has([role=checkbox])]:pr-0', | ||
className | ||
)} | ||
{...props} | ||
/> | ||
) | ||
) | ||
TableHead.displayName = 'TableHead' | ||
|
||
const TableCell = React.forwardRef<HTMLTableCellElement, React.TdHTMLAttributes<HTMLTableCellElement>>( | ||
({ className, ...props }, ref) => ( | ||
<td ref={ref} className={cn('p-[8px] align-middle [&:has([role=checkbox])]:pr-0', className)} {...props} /> | ||
) | ||
) | ||
TableCell.displayName = 'TableCell' | ||
|
||
const TableCaption = React.forwardRef<HTMLTableCaptionElement, React.HTMLAttributes<HTMLTableCaptionElement>>( | ||
({ className, ...props }, ref) => ( | ||
<caption ref={ref} className={cn('mt-4 text-[12px] text-muted-foreground', className)} {...props} /> | ||
) | ||
) | ||
TableCaption.displayName = 'TableCaption' | ||
|
||
export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption } |
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
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
Oops, something went wrong.