Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(#575): change selection strategy to 3 #591

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
48 changes: 28 additions & 20 deletions govtool/frontend/src/context/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ type BuildSignSubmitConwayCertTxArgs = {
votingBuilder?: VotingBuilder;
voterDeposit?: string;
} & (
| Pick<TransactionStateWithoutResource, 'type' | 'resourceId'>
| Pick<TransactionStateWithResource, 'type' | 'resourceId'>
);
| Pick<TransactionStateWithoutResource, "type" | "resourceId">
| Pick<TransactionStateWithResource, "type" | "resourceId">
);

interface CardanoContextType {
address?: string;
Expand Down Expand Up @@ -168,8 +168,10 @@ type Utxos = {

const NETWORK = +import.meta.env.VITE_NETWORK_FLAG;

const CardanoContext = createContext<CardanoContextType>({} as CardanoContextType);
CardanoContext.displayName = 'CardanoContext';
const CardanoContext = createContext<CardanoContextType>(
{} as CardanoContextType,
);
CardanoContext.displayName = "CardanoContext";

const CardanoProvider = (props: Props) => {
const [isEnabled, setIsEnabled] = useState(false);
Expand Down Expand Up @@ -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",
}),
);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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],
);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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}`),
Expand Down Expand Up @@ -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();
Expand Down
Loading