-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add components for positions and transaction history
- Loading branch information
Showing
5 changed files
with
182 additions
and
115 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,46 @@ | ||
import useMangoGroup from 'hooks/useMangoGroup' | ||
import { useMemo } from 'react' | ||
import useMangoAccount from 'hooks/useMangoAccount' | ||
import { STAKEABLE_TOKENS } from 'pages' | ||
|
||
const Positions = () => { | ||
const { mangoAccount } = useMangoAccount() | ||
const { group } = useMangoGroup() | ||
|
||
const banks = useMemo(() => { | ||
if (!group) return [] | ||
const positionBanks = [] | ||
for (const token of STAKEABLE_TOKENS) { | ||
const tokenName = token === 'mSOL' ? 'MSOL' : token | ||
const bank = group.banksMapByName.get(tokenName)?.[0] | ||
positionBanks.push(bank) | ||
} | ||
return positionBanks | ||
}, [group]) | ||
|
||
const positions = useMemo(() => { | ||
if (!banks.length || !mangoAccount) return [] | ||
const positions = [] | ||
for (const bank of banks) { | ||
let balance = 0 | ||
if (bank) { | ||
balance = mangoAccount.getTokenBalanceUi(bank) | ||
} | ||
positions.push({ balance, bank }) | ||
} | ||
return positions | ||
}, [banks, mangoAccount]) | ||
|
||
console.log(banks) | ||
console.log(positions) | ||
|
||
return positions.length ? ( | ||
<div></div> | ||
) : ( | ||
<div className="flex justify-center rounded-2xl border border-th-fgd-1 p-6"> | ||
<span>No positions found</span> | ||
</div> | ||
) | ||
} | ||
|
||
export default Positions |
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,79 @@ | ||
import { STAKEABLE_TOKENS } from 'pages' | ||
import TokenButton from './TokenButton' | ||
import { useCallback, useEffect, useState } from 'react' | ||
import mangoStore from '@store/mangoStore' | ||
import { ACCOUNT_PREFIX } from 'utils/transactions' | ||
import TabUnderline from './shared/TabUnderline' | ||
import StakeForm from '@components/StakeForm' | ||
import UnstakeForm from '@components/UnstakeForm' | ||
import AccountStats from './AccountStats' | ||
|
||
const set = mangoStore.getState().set | ||
|
||
const Stake = () => { | ||
const [activeFormTab, setActiveFormTab] = useState('Add') | ||
const [selectedToken, setSelectedToken] = useState(STAKEABLE_TOKENS[0]) | ||
|
||
useEffect(() => { | ||
const mangoAccounts = mangoStore.getState().mangoAccounts | ||
const selectedMangoAccount = mangoAccounts.find( | ||
(ma) => ma.name === `${ACCOUNT_PREFIX}${selectedToken}`, | ||
) | ||
console.log('selectedMangoAccount', selectedMangoAccount) | ||
|
||
set((s) => { | ||
s.mangoAccount.current = selectedMangoAccount | ||
}) | ||
}, [selectedToken]) | ||
|
||
const onClose = useCallback(() => { | ||
console.log('StakeForm onSuccess') | ||
}, []) | ||
|
||
const handleTokenSelect = useCallback((token: string) => { | ||
setSelectedToken(token) | ||
}, []) | ||
|
||
return ( | ||
<> | ||
<div className="grid grid-cols-5 rounded-t-2xl border border-b-0 border-th-fgd-1"> | ||
{STAKEABLE_TOKENS.map((token) => ( | ||
<TokenButton | ||
key={token} | ||
handleTokenSelect={handleTokenSelect} | ||
selectedToken={selectedToken} | ||
tokenName={token} | ||
/> | ||
))} | ||
</div> | ||
<div className="grid max-w-4xl grid-cols-12"> | ||
<div | ||
className={`col-span-7 rounded-bl-2xl border border-th-fgd-1 bg-th-bkg-1 text-th-fgd-1`} | ||
> | ||
<div className={`p-8 pt-6`}> | ||
<div className="pb-2"> | ||
<TabUnderline | ||
activeValue={activeFormTab} | ||
values={['Add', 'Remove']} | ||
onChange={(v) => setActiveFormTab(v)} | ||
/> | ||
</div> | ||
{activeFormTab === 'Add' ? ( | ||
<StakeForm onSuccess={onClose} token={selectedToken} /> | ||
) : null} | ||
{activeFormTab === 'Remove' ? ( | ||
<UnstakeForm onSuccess={onClose} token={selectedToken} /> | ||
) : null} | ||
</div> | ||
</div> | ||
<div | ||
className={`col-span-5 rounded-br-2xl border-y border-r border-th-fgd-1 bg-th-bkg-2 p-8 pt-6`} | ||
> | ||
<AccountStats token={selectedToken} /> | ||
</div> | ||
</div> | ||
</> | ||
) | ||
} | ||
|
||
export default Stake |
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,9 @@ | ||
const TransactionHistory = () => { | ||
return ( | ||
<div className="flex justify-center rounded-2xl border border-th-fgd-1 p-6"> | ||
<span>No transaction history found</span> | ||
</div> | ||
) | ||
} | ||
|
||
export default TransactionHistory |
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