@huma-finance/widgets 0.0.62-beta.612 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huma-finance/widgets",
3
- "version": "0.0.62-beta.612+99e0987",
3
+ "version": "0.0.62-beta.617+10ec4cd",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -21,8 +21,6 @@
21
21
  "dependencies": {
22
22
  "@apollo/client": "^3.7.2",
23
23
  "@coinbase/wallet-sdk": "^3.5.3",
24
- "@emotion/react": "^11.5.0",
25
- "@emotion/styled": "^11.3.0",
26
24
  "@ethersproject/address": "^5.7.0",
27
25
  "@ethersproject/bignumber": "^5.6.0",
28
26
  "@ethersproject/constants": "^5.7.0",
@@ -30,14 +28,9 @@
30
28
  "@ethersproject/experimental": "^5.7.0",
31
29
  "@ethersproject/providers": "^5.6.0",
32
30
  "@ethersproject/units": "^5.6.0",
33
- "@huma-finance/sdk": "^0.0.62-beta.612+99e0987",
34
- "@huma-finance/shared": "^0.0.62-beta.612+99e0987",
35
- "@huma-finance/web-shared": "^0.0.62-beta.612+99e0987",
36
- "@mui/icons-material": "^5.3.0",
37
- "@mui/material": "^5.0.6",
38
- "@mui/styles": "^5.0.2",
39
- "@mui/system": "^5.0.6",
40
- "@mui/x-date-pickers": "^5.0.7",
31
+ "@huma-finance/sdk": "^0.0.61",
32
+ "@huma-finance/shared": "^0.0.61",
33
+ "@huma-finance/web-shared": "^0.0.62-beta.617+10ec4cd",
41
34
  "@notifi-network/notifi-frontend-client": "^0.91.1",
42
35
  "@reduxjs/toolkit": "^1.8.6",
43
36
  "@types/utf8": "^3.0.1",
@@ -187,6 +180,13 @@
187
180
  },
188
181
  "peerDependencies": {
189
182
  "@coral-xyz/anchor": "^0.30.1",
183
+ "@emotion/react": "^11.5.0",
184
+ "@emotion/styled": "^11.3.0",
185
+ "@mui/icons-material": "^5.3.0",
186
+ "@mui/material": "^5.0.6",
187
+ "@mui/styles": "^5.0.2",
188
+ "@mui/system": "^5.0.6",
189
+ "@mui/x-date-pickers": "^5.0.7",
190
190
  "@solana/spl-token": "^0.4.8",
191
191
  "@solana/wallet-adapter-base": "^0.9.23",
192
192
  "@solana/wallet-adapter-react": "^0.15.35",
@@ -200,5 +200,5 @@
200
200
  "optionalDependencies": {
201
201
  "encoding": "^0.1.13"
202
202
  },
203
- "gitHead": "99e0987b7a460f47f40d91836af7d44c9744142b"
203
+ "gitHead": "10ec4cd7144139bbec751768015e41a0bc79a1d7"
204
204
  }
@@ -8,13 +8,14 @@ import React, { useCallback, useEffect, useState } from 'react'
8
8
 
9
9
  import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token'
10
10
  import { useWallet } from '@solana/wallet-adapter-react'
11
- import { useHumaProgram } from '@huma-finance/web-shared'
11
+ import { useHumaProgram, useLenderAccounts } from '@huma-finance/web-shared'
12
12
  import { Transaction } from '@solana/web3.js'
13
13
  import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
14
14
  import { setStep } from '../../../store/widgets.reducers'
15
15
  import { WIDGET_STEP } from '../../../store/widgets.store'
16
16
  import { selectWidgetState } from '../../../store/widgets.selectors'
17
17
  import { SolanaTxSendModal } from '../../SolanaTxSendModal'
18
+ import { LoadingModal } from '../../LoadingModal'
18
19
 
19
20
  type Props = {
20
21
  poolInfo: SolanaPoolInfo
@@ -34,6 +35,13 @@ export function Transfer({
34
35
  decimals,
35
36
  )
36
37
  const [transaction, setTransaction] = useState<Transaction>()
38
+ const {
39
+ juniorLenderApprovedAccountPDA,
40
+ seniorLenderApprovedAccountPDA,
41
+ seniorLenderStateAccount,
42
+ juniorLenderStateAccount,
43
+ loading: isLoadingLenderAccounts,
44
+ } = useLenderAccounts(poolInfo.chainId, poolInfo.poolName)
37
45
  const program = useHumaProgram(poolInfo.chainId)
38
46
 
39
47
  const handleSuccess = useCallback(() => {
@@ -42,13 +50,43 @@ export function Transfer({
42
50
 
43
51
  useEffect(() => {
44
52
  async function getTx() {
45
- if (!publicKey || transaction) {
53
+ if (!publicKey || transaction || isLoadingLenderAccounts) {
46
54
  return
47
55
  }
48
56
 
57
+ const tx = new Transaction()
58
+
49
59
  const { underlyingTokenATA, seniorTrancheATA, juniorTrancheATA } =
50
60
  getTokenAccounts(poolInfo, publicKey)
51
- const tx = await program.methods
61
+ if (
62
+ (selectedTranche === 'senior' && !seniorLenderStateAccount) ||
63
+ (selectedTranche === 'junior' && !juniorLenderStateAccount)
64
+ ) {
65
+ const createLenderAccountsTx = await program.methods
66
+ .createLenderAccounts()
67
+ .accountsPartial({
68
+ lender: publicKey,
69
+ humaConfig: poolInfo.humaConfig,
70
+ poolConfig: poolInfo.poolConfig,
71
+ approvedLender:
72
+ selectedTranche === 'senior'
73
+ ? seniorLenderApprovedAccountPDA!
74
+ : juniorLenderApprovedAccountPDA!,
75
+ trancheMint:
76
+ selectedTranche === 'senior'
77
+ ? poolInfo.seniorTrancheMint
78
+ : poolInfo.juniorTrancheMint,
79
+ lenderTrancheToken:
80
+ selectedTranche === 'senior'
81
+ ? seniorTrancheATA
82
+ : juniorTrancheATA,
83
+ tokenProgram: TOKEN_2022_PROGRAM_ID,
84
+ })
85
+ .transaction()
86
+ tx.add(createLenderAccountsTx)
87
+ }
88
+
89
+ const depositTx = await program.methods
52
90
  .deposit(supplyBigNumber)
53
91
  .accountsPartial({
54
92
  depositor: publicKey,
@@ -66,19 +104,29 @@ export function Transfer({
66
104
  tokenProgram: TOKEN_2022_PROGRAM_ID,
67
105
  })
68
106
  .transaction()
107
+ tx.add(depositTx)
69
108
 
70
109
  setTransaction(tx)
71
110
  }
72
111
  getTx()
73
112
  }, [
113
+ isLoadingLenderAccounts,
114
+ juniorLenderApprovedAccountPDA,
115
+ juniorLenderStateAccount,
74
116
  poolInfo,
75
117
  program.methods,
76
118
  publicKey,
77
119
  selectedTranche,
120
+ seniorLenderApprovedAccountPDA,
121
+ seniorLenderStateAccount,
78
122
  supplyBigNumber,
79
123
  transaction,
80
124
  ])
81
125
 
126
+ if (isLoadingLenderAccounts) {
127
+ return <LoadingModal title='Supply' />
128
+ }
129
+
82
130
  return (
83
131
  <SolanaTxSendModal
84
132
  tx={transaction}