diff --git a/src/components/BorrowInput/index.tsx b/src/components/BorrowInput/index.tsx index e6e2a10..a59db0e 100644 --- a/src/components/BorrowInput/index.tsx +++ b/src/components/BorrowInput/index.tsx @@ -34,16 +34,16 @@ export const BorrowInput = (props: { const borrowReserve = props.reserve; - const [collateralReserveMint, setCollateralReserveMint] = useState(); + const [collateralReserveKey, setCollateralReserveKey] = useState(); const collateralReserve = useMemo(() => { const id: string = cache .byParser(LendingReserveParser) - .find((acc) => acc === collateralReserveMint) || ""; + .find((acc) => acc === collateralReserveKey) || ""; return cache.get(id) as ParsedAccount; - }, [collateralReserveMint]); + }, [collateralReserveKey]); const name = useTokenName(borrowReserve?.info.liquidityMint); const { accounts: fromAccounts } = useUserBalance( @@ -51,7 +51,8 @@ export const BorrowInput = (props: { ); const { userObligationsByReserve } = useUserObligationByReserve( - borrowReserve.pubkey + borrowReserve?.pubkey, + collateralReserve?.pubkey, ); const onBorrow = useCallback(() => { @@ -74,6 +75,7 @@ export const BorrowInput = (props: { borrowReserve, collateralReserve, + // TODO: select exsisting obligations by collateral reserve userObligationsByReserve.length > 0 ? userObligationsByReserve[0].obligation : undefined, @@ -126,8 +128,8 @@ export const BorrowInput = (props: {
{LABELS.SELECT_COLLATERAL}
{LABELS.BORROW_QUESTION}
diff --git a/src/components/CollateralSelector/index.tsx b/src/components/CollateralSelector/index.tsx index 0603618..bb91b51 100644 --- a/src/components/CollateralSelector/index.tsx +++ b/src/components/CollateralSelector/index.tsx @@ -11,8 +11,9 @@ const { Option } = Select; export const CollateralSelector = (props: { reserve: LendingReserve; - mint?: string; - onMintChange: (id: string) => void; + collateralReserve?: string; + disabled?: boolean; + onCollateralReserve?: (id: string) => void; }) => { const { reserveAccounts } = useLendingReserves(); const { tokenMap } = useConnectionConfig(); @@ -20,8 +21,8 @@ export const CollateralSelector = (props: { const market = cache.get(props.reserve.lendingMarket) as ParsedAccount< LendingMarket >; - const onlyQuoteAllowed = !props.reserve.liquidityMint.equals( - market.info.quoteMint + const onlyQuoteAllowed = !props.reserve?.liquidityMint?.equals( + market?.info?.quoteMint ); return ( @@ -30,10 +31,12 @@ export const CollateralSelector = (props: { showSearch style={{ minWidth: 300 , margin: "5px 0px" }} placeholder="Collateral" - value={props.mint} + value={props.collateralReserve} + disabled={props.disabled} + defaultValue={props.collateralReserve} onChange={(item) => { - if (props.onMintChange) { - props.onMintChange(item); + if (props.onCollateralReserve) { + props.onCollateralReserve(item); } }} filterOption={(input, option) => diff --git a/src/components/RepayInput/index.tsx b/src/components/RepayInput/index.tsx index a1b1c64..353bb07 100644 --- a/src/components/RepayInput/index.tsx +++ b/src/components/RepayInput/index.tsx @@ -21,7 +21,8 @@ import { notify } from "../../utils/notifications"; export const RepayInput = (props: { className?: string; - reserve: ParsedAccount; + borrowReserve: ParsedAccount; + collateralReserve?: ParsedAccount; obligation: ParsedAccount; }) => { const connection = useConnection(); @@ -29,7 +30,7 @@ export const RepayInput = (props: { const [pendingTx, setPendingTx] = useState(false); const [showConfirmation, setShowConfirmation] = useState(false); - const repayReserve = props.reserve; + const repayReserve = props.borrowReserve; const obligation = props.obligation; const liquidityMint = useMint(repayReserve.info.liquidityMint); @@ -39,17 +40,7 @@ export const RepayInput = (props: { borrowAmountLamports, liquidityMint ); - - const [collateralReserveMint, setCollateralReserveMint] = useState(); - - const collateralReserve = useMemo(() => { - const id: string = - cache - .byParser(LendingReserveParser) - .find((acc) => acc === collateralReserveMint) || ""; - - return cache.get(id) as ParsedAccount; - }, [collateralReserveMint]); + const collateralReserve = props.collateralReserve; const name = useTokenName(repayReserve?.info.liquidityMint); const { accounts: fromAccounts } = useUserBalance( @@ -173,11 +164,11 @@ export const RepayInput = (props: { value={pct} onChange={setPct} /> -
{LABELS.SELECT_COLLATERAL}
+
{LABELS.COLLATERAL}