Skip to content

Commit

Permalink
[#512] fix ts and eslint errors in wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dyczka committed Mar 26, 2024
1 parent bb26945 commit a189d87
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
1 change: 1 addition & 0 deletions govtool/frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ module.exports = {
"operator-linebreak": "off",
"implicit-arrow-linebreak": "off",
"consistent-return": "off",
"no-console": ["error", { allow: ["warn", "error"] }],
"no-shadow": "off",
"function-paren-newline": "off",
"object-curly-newline": "off",
Expand Down
1 change: 0 additions & 1 deletion govtool/frontend/src/context/getUtxos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export const getUtxos = async (
return utxos;
} catch (err) {
Sentry.captureException(err);
// eslint-disable-next-line no-console
console.error(err);
}
};
49 changes: 27 additions & 22 deletions govtool/frontend/src/context/wallet.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// TODO: enable eslint and fix all the errors with wallet refactor
/* eslint-disable */
import {
createContext,
useCallback,
Expand Down Expand Up @@ -107,7 +105,7 @@ type BuildSignSubmitConwayCertTxArgs = {
| Pick<TransactionStateWithResource, 'type' | 'resourceId'>
);

interface CardanoContext {
interface CardanoContextType {
address?: string;
disconnectWallet: () => Promise<void>;
enable: (walletName: string) => Promise<EnableResponse>;
Expand Down Expand Up @@ -160,17 +158,17 @@ interface CardanoContext {
}

type Utxos = {
txid: any;
txid: unknown;
txindx: number;
amount: string;
str: string;
multiAssetStr: string;
TransactionUnspentOutput: TransactionUnspentOutput;
}[];

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

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

const CardanoProvider = (props: Props) => {
Expand Down Expand Up @@ -248,7 +246,7 @@ const CardanoProvider = (props: Props) => {
throw new Error(t('errors.walletNoCIP30Nor90Support'));
}
// Enable wallet connection
const enabledApi = await window.cardano[walletName]
const enabledApi: CardanoApiWallet = await window.cardano[walletName]
.enable({
extensions: [{ cip: 95 }],
})
Expand All @@ -266,15 +264,15 @@ const CardanoProvider = (props: Props) => {
throw new Error(t('errors.walletNoCIP90FunctionsEnabled'));
}
const network = await enabledApi.getNetworkId();
if (network != NETWORK) {
if (network !== NETWORK) {
throw new Error(
t('errors.tryingConnectTo', {
networkFrom: network == 1 ? 'mainnet' : 'testnet',
networkTo: network != 1 ? 'mainnet' : 'testnet',
networkFrom: network === 1 ? 'mainnet' : 'testnet',
networkTo: network !== 1 ? 'mainnet' : 'testnet',
}),
);
}
setIsMainnet(network == 1);
setIsMainnet(network === 1);
// Check and set wallet address
const usedAddresses = await enabledApi.getUsedAddresses();
const unusedAddresses = await enabledApi.getUnusedAddresses();
Expand All @@ -296,8 +294,8 @@ const CardanoProvider = (props: Props) => {

let stakeKeysList;
if (registeredStakeKeysList.length > 0) {
stakeKeysList = registeredStakeKeysList.map((stakeKey) => {
const stakeKeyHash = PublicKey.from_hex(stakeKey).hash();
stakeKeysList = registeredStakeKeysList.map((key) => {
const stakeKeyHash = PublicKey.from_hex(key).hash();
const stakeCredential = Credential.from_keyhash(stakeKeyHash);
if (network === 1) {
return RewardAddress.new(1, stakeCredential)
Expand All @@ -310,8 +308,8 @@ const CardanoProvider = (props: Props) => {
});
} else {
console.warn(t('warnings.usingUnregisteredStakeKeys'));
stakeKeysList = unregisteredStakeKeysList.map((stakeKey) => {
const stakeKeyHash = PublicKey.from_hex(stakeKey).hash();
stakeKeysList = unregisteredStakeKeysList.map((key) => {
const stakeKeyHash = PublicKey.from_hex(key).hash();
const stakeCredential = Credential.from_keyhash(stakeKeyHash);
if (network === 1) {
return RewardAddress.new(1, stakeCredential)
Expand Down Expand Up @@ -361,14 +359,16 @@ const CardanoProvider = (props: Props) => {
setPubDRepKey('');
setStakeKey(undefined);
setIsEnabled(false);
// eslint-disable-next-line no-throw-literal
throw {
status: 'ERROR',
error: `${e == undefined ? t('errors.somethingWentWrong') : e}`,
error: `${e ?? t('errors.somethingWentWrong')}`,
};
} finally {
setIsEnableLoading(null);
}
}
// eslint-disable-next-line no-throw-literal
throw { status: 'ERROR', error: t('errors.somethingWentWrong') };
},
[isEnabled, stakeKeys],
Expand Down Expand Up @@ -414,6 +414,7 @@ const CardanoProvider = (props: Props) => {

const getTxUnspentOutputs = async (utxos: Utxos) => {
const txOutputs = TransactionUnspentOutputs.new();
// eslint-disable-next-line no-restricted-syntax
for (const utxo of utxos) {
txOutputs.add(utxo.TransactionUnspentOutput);
}
Expand Down Expand Up @@ -531,9 +532,11 @@ const CardanoProvider = (props: Props) => {
resourceId,
});

// eslint-disable-next-line no-console
console.log(signedTx.to_hex(), 'signed tx cbor');
return resultHash;
// TODO: type error
// 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 @@ -589,7 +592,7 @@ const CardanoProvider = (props: Props) => {
return certBuilder;
} catch (e) {
Sentry.captureException(e);
console.log(e);
console.error(e);
throw e;
}
},
Expand Down Expand Up @@ -621,7 +624,7 @@ const CardanoProvider = (props: Props) => {
anchor,
);
} else {
console.log(t('errors.notUsingAnchor'));
console.error(t('errors.notUsingAnchor'));
dRepRegCert = DrepRegistration.new(
dRepCred,
BigNum.from_str(`${epochParams.drep_deposit}`),
Expand Down Expand Up @@ -667,7 +670,7 @@ const CardanoProvider = (props: Props) => {
return certBuilder;
} catch (e) {
Sentry.captureException(e);
console.log(e);
console.error(e);
throw e;
}
},
Expand Down Expand Up @@ -695,7 +698,7 @@ const CardanoProvider = (props: Props) => {
return certBuilder;
} catch (e) {
Sentry.captureException(e);
console.log(e);
console.error(e);
throw e;
}
},
Expand Down Expand Up @@ -748,7 +751,7 @@ const CardanoProvider = (props: Props) => {
return votingBuilder;
} catch (e) {
Sentry.captureException(e);
console.log(e);
console.error(e);
throw e;
}
},
Expand Down Expand Up @@ -955,6 +958,8 @@ function useCardano() {
}
return result;
}
// TODO: type error
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
Sentry.captureException(e);
await context.disconnectWallet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ export const useCreateGovernanceActionForm = (
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
// eslint-disable-next-line no-console
console.error(error);
throw error;
}
Expand Down
1 change: 0 additions & 1 deletion govtool/frontend/src/hooks/forms/useRegisterAsdRepForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const useRegisterAsdRepForm = () => {
console.log(values);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
// eslint-disable-next-line no-console
console.error(e);
} finally {
setIsLoading(false);
Expand Down
1 change: 0 additions & 1 deletion govtool/frontend/src/utils/getDRepID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export const getPubDRepID = async (walletApi: CardanoApiWallet) => {
dRepIDBech32,
};
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
return {
dRepKey: undefined,
Expand Down

0 comments on commit a189d87

Please sign in to comment.