Skip to content

Commit

Permalink
feat: bonding assets for incentives (#555)
Browse files Browse the repository at this point in the history
  • Loading branch information
nick134-bit authored Apr 9, 2024
1 parent 9ca0c42 commit 25a5109
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
2 changes: 2 additions & 0 deletions components/AssetInput/AssetInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface AssetInputProps {
unbondingBalances?: TokenBalance[]
mobile?: boolean
fee?: any
isIncentives?: boolean
}

const AssetInput = forwardRef((props: AssetInputProps, _) => {
Expand All @@ -44,6 +45,7 @@ const AssetInput = forwardRef((props: AssetInputProps, _) => {
hideDollarValue,
mobile,
fee = null,
isIncentives,
} = props
const tokenInfo = useTokenInfo(token?.tokenSymbol)
const [maxClicked, setMaxClicked] = useState(false)
Expand Down
20 changes: 14 additions & 6 deletions components/AssetInput/AssetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type AssetListProps = {
amount?: number
isBonding?: boolean
unbondingBalances?: TokenBalance[]
isIncentives?: boolean
}

const AssetList: FC<AssetListProps> = ({
Expand All @@ -27,15 +28,22 @@ const AssetList: FC<AssetListProps> = ({
amount,
edgeTokenList = [],
isBonding = false,
isIncentives = false,
unbondingBalances = null,
}) => {
const [tokenList] = useTokenList()

const { network, chainId } = useRecoilValue(chainState)
const config = useConfig(network, chainId)
const tokens = isBonding
? config?.bonding_tokens
: [...tokenList?.tokensBySymbol?.values()].filter((token:any) => !token?.withoutPool)
const tokens = useMemo(() => {
if (!config) return [...(tokenList?.tokensBySymbol?.values() || [])].filter((token: any) => !token?.withoutPool);

let res = isBonding ? config.bonding_tokens : [...(tokenList?.tokensBySymbol?.values() || [])];

if (isIncentives) return res;

return res.length > 0 ? res : [...(tokenList?.tokensBySymbol?.values() || [])].filter((token: any) => !token?.withoutPool);
}, [config, isBonding, isIncentives, tokenList]);

const [tokenBalance = []] =
unbondingBalances
? [
Expand Down Expand Up @@ -81,7 +89,7 @@ const AssetList: FC<AssetListProps> = ({
},
}}
>
{filterAssets.map((item, index) => (
{filterAssets?.map((item, index) => (
<HStack
key={item?.name}
as={Button}
Expand All @@ -99,7 +107,7 @@ const AssetList: FC<AssetListProps> = ({
tokenSymbol: item?.symbol,
amount,
},
true)
true)
}
>
<HStack>
Expand Down
3 changes: 3 additions & 0 deletions components/AssetInput/AssetSelectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface AssetSelectModalProps {
disabled: boolean
amount?: number
isBonding?: boolean
isIncentives?: boolean
unbondingBalances?: TokenBalance[]
}

Expand All @@ -35,6 +36,7 @@ const AssetSelectModal: FC<AssetSelectModalProps> = ({
disabled,
amount,
isBonding = false,
isIncentives = false,
unbondingBalances = null,
}) => {
const { isOpen, onOpen, onClose } = useDisclosure()
Expand Down Expand Up @@ -83,6 +85,7 @@ const AssetSelectModal: FC<AssetSelectModalProps> = ({
edgeTokenList={edgeTokenList}
currentToken={currentToken}
isBonding={isBonding}
isIncentives={isIncentives}
unbondingBalances={unbondingBalances}
/>
</ModalBody>
Expand Down
6 changes: 6 additions & 0 deletions components/AssetInput/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type Props = {
ignoreSlack?: boolean
showList?: boolean
mobile?: boolean
isBonding?: boolean
isIncentives?: boolean
}

const Input = ({
Expand All @@ -28,6 +30,8 @@ const Input = ({
fetchBalance = true,
ignoreSlack = false,
showList = false,
isBonding = false,
isIncentives = false,
mobile,
}: Props) => {
const { balance: tokenBalance } = useTokenBalance(token?.tokenSymbol)
Expand All @@ -46,6 +50,8 @@ const Input = ({
balance={fetchBalance ? tokenBalance : balance}
ignoreSlack={ignoreSlack}
showList={showList}
isBonding={isBonding}
isIncentives={isIncentives}
mobile={mobile}
onChange={(value) => {
onChange(value)
Expand Down
3 changes: 3 additions & 0 deletions components/AssetInput/WhaleInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface AssetInputProps {
hideToken?: string
edgeTokenList?: string[]
isBonding?: boolean
isIncentives?: boolean
unbondingBalances?: TokenBalance[]
}

Expand Down Expand Up @@ -84,6 +85,7 @@ const AssetInput: FC<AssetInputProps> = forwardRef(({
hideToken,
edgeTokenList,
isBonding = false,
isIncentives = false,
unbondingBalances = null,
},
ref) => {
Expand Down Expand Up @@ -149,6 +151,7 @@ ref) => {
disabled={disabled || !showList}
amount={token?.amount}
isBonding={isBonding}
isIncentives={isIncentives}
unbondingBalances={unbondingBalances}
>
<AssetSelectTrigger
Expand Down
10 changes: 6 additions & 4 deletions components/Pages/Trade/Incentivize/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,22 @@ const Create = ({ poolId }: Props) => {
const { isWalletConnected } = useChain(walletChainName)
const { txStep } = useRecoilValue(txRecoilState)
const [isMobile] = useMediaQuery('(max-width: 640px)')
const { simulate, submit } = useOpenFlow({ poolId,
...formData })
const { simulate, submit } = useOpenFlow({
poolId,
...formData
})

const startDate = formData.startDate === '' ? dayjs() : dayjs(formData.startDate)
const endDateMinimum = startDate.add(1, 'day')
const startDateInvalid = startDate.isBefore(dayjs(), 'day')

return (
<Stack as="form" gap="5" onSubmit={handleSubmit(() => submit())}>
<Input
name="token"
control={control}
token={token}
showList={true}
isIncentives={true}
mobile={isMobile}
onChange={(value) => {
setToken({
Expand Down Expand Up @@ -136,7 +138,7 @@ const Create = ({ poolId }: Props) => {
/>
</HStack>

<Divider opacity="0.2" paddingY={'2'}/>
<Divider opacity="0.2" paddingY={'2'} />
<HStack justifyContent="space-between">
<Text color="whiteAlpha.600">Fee</Text>
<Spacer />
Expand Down

0 comments on commit 25a5109

Please sign in to comment.