@huma-finance/widgets 0.0.73-beta.954 → 0.0.73-beta.961

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 CHANGED
@@ -54097,15 +54097,6 @@ function getBlockchainConfigFromChain(ar) {
54097
54097
  }
54098
54098
  function doesChainSupportNotifi(ar, or) {
54099
54099
  switch (ar) {
54100
- case ChainEnum.Celo:
54101
- case ChainEnum.Polygon:
54102
- case ChainEnum.Scroll:
54103
- return !0;
54104
- case ChainEnum.Alfajores:
54105
- case ChainEnum.Mumbai:
54106
- case ChainEnum.Goerli:
54107
- case ChainEnum.ScrollSepolia:
54108
- return or;
54109
54100
  default:
54110
54101
  return !1;
54111
54102
  }
@@ -174952,59 +174943,79 @@ function Transfer$9({
174952
174943
  poolIsClosed: ur
174953
174944
  }) {
174954
174945
  useLogOnFirstMount("Transaction");
174955
- const { publicKey: cr } = useWallet(), fr = useAppDispatch(), lr = useHumaProgram(ar.chainId), [dr, pr] = useState();
174946
+ const { publicKey: cr } = useWallet(), fr = useAppDispatch(), { connection: lr } = useConnection(), dr = useHumaProgram(ar.chainId), [pr, yr] = useState();
174956
174947
  useEffect(() => {
174957
- async function Ar() {
174958
- if (!cr || dr)
174948
+ async function gr() {
174949
+ if (!cr || pr || !lr)
174959
174950
  return;
174960
- const gr = new Transaction$3(), { underlyingTokenATA: hr, seniorTrancheATA: Sr, juniorTrancheATA: Ir } = getTokenAccounts(ar, cr), Tr = or === "senior" ? ar.seniorTrancheMint : ar.juniorTrancheMint, xr = or === "senior" ? Sr : Ir;
174951
+ const hr = new Transaction$3(), { underlyingTokenATA: Sr, seniorTrancheATA: Ir, juniorTrancheATA: Tr } = getTokenAccounts(ar, cr), xr = or === "senior" ? ar.seniorTrancheMint : ar.juniorTrancheMint, Br = or === "senior" ? Ir : Tr;
174952
+ try {
174953
+ await getAccount(
174954
+ lr,
174955
+ Sr,
174956
+ void 0,
174957
+ TOKEN_PROGRAM_ID
174958
+ );
174959
+ } catch (Pr) {
174960
+ (Pr instanceof TokenAccountNotFoundError || Pr instanceof TokenInvalidAccountOwnerError) && hr.add(
174961
+ createAssociatedTokenAccountInstruction(
174962
+ cr,
174963
+ Sr,
174964
+ cr,
174965
+ new PublicKey$2(ar.underlyingMint.address),
174966
+ TOKEN_PROGRAM_ID,
174967
+ ASSOCIATED_TOKEN_PROGRAM_ID
174968
+ )
174969
+ );
174970
+ }
174961
174971
  if (ur) {
174962
- const Br = await lr.methods.withdrawAfterPoolClosure().accountsPartial({
174972
+ const Pr = await dr.methods.withdrawAfterPoolClosure().accountsPartial({
174963
174973
  lender: cr,
174964
174974
  humaConfig: ar.humaConfig,
174965
174975
  poolConfig: ar.poolConfig,
174966
174976
  underlyingMint: ar.underlyingMint.address,
174967
- trancheMint: Tr,
174977
+ trancheMint: xr,
174968
174978
  poolUnderlyingToken: ar.poolUnderlyingTokenAccount,
174969
- lenderUnderlyingToken: hr,
174970
- lenderTrancheToken: xr,
174979
+ lenderUnderlyingToken: Sr,
174980
+ lenderTrancheToken: Br,
174971
174981
  underlyingTokenProgram: TOKEN_PROGRAM_ID,
174972
174982
  trancheTokenProgram: TOKEN_2022_PROGRAM_ID
174973
174983
  }).transaction();
174974
- gr.add(Br);
174984
+ hr.add(Pr);
174975
174985
  } else {
174976
- const Br = await lr.methods.disburse().accountsPartial({
174986
+ const Pr = await dr.methods.disburse().accountsPartial({
174977
174987
  lender: cr,
174978
174988
  humaConfig: ar.humaConfig,
174979
174989
  poolConfig: ar.poolConfig,
174980
174990
  underlyingMint: ar.underlyingMint.address,
174981
- trancheMint: Tr,
174991
+ trancheMint: xr,
174982
174992
  poolUnderlyingToken: ar.poolUnderlyingTokenAccount,
174983
- lenderUnderlyingToken: hr,
174993
+ lenderUnderlyingToken: Sr,
174984
174994
  tokenProgram: TOKEN_PROGRAM_ID
174985
174995
  }).transaction();
174986
- gr.add(Br);
174996
+ hr.add(Pr);
174987
174997
  }
174988
- pr(gr);
174998
+ yr(hr);
174989
174999
  }
174990
- Ar();
175000
+ gr();
174991
175001
  }, [
175002
+ lr,
174992
175003
  ar,
174993
175004
  ur,
174994
- lr.methods,
175005
+ dr.methods,
174995
175006
  cr,
174996
175007
  or,
174997
- dr
175008
+ pr
174998
175009
  ]);
174999
- const yr = useCallback(() => {
175010
+ const Ar = useCallback(() => {
175000
175011
  fr(setStep(WIDGET_STEP.Done));
175001
175012
  }, [fr]);
175002
175013
  return /* @__PURE__ */ jsx(
175003
175014
  SolanaTxSendModal,
175004
175015
  {
175005
- tx: dr,
175016
+ tx: pr,
175006
175017
  chainId: ar.chainId,
175007
- handleSuccess: yr
175018
+ handleSuccess: Ar
175008
175019
  }
175009
175020
  );
175010
175021
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huma-finance/widgets",
3
- "version": "0.0.73-beta.954+dbbe72e",
3
+ "version": "0.0.73-beta.961+34c4cad",
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.954+dbbe72e",
26
- "@huma-finance/shared": "^0.0.73-beta.954+dbbe72e",
27
- "@huma-finance/web-shared": "^0.0.73-beta.954+dbbe72e",
25
+ "@huma-finance/sdk": "^0.0.73-beta.961+34c4cad",
26
+ "@huma-finance/shared": "^0.0.73-beta.961+34c4cad",
27
+ "@huma-finance/web-shared": "^0.0.73-beta.961+34c4cad",
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": "dbbe72e2b42c554da0f293a33a22a7cd6d9d93ba"
193
+ "gitHead": "34c4cad8e5f86bb81f80fb99eb320248271a320c"
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 { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
8
- import { useWallet } from '@solana/wallet-adapter-react'
9
- import { Transaction } from '@solana/web3.js'
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,