Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add Wrapped Token Button #156

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components/Modal/WrapTokenModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useAccount, useNetwork } from 'wagmi'
import { ActionState, formatNumberWithStyle } from '~/utils'
import { useStoreActions } from '~/store'
import { handleTransactionError, useBalance, useEthersSigner, useGeb, useTokenApproval, ApprovalState } from '~/hooks'
import { useAddTokens } from '~/hooks'

import styled from 'styled-components'
import { Flex, HaiButton, Text, CenteredFlex } from '~/styles'
Expand Down Expand Up @@ -34,6 +35,8 @@ export function WrapTokenModal(props: ModalProps) {
const signer = useEthersSigner()
const geb = useGeb()

const { addTokens } = useAddTokens({ isHaiVelo: true })

const [action] = useState(Action.WRAP)

const {
Expand Down Expand Up @@ -148,6 +151,9 @@ export function WrapTokenModal(props: ModalProps) {
>
{approvalState === ApprovalState.NOT_APPROVED ? 'Approve' : 'Mint haiVELO'}
</HaiButton>
<HaiButton $variant="greenish" onClick={addTokens}>
Add haiVELO
</HaiButton>
</Footer>
}
>
Expand Down
9 changes: 7 additions & 2 deletions src/hooks/useAddTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ import { useStoreActions, useStoreState } from '~/store'
const hostedTokenImages = {
HAI: 'https://i.postimg.cc/QdVYkNcp/hai-logo.jpg',
KITE: 'https://i.postimg.cc/Z5g7fkLX/kite-logo.jpg',
HAIVELO: 'https://i.postimg.cc/66YBwPjp/hai-velo.png',
}

export function useAddTokens() {
export function useAddTokens({ isHaiVelo = false }: { isHaiVelo?: boolean } = {}) {
const { address } = useAccount()

const tokenImages = isHaiVelo
? { HAIVELO: hostedTokenImages['HAIVELO'] }
: { HAI: hostedTokenImages['HAI'], KITE: hostedTokenImages['KITE'] }

const {
connectWalletModel: { tokensData },
} = useStoreState((state) => state)
Expand All @@ -31,7 +36,7 @@ export function useAddTokens() {
})
try {
const wasAdded = await addTokensToMetamask(
Object.entries(hostedTokenImages).map(([token, image]) => ({
Object.entries(tokenImages).map(([token, image]) => ({
type: 'ERC20',
options: {
...tokensData[token],
Expand Down
Loading