@huma-finance/widgets 0.0.62-beta.611 → 0.0.62-beta.617

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9504,21 +9504,41 @@ function Transfer$2(_ref) {
9504
9504
  } = poolInfo.underlyingMint;
9505
9505
  const supplyBigNumber = shared.SolanaTokenUtils.parseUnits(String(supplyAmount), decimals);
9506
9506
  const [transaction, setTransaction] = React.useState();
9507
+ const {
9508
+ juniorLenderApprovedAccountPDA,
9509
+ seniorLenderApprovedAccountPDA,
9510
+ seniorLenderStateAccount,
9511
+ juniorLenderStateAccount,
9512
+ loading: isLoadingLenderAccounts
9513
+ } = webShared.useLenderAccounts(poolInfo.chainId, poolInfo.poolName);
9507
9514
  const program = webShared.useHumaProgram(poolInfo.chainId);
9508
9515
  const handleSuccess = React.useCallback(() => {
9509
9516
  dispatch(setStep(WIDGET_STEP.Done));
9510
9517
  }, [dispatch]);
9511
9518
  React.useEffect(() => {
9512
9519
  async function getTx() {
9513
- if (!publicKey || transaction) {
9520
+ if (!publicKey || transaction || isLoadingLenderAccounts) {
9514
9521
  return;
9515
9522
  }
9523
+ const tx = new web3_js.Transaction();
9516
9524
  const {
9517
9525
  underlyingTokenATA,
9518
9526
  seniorTrancheATA,
9519
9527
  juniorTrancheATA
9520
9528
  } = shared.getTokenAccounts(poolInfo, publicKey);
9521
- const tx = await program.methods.deposit(supplyBigNumber).accountsPartial({
9529
+ if (selectedTranche === 'senior' && !seniorLenderStateAccount || selectedTranche === 'junior' && !juniorLenderStateAccount) {
9530
+ const createLenderAccountsTx = await program.methods.createLenderAccounts().accountsPartial({
9531
+ lender: publicKey,
9532
+ humaConfig: poolInfo.humaConfig,
9533
+ poolConfig: poolInfo.poolConfig,
9534
+ approvedLender: selectedTranche === 'senior' ? seniorLenderApprovedAccountPDA : juniorLenderApprovedAccountPDA,
9535
+ trancheMint: selectedTranche === 'senior' ? poolInfo.seniorTrancheMint : poolInfo.juniorTrancheMint,
9536
+ lenderTrancheToken: selectedTranche === 'senior' ? seniorTrancheATA : juniorTrancheATA,
9537
+ tokenProgram: splToken.TOKEN_2022_PROGRAM_ID
9538
+ }).transaction();
9539
+ tx.add(createLenderAccountsTx);
9540
+ }
9541
+ const depositTx = await program.methods.deposit(supplyBigNumber).accountsPartial({
9522
9542
  depositor: publicKey,
9523
9543
  poolConfig: poolInfo.poolConfig,
9524
9544
  underlyingMint: poolInfo.underlyingMint.address,
@@ -9529,10 +9549,16 @@ function Transfer$2(_ref) {
9529
9549
  humaConfig: poolInfo.humaConfig,
9530
9550
  tokenProgram: splToken.TOKEN_2022_PROGRAM_ID
9531
9551
  }).transaction();
9552
+ tx.add(depositTx);
9532
9553
  setTransaction(tx);
9533
9554
  }
9534
9555
  getTx();
9535
- }, [poolInfo, program.methods, publicKey, selectedTranche, supplyBigNumber, transaction]);
9556
+ }, [isLoadingLenderAccounts, juniorLenderApprovedAccountPDA, juniorLenderStateAccount, poolInfo, program.methods, publicKey, selectedTranche, seniorLenderApprovedAccountPDA, seniorLenderStateAccount, supplyBigNumber, transaction]);
9557
+ if (isLoadingLenderAccounts) {
9558
+ return jsxRuntime.jsx(LoadingModal, {
9559
+ title: "Supply"
9560
+ });
9561
+ }
9536
9562
  return jsxRuntime.jsx(SolanaTxSendModal, {
9537
9563
  tx: transaction,
9538
9564
  chainId: poolInfo.chainId,