@huma-finance/widgets 0.0.73-beta.917 → 0.0.73-beta.922

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
@@ -3896,7 +3896,7 @@ function SolanaTxSendModal(_ref) {
3896
3896
  } = useConnection();
3897
3897
  const [signature, setSignature] = useState('');
3898
3898
  const [showRetryScreen, setShowRetryScreen] = useState(false);
3899
- const [useHighPriority, setUseHighPriority] = useState(false);
3899
+ const [useHighPriority, setUseHighPriority] = useState(true);
3900
3900
  const [refreshCount, refresh] = useForceRefresh();
3901
3901
  const styles = {
3902
3902
  wrapper: css(_templateObject$j || (_templateObject$j = _taggedTemplateLiteral(["\n height: 438px;\n position: relative;\n "]))),
@@ -3910,51 +3910,33 @@ function SolanaTxSendModal(_ref) {
3910
3910
  if (!connection || !tx || !publicKey || !signTransaction) {
3911
3911
  return;
3912
3912
  }
3913
- let signatureResult = '';
3914
3913
  try {
3915
- var _txResult$meta;
3916
3914
  // Optimize transaction
3917
3915
  // Make a copy of the tx so we can use the original tx for retries
3918
3916
  const txCopy = new Transaction();
3919
3917
  txCopy.instructions = [...tx.instructions];
3920
- const recentBlockhash = await connection.getLatestBlockhash('confirmed');
3921
- txCopy.recentBlockhash = recentBlockhash.blockhash;
3922
- txCopy.lastValidBlockHeight = recentBlockhash.lastValidBlockHeight;
3918
+ const txBlockhashData = await connection.getLatestBlockhash('confirmed');
3919
+ txCopy.recentBlockhash = txBlockhashData.blockhash;
3920
+ txCopy.lastValidBlockHeight = txBlockhashData.lastValidBlockHeight;
3923
3921
  txCopy.feePayer = publicKey;
3924
3922
  // Extract writable accounts
3925
3923
  const txAccounts = extractWritableAccounts(txCopy);
3926
3924
  // Add on compute unit limit + price instructions
3927
3925
  const optimizedTx = await buildOptimalTransactionFromConnection(txCopy, txAccounts, connection, chainId, publicKey, useHighPriority ? 'High' : undefined, process.env.REACT_APP_HELIUS_API_KEY);
3928
- signatureResult = await sendTransaction(optimizedTx, connection, {
3926
+ const signedTx = await signTransaction(optimizedTx);
3927
+ const signatureResult = await connection.sendRawTransaction(signedTx.serialize(), {
3929
3928
  preflightCommitment: 'confirmed',
3930
- skipPreflight: true
3929
+ skipPreflight: true,
3930
+ maxRetries: 0
3931
3931
  });
3932
3932
  setSignature(signatureResult);
3933
3933
  dispatch(setSolanaSignature(signatureResult));
3934
- await connection.confirmTransaction({
3935
- blockhash: optimizedTx.recentBlockhash,
3936
- lastValidBlockHeight: optimizedTx.lastValidBlockHeight,
3937
- signature: signatureResult
3938
- });
3939
- const txResult = await connection.getParsedTransaction(signatureResult, 'confirmed');
3940
- if (txResult !== null && txResult !== void 0 && (_txResult$meta = txResult.meta) !== null && _txResult$meta !== void 0 && _txResult$meta.err) {
3941
- dispatch(setError({
3942
- errorMessage: 'Your transaction was confirmed but had errors. Please check the transaction details on the explorer for more information.'
3943
- }));
3944
- return;
3945
- }
3946
- handleSuccess({
3947
- signature: signatureResult
3948
- });
3949
- } catch (error) {
3950
- var _err$message;
3951
- console.log(error);
3952
- let signatureStatusRetries = 0;
3953
- while (signatureStatusRetries < 5) {
3934
+
3935
+ // Loop and poll the transaction continuously until it is either confirmed or
3936
+ // the block height has been exceeded
3937
+ // eslint-disable-next-line no-constant-condition
3938
+ while (true) {
3954
3939
  var _result$value, _result$value2;
3955
- // Attempt to load the signature status using transaction history
3956
- // eslint-disable-next-line no-await-in-loop
3957
- await sleep(1000);
3958
3940
  // eslint-disable-next-line no-await-in-loop
3959
3941
  const result = await connection.getSignatureStatus(signatureResult, {
3960
3942
  searchTransactionHistory: true
@@ -3972,17 +3954,23 @@ function SolanaTxSendModal(_ref) {
3972
3954
  });
3973
3955
  return;
3974
3956
  }
3975
- signatureStatusRetries += 1;
3957
+
3958
+ // eslint-disable-next-line no-await-in-loop
3959
+ const latestBlockhash = await connection.getLatestBlockhash('confirmed');
3960
+ if (latestBlockhash.lastValidBlockHeight - optimizedTx.lastValidBlockHeight > 100) {
3961
+ setShowRetryScreen(true);
3962
+ return;
3963
+ }
3964
+
3965
+ // eslint-disable-next-line no-await-in-loop
3966
+ await sleep(1000);
3976
3967
  }
3968
+ } catch (error) {
3969
+ console.log(error);
3977
3970
  const err = error;
3978
- if (err !== null && err !== void 0 && (_err$message = err.message) !== null && _err$message !== void 0 && _err$message.includes('block height exceeded')) {
3979
- // Allow the user to retry the transaction
3980
- setShowRetryScreen(true);
3981
- } else {
3982
- dispatch(setError({
3983
- errorMessage: (err === null || err === void 0 ? void 0 : err.message) || ''
3984
- }));
3985
- }
3971
+ dispatch(setError({
3972
+ errorMessage: (err === null || err === void 0 ? void 0 : err.message) || ''
3973
+ }));
3986
3974
  }
3987
3975
  }
3988
3976
  sendTx();