This commit is contained in:
juan 2021-01-27 12:45:16 -05:00
parent 404770aea1
commit e3df946feb
10 changed files with 61 additions and 42 deletions

View File

@ -126,8 +126,6 @@ export const borrow = async (
) )
: undefined; : undefined;
let amountLamports: number = 0; let amountLamports: number = 0;
let fromLamports: number = 0; let fromLamports: number = 0;
if (amountType === BorrowAmountType.LiquidityBorrowAmount) { if (amountType === BorrowAmountType.LiquidityBorrowAmount) {
@ -154,7 +152,6 @@ export const borrow = async (
fromLamports = amountLamports; fromLamports = amountLamports;
} }
const fromAccount = ensureSplAccount( const fromAccount = ensureSplAccount(
instructions, instructions,
finalCleanupInstructions, finalCleanupInstructions,
@ -197,7 +194,6 @@ export const borrow = async (
instructions = []; instructions = [];
cleanupInstructions = [...finalCleanupInstructions]; cleanupInstructions = [...finalCleanupInstructions];
// create approval for transfer transactions // create approval for transfer transactions
const transferAuthority = approve( const transferAuthority = approve(
instructions, instructions,
@ -205,7 +201,7 @@ export const borrow = async (
fromAccount, fromAccount,
wallet.publicKey, wallet.publicKey,
fromLamports, fromLamports,
false, false
); );
signers.push(transferAuthority); signers.push(transferAuthority);

View File

@ -205,7 +205,7 @@ export const BorrowInput = (props: {
flexDirection: "row", flexDirection: "row",
justifyContent: "space-evenly", justifyContent: "space-evenly",
alignItems: "center", alignItems: "center",
marginBottom: 20 marginBottom: 20,
}} }}
> >
<CollateralInput <CollateralInput

View File

@ -1,7 +1,11 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { cache, ParsedAccount } from "../../contexts/accounts"; import { cache, ParsedAccount } from "../../contexts/accounts";
import { useConnectionConfig } from "../../contexts/connection"; import { useConnectionConfig } from "../../contexts/connection";
import {useLendingReserves, useUserBalance, useUserDeposits} from "../../hooks"; import {
useLendingReserves,
useUserBalance,
useUserDeposits,
} from "../../hooks";
import { import {
LendingReserve, LendingReserve,
LendingMarket, LendingMarket,
@ -42,7 +46,7 @@ export default function CollateralInput(props: {
useEffect(() => { useEffect(() => {
if (props.useWalletBalance) { if (props.useWalletBalance) {
setBalance(tokenBalance) setBalance(tokenBalance);
} else { } else {
const id: string = const id: string =
cache cache
@ -77,26 +81,29 @@ export default function CollateralInput(props: {
(reserve) => (reserve) =>
!onlyQuoteAllowed || !onlyQuoteAllowed ||
reserve.info.liquidityMint.equals(market.info.quoteMint) reserve.info.liquidityMint.equals(market.info.quoteMint)
) );
if(!collateralReserve && props.useFirstReserve && filteredReserveAccounts.length) { if (
!collateralReserve &&
props.useFirstReserve &&
filteredReserveAccounts.length
) {
const address = filteredReserveAccounts[0].pubkey.toBase58(); const address = filteredReserveAccounts[0].pubkey.toBase58();
setCollateralReserve(address); setCollateralReserve(address);
} }
const renderReserveAccounts = filteredReserveAccounts const renderReserveAccounts = filteredReserveAccounts.map((reserve) => {
.map((reserve) => { const mint = reserve.info.liquidityMint.toBase58();
const mint = reserve.info.liquidityMint.toBase58(); const address = reserve.pubkey.toBase58();
const address = reserve.pubkey.toBase58(); const name = getTokenName(tokenMap, mint);
const name = getTokenName(tokenMap, mint); return (
return ( <Option key={address} value={address} name={name} title={address}>
<Option key={address} value={address} name={name} title={address}> <div key={address} style={{ display: "flex", alignItems: "center" }}>
<div key={address} style={{ display: "flex", alignItems: "center" }}> <TokenIcon mintAddress={mint} />
<TokenIcon mintAddress={mint} /> {name}
{name} </div>
</div> </Option>
</Option> );
); });
});
return ( return (
<Card <Card

View File

@ -148,7 +148,7 @@ export const cache = {
obj: AccountInfo<Buffer>, obj: AccountInfo<Buffer>,
parser?: AccountParser parser?: AccountParser
) => { ) => {
if(obj.data.length === 0) { if (obj.data.length === 0) {
return; return;
} }

View File

@ -39,7 +39,7 @@ export function approve(
) )
); );
if(autoRevoke) { if (autoRevoke) {
cleanupInstructions.push( cleanupInstructions.push(
Token.createRevokeInstruction(tokenProgram, account, owner, []) Token.createRevokeInstruction(tokenProgram, account, owner, [])
); );

View File

@ -18,7 +18,11 @@ export const BorrowView = () => {
<div></div> <div></div>
</div> </div>
{reserveAccounts.map((account) => ( {reserveAccounts.map((account) => (
<BorrowItem key={account.pubkey.toBase58()} reserve={account.info} address={account.pubkey} /> <BorrowItem
key={account.pubkey.toBase58()}
reserve={account.info}
address={account.pubkey}
/>
))} ))}
</Card> </Card>
</div> </div>

View File

@ -33,7 +33,10 @@ export const DashboardDeposits = () => {
<div></div> <div></div>
</div> </div>
{userDeposits.map((deposit) => ( {userDeposits.map((deposit) => (
<DepositItem key={deposit.account.pubkey.toBase58()} userDeposit={deposit} /> <DepositItem
key={deposit.account.pubkey.toBase58()}
userDeposit={deposit}
/>
))} ))}
</Card> </Card>
); );

View File

@ -23,9 +23,7 @@ export const DashboardView = () => {
/> />
{LABELS.DASHBOARD_INFO} {LABELS.DASHBOARD_INFO}
</div> </div>
): ) : userDeposits.length === 0 && userObligations.length === 0 ? (
userDeposits.length === 0 && userObligations.length === 0 ?
(
<div className="dashboard-info"> <div className="dashboard-info">
<img <img
src="splash.svg" src="splash.svg"
@ -34,17 +32,21 @@ export const DashboardView = () => {
/> />
{LABELS.NO_LOANS_NO_DEPOSITS} {LABELS.NO_LOANS_NO_DEPOSITS}
</div> </div>
): ( ) : (
<Row gutter={GUTTER}> <Row gutter={GUTTER}>
<Col md={24} xl={12} span={24}> <Col md={24} xl={12} span={24}>
{userDeposits.length > 0 ? {userDeposits.length > 0 ? (
<DashboardDeposits /> : <DashboardDeposits />
<Card>{LABELS.NO_DEPOSITS}</Card> } ) : (
<Card>{LABELS.NO_DEPOSITS}</Card>
)}
</Col> </Col>
<Col md={24} xl={12} span={24}> <Col md={24} xl={12} span={24}>
{userObligations.length > 0 ? {userObligations.length > 0 ? (
<DashboardObligations /> : <DashboardObligations />
<Card>{LABELS.NO_LOANS}</Card> } ) : (
<Card>{LABELS.NO_LOANS}</Card>
)}
</Col> </Col>
</Row> </Row>
)} )}

View File

@ -35,9 +35,12 @@ export const DashboardObligations = () => {
<div></div> <div></div>
</div> </div>
{userObligations.map((item) => { {userObligations.map((item) => {
return <ObligationItem return (
key={item.obligation.account.pubkey.toBase58()} <ObligationItem
obligation={item.obligation} />; key={item.obligation.account.pubkey.toBase58()}
obligation={item.obligation}
/>
);
})} })}
</Card> </Card>
); );

View File

@ -17,7 +17,11 @@ export const DepositView = () => {
<div></div> <div></div>
</div> </div>
{reserveAccounts.map((account) => ( {reserveAccounts.map((account) => (
<ReserveItem key={account.pubkey.toBase58()} reserve={account.info} address={account.pubkey} /> <ReserveItem
key={account.pubkey.toBase58()}
reserve={account.info}
address={account.pubkey}
/>
))} ))}
</Card> </Card>
</div> </div>