-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add vest all option in create vesting
- Loading branch information
1 parent
d4dc945
commit 8817157
Showing
8 changed files
with
189 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { useTokenAmountTypeContext } from "#/context/TokenAmountType"; | ||
import React, { useEffect } from "react"; | ||
import { useFormContext } from "react-hook-form"; | ||
|
||
export const FormCheckbox = ({ | ||
name, | ||
state, | ||
setState, | ||
label, | ||
}: { | ||
name: string; | ||
state: boolean; | ||
setState: (state: boolean) => void; | ||
label?: string; | ||
}) => { | ||
const { setValue } = useFormContext(); | ||
|
||
useEffect(() => { | ||
console.log("state", state); | ||
state ? setValue("amount", 1) : setValue("amount", 0); | ||
setValue(name, state); | ||
}, [state]); | ||
|
||
return ( | ||
<div className="flex items-center space-x-2"> | ||
<input | ||
type="checkbox" | ||
id={name} | ||
name={name} | ||
checked={state} | ||
onChange={() => setState(!state)} | ||
className="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600" | ||
/> | ||
<label | ||
htmlFor={name} | ||
className="text-sm font-medium text-gray-900 dark:text-gray-300" | ||
> | ||
{label} | ||
</label> | ||
</div> | ||
); | ||
}; | ||
|
||
export const VestAllFromSwapCheckbox = () => { | ||
const { vestAllFromSwap, setVestAllFromSwap } = useTokenAmountTypeContext(); | ||
return ( | ||
<FormCheckbox | ||
name="vestAllFromSwap" | ||
state={vestAllFromSwap} | ||
setState={setVestAllFromSwap} | ||
label="Use all tokens from swap" | ||
/> | ||
); | ||
}; | ||
|
||
export const VestAllCheckbox = () => { | ||
const { vestAll, setVestAll } = useTokenAmountTypeContext(); | ||
return ( | ||
<FormCheckbox | ||
name="vestAll" | ||
state={vestAll} | ||
setState={setVestAll} | ||
label="Use all your tokens after swap" | ||
/> | ||
); | ||
}; |
32 changes: 0 additions & 32 deletions
32
apps/create-vesting/src/components/VestAllFromSwapCheckbox.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
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,69 @@ | ||
import { | ||
TRANSACTION_TYPES, | ||
TransactionFactory, | ||
} from "@bleu/utils/transactionFactory"; | ||
import { useCallback } from "react"; | ||
import { GetHooksTransactionsParams } from "./useGetHooksTransactions"; | ||
import { | ||
BaseTransaction, | ||
IHooksInfo, | ||
useIFrameContext, | ||
} from "@bleu/cow-hooks-ui"; | ||
import { scaleToSecondsMapping } from "#/utils/scaleToSecondsMapping"; | ||
import { Address, maxUint256 } from "viem"; | ||
|
||
export const useGetHooksInfoVestAll = () => { | ||
const { context, cowShedProxy } = useIFrameContext(); | ||
|
||
return useCallback( | ||
async ( | ||
params: GetHooksTransactionsParams | ||
): Promise<IHooksInfo | undefined> => { | ||
const { | ||
token, | ||
vestingEscrowFactoryAddress, | ||
formData: { period, periodScale, recipient }, | ||
} = params; | ||
|
||
if (!context?.account || !cowShedProxy) return; | ||
|
||
const periodInSeconds = period * scaleToSecondsMapping[periodScale]; | ||
const tokenAddress = token.address as Address; | ||
const tokenSymbol = token.symbol ?? ""; | ||
|
||
const txs = await Promise.all([ | ||
// Approve create vesting | ||
TransactionFactory.createRawTx(TRANSACTION_TYPES.ERC20_APPROVE, { | ||
type: TRANSACTION_TYPES.ERC20_APPROVE, | ||
token: tokenAddress, | ||
spender: vestingEscrowFactoryAddress, | ||
amount: maxUint256, | ||
}), | ||
// transfer from user to proxy and create vesting (weiroll) | ||
TransactionFactory.createRawTx( | ||
TRANSACTION_TYPES.CREATE_VESTING_WEIROLL, | ||
{ | ||
type: TRANSACTION_TYPES.CREATE_VESTING_WEIROLL, | ||
token: tokenAddress, | ||
recipient: recipient, | ||
cowShedProxy, | ||
vestingDuration: BigInt(periodInSeconds), | ||
vestingEscrowFactoryAddress: vestingEscrowFactoryAddress, | ||
user: context.account, | ||
} | ||
), | ||
]); | ||
|
||
const permitData = [ | ||
{ | ||
tokenAddress: tokenAddress, | ||
amount: maxUint256, | ||
tokenSymbol: tokenSymbol, | ||
}, | ||
]; | ||
|
||
return { txs, permitData }; | ||
}, | ||
[context?.account, cowShedProxy] | ||
); | ||
}; |
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