@huma-finance/widgets 0.0.73-beta.957 → 0.0.73-beta.963
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/dist/index.js +10448 -10366
- package/package.json +5 -5
- package/src/components/Lend/solanaWithdraw/2-Transfer.tsx +46 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huma-finance/widgets",
|
|
3
|
-
"version": "0.0.73-beta.
|
|
3
|
+
"version": "0.0.73-beta.963+7ee8a9e",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"@ethersproject/contracts": "^5.7.0",
|
|
23
23
|
"@ethersproject/experimental": "^5.7.0",
|
|
24
24
|
"@ethersproject/units": "^5.6.0",
|
|
25
|
-
"@huma-finance/sdk": "^0.0.73-beta.
|
|
26
|
-
"@huma-finance/shared": "^0.0.73-beta.
|
|
27
|
-
"@huma-finance/web-shared": "^0.0.73-beta.
|
|
25
|
+
"@huma-finance/sdk": "^0.0.73-beta.963+7ee8a9e",
|
|
26
|
+
"@huma-finance/shared": "^0.0.73-beta.963+7ee8a9e",
|
|
27
|
+
"@huma-finance/web-shared": "^0.0.73-beta.963+7ee8a9e",
|
|
28
28
|
"@mui/x-date-pickers": "^5.0.7",
|
|
29
29
|
"@notifi-network/notifi-frontend-client": "^1.1.2",
|
|
30
30
|
"@notifi-network/notifi-react": "^1.1.2",
|
|
@@ -190,5 +190,5 @@
|
|
|
190
190
|
"optionalDependencies": {
|
|
191
191
|
"encoding": "^0.1.13"
|
|
192
192
|
},
|
|
193
|
-
"gitHead": "
|
|
193
|
+
"gitHead": "7ee8a9ee4711ce7a4a9542c704b1451eec255a31"
|
|
194
194
|
}
|
|
@@ -4,15 +4,23 @@ import {
|
|
|
4
4
|
TrancheType,
|
|
5
5
|
} from '@huma-finance/shared'
|
|
6
6
|
import { useHumaProgram } from '@huma-finance/web-shared'
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
import {
|
|
8
|
+
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
9
|
+
createAssociatedTokenAccountInstruction,
|
|
10
|
+
getAccount,
|
|
11
|
+
TOKEN_2022_PROGRAM_ID,
|
|
12
|
+
TOKEN_PROGRAM_ID,
|
|
13
|
+
TokenAccountNotFoundError,
|
|
14
|
+
TokenInvalidAccountOwnerError,
|
|
15
|
+
} from '@solana/spl-token'
|
|
16
|
+
import { useConnection, useWallet } from '@solana/wallet-adapter-react'
|
|
17
|
+
import { PublicKey, Transaction } from '@solana/web3.js'
|
|
10
18
|
import React, { useCallback, useEffect, useState } from 'react'
|
|
19
|
+
import useLogOnFirstMount from '../../../hooks/useLogOnFirstMount'
|
|
11
20
|
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
12
21
|
import { setStep } from '../../../store/widgets.reducers'
|
|
13
22
|
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
14
23
|
import { SolanaTxSendModal } from '../../SolanaTxSendModal'
|
|
15
|
-
import useLogOnFirstMount from '../../../hooks/useLogOnFirstMount'
|
|
16
24
|
|
|
17
25
|
type Props = {
|
|
18
26
|
poolInfo: SolanaPoolInfo
|
|
@@ -28,12 +36,13 @@ export function Transfer({
|
|
|
28
36
|
useLogOnFirstMount('Transaction')
|
|
29
37
|
const { publicKey } = useWallet()
|
|
30
38
|
const dispatch = useAppDispatch()
|
|
39
|
+
const { connection } = useConnection()
|
|
31
40
|
const program = useHumaProgram(poolInfo.chainId)
|
|
32
41
|
const [transaction, setTransaction] = useState<Transaction>()
|
|
33
42
|
|
|
34
43
|
useEffect(() => {
|
|
35
44
|
async function getTx() {
|
|
36
|
-
if (!publicKey || transaction) {
|
|
45
|
+
if (!publicKey || transaction || !connection) {
|
|
37
46
|
return
|
|
38
47
|
}
|
|
39
48
|
|
|
@@ -47,6 +56,37 @@ export function Transfer({
|
|
|
47
56
|
const lenderTrancheToken =
|
|
48
57
|
selectedTranche === 'senior' ? seniorTrancheATA : juniorTrancheATA
|
|
49
58
|
|
|
59
|
+
// Create user token account if it doesn't exist
|
|
60
|
+
try {
|
|
61
|
+
await getAccount(
|
|
62
|
+
connection,
|
|
63
|
+
underlyingTokenATA,
|
|
64
|
+
undefined,
|
|
65
|
+
TOKEN_PROGRAM_ID,
|
|
66
|
+
)
|
|
67
|
+
} catch (error: unknown) {
|
|
68
|
+
// TokenAccountNotFoundError can be possible if the associated address has already received some lamports,
|
|
69
|
+
// becoming a system account. Assuming program derived addressing is safe, this is the only case for the
|
|
70
|
+
// TokenInvalidAccountOwnerError in this code path.
|
|
71
|
+
// Source: https://solana.stackexchange.com/questions/802/checking-to-see-if-a-token-account-exists-using-anchor-ts
|
|
72
|
+
if (
|
|
73
|
+
error instanceof TokenAccountNotFoundError ||
|
|
74
|
+
error instanceof TokenInvalidAccountOwnerError
|
|
75
|
+
) {
|
|
76
|
+
// As this isn't atomic, it's possible others can create associated accounts meanwhile.
|
|
77
|
+
tx.add(
|
|
78
|
+
createAssociatedTokenAccountInstruction(
|
|
79
|
+
publicKey,
|
|
80
|
+
underlyingTokenATA,
|
|
81
|
+
publicKey,
|
|
82
|
+
new PublicKey(poolInfo.underlyingMint.address),
|
|
83
|
+
TOKEN_PROGRAM_ID,
|
|
84
|
+
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
85
|
+
),
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
50
90
|
if (!poolIsClosed) {
|
|
51
91
|
const disburseTx = await program.methods
|
|
52
92
|
.disburse()
|
|
@@ -85,6 +125,7 @@ export function Transfer({
|
|
|
85
125
|
}
|
|
86
126
|
getTx()
|
|
87
127
|
}, [
|
|
128
|
+
connection,
|
|
88
129
|
poolInfo,
|
|
89
130
|
poolIsClosed,
|
|
90
131
|
program.methods,
|