This repository has been archived by the owner on Nov 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add kton staking migration logic and instruction in koi testnet (#20)
* Add kton migrate in koi testnet * Add instruction * Remove useless change * Rename files * Fix lint issues * Update src/config/v2migrate.ts * Update src/config/v2migrate.ts * Update src/config/v2migrate.ts --------- Co-authored-by: Gege Li <[email protected]> Co-authored-by: fisher <[email protected]>
- Loading branch information
1 parent
a787209
commit 041fa70
Showing
18 changed files
with
429 additions
and
79 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
|
@@ -24,4 +24,4 @@ | |
transform: scale(0.5); | ||
opacity: 0.3; | ||
} | ||
} | ||
} |
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,112 @@ | ||
import { useAccount } from "wagmi"; | ||
import { useEffect } from "react"; | ||
|
||
import { useBigIntContractQuery } from "@/hooks/useBigIntContractQuery"; | ||
import { useChain } from "@/hooks/useChain"; | ||
import { ActionProps } from "@/types/action"; | ||
import { abi } from '@/config/abi/KTONStakingRewards'; | ||
import { usePoolAmount } from "@/hooks/usePoolAmount"; | ||
import { useMigrate } from "@/hooks/useMigrate"; | ||
import { useMigrateState } from "@/hooks/useMigrateState"; | ||
import { formatNumericValue } from "@/utils"; | ||
import { Button } from '@/components/ui/button'; | ||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'; | ||
|
||
import Loading from "./loading"; | ||
|
||
const newPoolButtonText = "Stake in new pool"; | ||
const newPoolUrl = "https://kton-staking-v2.darwinia.network" | ||
|
||
const Migrate = ({ onTransactionActiveChange }: ActionProps) => { | ||
const { address, isConnected } = useAccount(); | ||
const { isSupportedChainId, activeChain } = useChain(); | ||
const { refetch: refetchPoolAmount } = usePoolAmount(); | ||
|
||
const { value, formatted, isLoadingOrRefetching, refetch: refetchBalance } = useBigIntContractQuery({ | ||
contractAddress: activeChain.stakingContractAddress, | ||
abi, | ||
functionName: 'balanceOf', | ||
args: [address!], | ||
forceEnabled: isSupportedChainId | ||
}); | ||
|
||
const { migrate, isMigrating, isTransactionConfirming } = useMigrate({ | ||
ownerAddress: address!, | ||
onSuccess() { | ||
refetchBalance(); | ||
refetchPoolAmount(); | ||
} | ||
}); | ||
|
||
const { buttonText, isButtonDisabled, isFetching } = useMigrateState({ | ||
isConnected, | ||
isSupportedChainId, | ||
isMigrating, | ||
isTransactionConfirming, | ||
isLoadingOrRefetching, | ||
value | ||
}); | ||
|
||
const balanceAmount = formatNumericValue(formatted); | ||
|
||
const openInNewTab = (url: string) => { | ||
window.open(url, '_blank', 'noopener,noreferrer'); | ||
} | ||
|
||
useEffect(() => { | ||
const isActive = isMigrating || isTransactionConfirming; | ||
onTransactionActiveChange && onTransactionActiveChange(isActive); | ||
}, [isMigrating, isTransactionConfirming, onTransactionActiveChange]); | ||
|
||
return ( | ||
<div> | ||
<div className="flex h-[4.5rem] items-center justify-center gap-3 self-stretch rounded-[0.3125rem] bg-[#1A1D1F]"> | ||
{isLoadingOrRefetching ? ( | ||
<Loading className="ml-2 gap-1" itemClassName="size-2" /> | ||
) : ( | ||
<TooltipProvider> | ||
<Tooltip delayDuration={0}> | ||
<TooltipTrigger asChild> | ||
<div> | ||
<span className=" text-[1.5rem] font-bold leading-normal text-white"> | ||
{balanceAmount?.integerPart} | ||
</span> | ||
{balanceAmount?.decimalPart ? ( | ||
<span className=" text-[1.5rem] font-bold leading-normal text-white/50"> | ||
.{balanceAmount?.decimalPart} | ||
</span> | ||
) : null} | ||
</div> | ||
</TooltipTrigger> | ||
<TooltipContent asChild> | ||
<span>{balanceAmount?.originalFormatNumberWithThousandsSeparator}</span> | ||
</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
)} | ||
<span className=" text-[1.5rem] font-bold leading-normal text-white"> | ||
{activeChain?.ktonToken.symbol} | ||
</span> | ||
</div> | ||
<Button | ||
disabled={isButtonDisabled} | ||
isLoading={isMigrating || isTransactionConfirming} | ||
type="button" | ||
onClick={migrate} | ||
className="mt-5 w-full rounded-[0.3125rem] text-[0.875rem] text-white" | ||
> | ||
{isFetching ? <span className="animate-pulse"> {buttonText}</span> : buttonText} | ||
</Button> | ||
<Button | ||
type="button" | ||
onClick={() => openInNewTab(newPoolUrl)} | ||
className="mt-5 w-full rounded-[0.3125rem] text-[0.875rem] text-white" | ||
> | ||
{newPoolButtonText} | ||
</Button> | ||
</div> | ||
); | ||
|
||
} | ||
|
||
export default Migrate; |
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,34 @@ | ||
"use client"; | ||
import { useState } from 'react'; | ||
|
||
import { cn } from '@/lib/utils'; | ||
|
||
import { Button } from './ui/button'; | ||
|
||
const title = "We are migrating"; | ||
const instruction = "Please migrate to new KTON Pool and get your gKTON reward. To migrate, please follow steps below:" | ||
const stepContents = [`Step 1:Click \"Unstake\" button to unstake your KTON`, `Step 2:Click \"Stake in new pool\" button to stake your KTON`]; | ||
const buttonText = "Start Migration"; | ||
|
||
export default function MigrationPopover() { | ||
const [open, setOpen] = useState(true); | ||
|
||
return ( | ||
open && <div className="absolute h-[360px] w-[480px] flex justify-center items-center rounded-[20px] bg-[#242A2E]"> | ||
<div className='h-full w-full px-[20px] font-mono'> | ||
<h1 className='text-center font-extrabold py-[15px]'>{title}</h1> | ||
<div className='h-[1px] bg-[rgba(255,255,255,0.1)]'></div> | ||
<div className='py-[20px]'> | ||
<p className='text-sm py-[10px]'>{instruction}</p> | ||
{stepContents.map((content, index) => { | ||
return <p className='text-center text-sm py-[10px] bg-[rgba(18,22,25)] mb-[10px]' key={index} style={{wordSpacing: '-3px', letterSpacing: '-0.5px'}}>{content}</p> | ||
})} | ||
</div> | ||
<div className='h-[1px] bg-[rgba(255,255,255,0.1)]'></div> | ||
<Button onClick={() => setOpen(false)} type="submit" | ||
className={cn('font-extrabold mt-5 w-full rounded-[0.3125rem] text-[0.875rem] text-white')} | ||
>{buttonText}</Button> | ||
</div> | ||
</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
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,2 +1,3 @@ | ||
export * from './crab'; | ||
export * from './darwinia'; | ||
export * from './koi'; |
Oops, something went wrong.