Skip to content

πŸ’„ Reusable ASA search table #987

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

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
100 changes: 89 additions & 11 deletions components/LaunchPad/Sale/CreateTokenSale.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import React, { useContext, useState } from 'react'
import React, { useContext, useEffect, useState } from 'react'
import { CreatorAddress } from '../CreatorAddress'
import { Note } from '../note'

Expand All @@ -28,6 +28,27 @@ import Button from '@mui/material/Button'
import OutlinedInput from '@/components/Input/OutlinedInput'
import { styles } from '../styles.css'
import { WalletReducerContext } from '@/hooks/WalletsReducerProvider'
import { TokenSearchInput } from '../TokenSearchInput'

const columns = [
{
id: 'symbol',
label: 'Symbol'
},
{
id: 'assetName',
label: 'Name'
},
{
id: 'assetId',
label: 'AssetId'
},
{
id: 'availableBalance',
label: 'Available Balance',
format: (value) => value.toLocaleString('en-US')
}
]

const initialValues = {
assetId: '',
Expand All @@ -39,12 +60,71 @@ export const CreateTokenSale = () => {
const { activeWallet } = useContext(WalletReducerContext)
const [loading, setLoading] = useState(false)
const [formData, setFormData] = useState(initialValues)
const [assetList, setAssetList] = useState([])

const { assetId, quantity, perUnit } = formData

const onChange = (e) => {
setFormData({ ...formData, [e.target.name]: e.target.value })
}

const fetchUserAssets = () => {
setAssetList([
{
assetId: 7789624,
symbol: 'BUSD',
assetName: 'BUSD Token',
availableBalance: 300000
},
{
assetId: 6789654,
symbol: 'UCDC',
assetName: 'UCDC Token',
availableBalance: 200000
},
{
assetId: 3789654,
symbol: 'goBTC',
assetName: 'goBTC',
availableBalance: 240000
},
{
assetId: 6789654,
symbol: 'UCDC',
assetName: 'UCDC',
availableBalance: 100000
},
{
assetId: 6789654,
symbol: 'UCDC',
assetName: 'UCDC',
availableBalance: 200000
},
{
assetId: 6789654,
symbol: 'UCDC',
assetName: 'UCDC',
availableBalance: 200000
},
{
assetId: 6789654,
symbol: 'UCDC',
assetName: 'UCDC',
availableBalance: 200000
},
{
assetId: 6789654,
symbol: 'UCDC',
assetName: 'UCDC',
availableBalance: 200000
}
])
}

useEffect(() => {
fetchUserAssets()
}, [])

const onSubmit = async (e) => {
e.preventDefault()

Expand Down Expand Up @@ -80,16 +160,14 @@ export const CreateTokenSale = () => {
<Typography variant="subtitle2" sx={{ ...styles.subtitle2, mb: '13px' }}>
Choose Asset:
</Typography>
<Box className="mb-4 px-4">
<OutlinedInput
type="text"
placeholder="ASA Asset ID"
name="assetId"
value={assetId}
onChange={(e) => onChange(e)}
sx={styles.input}
/>
</Box>
<TokenSearchInput
name="assetId"
value={assetId}
placeholder="ASA Asset ID"
onChange={onChange}
columns={columns}
rowData={assetList}
/>
</Box>

<Box className="mb-10">
Expand Down
100 changes: 89 additions & 11 deletions components/LaunchPad/Sale/ManageTokenSale.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import React, { useContext, useState } from 'react'
import React, { useContext, useEffect, useState } from 'react'
import { CreatorAddress } from '../CreatorAddress'
import { Icon } from '@iconify/react'

Expand All @@ -30,6 +30,7 @@ import { styles } from '../styles.css'
import { CopyIcon } from '../copyIcon'
import { LinearProgressWithLabel } from '../progressBar'
import { WalletReducerContext } from '@/hooks/WalletsReducerProvider'
import { TokenSearchInput } from '../TokenSearchInput'

const initialValues = {
tokenName: '',
Expand All @@ -39,9 +40,30 @@ const initialValues = {
showTotalForSale: false
}

const columns = [
{
id: 'symbol',
label: 'Symbol'
},
{
id: 'assetName',
label: 'Name'
},
{
id: 'assetId',
label: 'AssetId'
},
{
id: 'availableBalance',
label: 'Available Balance',
format: (value) => value.toLocaleString('en-US')
}
]

export const ManageTokenSale = () => {
const { activeWallet } = useContext(WalletReducerContext)
const [formData, setFormData] = useState(initialValues)
const [assetList, setAssetList] = useState([])
const { tokenName, pricePerToken, showPricePerToken, totalForSale, showTotalForSale } = formData

const onChange = (e) => {
Expand All @@ -61,6 +83,63 @@ export const ManageTokenSale = () => {
e.preventDefault()
}

const fetchUserAssets = () => {
setAssetList([
{
assetId: 7789624,
symbol: 'BUSD',
assetName: 'BUSD Token',
availableBalance: 300000
},
{
assetId: 6789654,
symbol: 'UCDC',
assetName: 'UCDC Token',
availableBalance: 200000
},
{
assetId: 3789654,
symbol: 'goBTC',
assetName: 'goBTC',
availableBalance: 240000
},
{
assetId: 6789654,
symbol: 'UCDC',
assetName: 'UCDC',
availableBalance: 100000
},
{
assetId: 6789654,
symbol: 'UCDC',
assetName: 'UCDC',
availableBalance: 200000
},
{
assetId: 6789654,
symbol: 'UCDC',
assetName: 'UCDC',
availableBalance: 200000
},
{
assetId: 6789654,
symbol: 'UCDC',
assetName: 'UCDC',
availableBalance: 200000
},
{
assetId: 6789654,
symbol: 'UCDC',
assetName: 'UCDC',
availableBalance: 200000
}
])
}

useEffect(() => {
fetchUserAssets()
}, [])

return (
<>
<Typography variant="subtitle1" sx={styles.title}>
Expand Down Expand Up @@ -89,16 +168,15 @@ export const ManageTokenSale = () => {
<Typography variant="subtitle2" sx={{ ...styles.subtitle2, mb: '13px' }}>
Choose Sale to Manage:
</Typography>
<Box className="mb-4 px-4">
<OutlinedInput
type="text"
placeholder="Token Name"
name="tokenName"
value={tokenName}
onChange={(e) => onChange(e)}
sx={styles.input}
/>
</Box>

<TokenSearchInput
name="tokenName"
value={tokenName}
placeholder="Token Name"
onChange={onChange}
columns={columns}
rowData={assetList}
/>
<Typography variant="body1" sx={{ ...styles.body1, marginBottom: '29px' }}>
Search with Asset Name or Asset ID - Only ASAs created by the currently connected wallet
will show as options.
Expand Down
Loading