From 7407065f4e1d80c9b9e7236349df49addfc28bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sza=C5=82owski?= Date: Thu, 28 Mar 2024 17:05:55 +0100 Subject: [PATCH] chore(#575): change selection strategy to 3 --- CHANGELOG.md | 3 +- govtool/frontend/src/context/wallet.tsx | 48 ++++++++++++++----------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec7a3913b..4e66a5baa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ changes. - Fix all the existing typescript errors [Issue 514](https://github.com/IntersectMBO/govtool/issues/514) - Fix endless spinner on a dashboard [Issue 539](https://github.com/IntersectMBO/govtool/issues/539) - Update frontend package readme to reflect recent changes [Issue 543](https://github.com/IntersectMBO/govtool/issues/543) +- Change input selection strategy to 3 (random) [Issue 575](https://github.com/IntersectMBO/govtool/issues/575) ### Added @@ -65,7 +66,7 @@ changes. ### Changed - `proposal/list` returns additional data such ass `expiryEpochNo`, `createdEpochNo`, `title`, `about`, `motivation`, - `rationale`. `TreasuryWithdrawals` GAs also got nicely formated details. [Issue 372](https://github.com/IntersectMBO/govtool/issues/372) + `rationale`. `TreasuryWithdrawals` GAs also got nicely formated details. [Issue 372](https://github.com/IntersectMBO/govtool/issues/372) - `drep/list` now return also `status` and `type` fields. Also it now returns the retired dreps, and you can search for given drep by name using optional query parameter. If the drep name is passed exactly, then you can even find a drep that's sole voter. [Issue 446](https://github.com/IntersectMBO/govtool/issues/446) - `drep/list` and `drep/info` endpoints now return additional data such as metadata url and hash, and voting power [Issue 223](https://github.com/IntersectMBO/govtool/issues/223) - `drep/info` now does not return sole voters (dreps without metadata) [Issue 317](https://github.com/IntersectMBO/govtool/issues/317) diff --git a/govtool/frontend/src/context/wallet.tsx b/govtool/frontend/src/context/wallet.tsx index c60b6cbaf..b9f8bfbf3 100644 --- a/govtool/frontend/src/context/wallet.tsx +++ b/govtool/frontend/src/context/wallet.tsx @@ -101,9 +101,9 @@ type BuildSignSubmitConwayCertTxArgs = { votingBuilder?: VotingBuilder; voterDeposit?: string; } & ( - | Pick - | Pick - ); + | Pick + | Pick +); interface CardanoContextType { address?: string; @@ -168,8 +168,10 @@ type Utxos = { const NETWORK = +import.meta.env.VITE_NETWORK_FLAG; -const CardanoContext = createContext({} as CardanoContextType); -CardanoContext.displayName = 'CardanoContext'; +const CardanoContext = createContext( + {} as CardanoContextType, +); +CardanoContext.displayName = "CardanoContext"; const CardanoProvider = (props: Props) => { const [isEnabled, setIsEnabled] = useState(false); @@ -266,9 +268,9 @@ const CardanoProvider = (props: Props) => { const network = await enabledApi.getNetworkId(); if (network !== NETWORK) { throw new Error( - t('errors.tryingConnectTo', { - networkFrom: network === 1 ? 'mainnet' : 'testnet', - networkTo: network !== 1 ? 'mainnet' : 'testnet', + t("errors.tryingConnectTo", { + networkFrom: network === 1 ? "mainnet" : "testnet", + networkTo: network !== 1 ? "mainnet" : "testnet", }), ); } @@ -307,7 +309,7 @@ const CardanoProvider = (props: Props) => { .to_hex(); }); } else { - console.warn(t('warnings.usingUnregisteredStakeKeys')); + console.warn(t("warnings.usingUnregisteredStakeKeys")); stakeKeysList = unregisteredStakeKeysList.map((key) => { const stakeKeyHash = PublicKey.from_hex(key).hash(); const stakeCredential = Credential.from_keyhash(stakeKeyHash); @@ -361,15 +363,15 @@ const CardanoProvider = (props: Props) => { setIsEnabled(false); // eslint-disable-next-line no-throw-literal throw { - status: 'ERROR', - error: `${e ?? t('errors.somethingWentWrong')}`, + status: "ERROR", + error: `${e ?? t("errors.somethingWentWrong")}`, }; } finally { setIsEnableLoading(null); } } // eslint-disable-next-line no-throw-literal - throw { status: 'ERROR', error: t('errors.somethingWentWrong') }; + throw { status: "ERROR", error: t("errors.somethingWentWrong") }; }, [isEnabled, stakeKeys], ); @@ -489,8 +491,14 @@ const CardanoProvider = (props: Props) => { // Find the available UTXOs in the wallet and use them as Inputs for the transaction const txUnspentOutputs = await getTxUnspentOutputs(utxos); - // Use UTxO selection strategy 2 - txBuilder.add_inputs_from(txUnspentOutputs, 2); + // Use UTxO selection strategy 3 + try { + txBuilder.add_inputs_from(txUnspentOutputs, 3); + } catch (e) { + console.error(e); + // Use UTxO selection strategy 2 if strategy 3 fails + txBuilder.add_inputs_from(txUnspentOutputs, 2); + } // Set change address, incase too much ADA provided for fee txBuilder.add_change_if_needed(shelleyChangeAddress); @@ -533,10 +541,10 @@ const CardanoProvider = (props: Props) => { }); // eslint-disable-next-line no-console - console.log(signedTx.to_hex(), 'signed tx cbor'); + console.log(signedTx.to_hex(), "signed tx cbor"); return resultHash; - // TODO: type error - // eslint-disable-next-line @typescript-eslint/no-shadow, @typescript-eslint/no-explicit-any + // TODO: type error + // eslint-disable-next-line @typescript-eslint/no-shadow, @typescript-eslint/no-explicit-any } catch (error: any) { const walletName = getItemFromLocalStorage(`${WALLET_LS_KEY}_name`); const isWalletConnected = await window.cardano[walletName].isEnabled(); @@ -624,7 +632,7 @@ const CardanoProvider = (props: Props) => { anchor, ); } else { - console.error(t('errors.notUsingAnchor')); + console.error(t("errors.notUsingAnchor")); dRepRegCert = DrepRegistration.new( dRepCred, BigNum.from_str(`${epochParams.drep_deposit}`), @@ -958,8 +966,8 @@ function useCardano() { } return result; } - // TODO: type error - // eslint-disable-next-line @typescript-eslint/no-explicit-any + // TODO: type error + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (e: any) { Sentry.captureException(e); await context.disconnectWallet();