Skip to content

Commit

Permalink
first shadow action
Browse files Browse the repository at this point in the history
  • Loading branch information
xieqiancaosissi committed Jan 2, 2024
1 parent 1060344 commit 3f312a8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion api/get-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const getAccount = async () => {
if (accountId) {
const assets = await getAssetsDetailed();
const tokenIds = assets.map((asset) => asset.token_id);
const shadowRecords = await getShadowRecords(accountId);
const shadowRecords = await getShadowRecords();
const accountBalance = (await account.getAccountBalance()).available;
const balances = await Promise.all(
tokenIds.map((id) => getBalance(id, accountId, shadowRecords)),
Expand Down
5 changes: 4 additions & 1 deletion api/get-shadows.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { ViewMethodsREFV1, IShadowRecordInfo } from "../interfaces";
import { getBurrow } from "../utils";
import { getAccount as getAccountWallet } from "../utils/wallet-selector-compat";

const getShadowRecords = async (accountId: string): Promise<IShadowRecordInfo> => {
const getShadowRecords = async (): Promise<IShadowRecordInfo> => {
const account = await getAccountWallet();
const { accountId } = account;
const { view, refv1Contract } = await getBurrow();
const res = (await view(refv1Contract, ViewMethodsREFV1[ViewMethodsREFV1.get_shadow_records], {
account_id: accountId,
Expand Down
9 changes: 4 additions & 5 deletions components/Modal/Action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import { trackActionButton, trackUseAsCollateral } from "../../utils/telemetry";
import { useDegenMode } from "../../hooks/hooks";
import { SubmitButton, AlertWarning } from "./components";
import { getAccountPortfolio } from "../../redux/accountSelectors";
import getShadowRecords from "../../api/get-shadows";

export default function Action({ maxBorrowAmount, healthFactor, collateralType }) {
const [loading, setLoading] = useState(false);
const { amount, useAsCollateral, isMax } = useAppSelector(getSelectedValues);
const dispatch = useAppDispatch();
const asset = useAppSelector(getAssetData);
const portfolio = useAppSelector(getAccountPortfolio);
const { action = "Deposit", tokenId, isLpToken, decimals } = asset;
const { isRepayFromDeposits } = useDegenMode();

Expand Down Expand Up @@ -61,16 +61,15 @@ export default function Action({ maxBorrowAmount, healthFactor, collateralType }
if (tokenId === nearTokenId) {
await deposit({ amount, useAsCollateral, isMax });
} else if (isLpToken) {
const isRegistered = !!(
portfolio?.supplied?.[tokenId] || portfolio?.positions?.[tokenId]?.collateral?.[tokenId]
);
const shadowRecords = await getShadowRecords();
const pool_id = tokenId.split("-")[1];
await shadow_action_supply({
tokenId,
decimals: +(decimals || 0) + +extraDecimals,
useAsCollateral,
amount,
isMax,
isRegistered,
isRegistered: !!shadowRecords?.[pool_id],
});
} else {
await supply({
Expand Down

0 comments on commit 3f312a8

Please sign in to comment.