Skip to content

Commit

Permalink
feat: disable staking when not supported in ledger
Browse files Browse the repository at this point in the history
  • Loading branch information
icfor committed Apr 9, 2024
1 parent 1e98a42 commit f83390f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import type {
StakingNetworkInfo,
} from "@src/screens/staking/lib/staking_sdk/core";
import { WalletId } from "@src/screens/staking/lib/staking_sdk/core/base";
import { unsupportedLedgerNetworks } from "@src/screens/staking/lib/staking_sdk/core/cosmos";
import { formatCoin } from "@src/screens/staking/lib/staking_sdk/formatters";
import {
accountHasDelegations,
Expand Down Expand Up @@ -290,6 +291,10 @@ const PopOver = ({
<HighlightButton
className={styles.stake}
data-test="popover-stake-button"
disabled={
stakingNetworkId &&
unsupportedLedgerNetworks.has(stakingNetworkId)
}
onClick={() => {
if (!hasNetworkSupportedWallet) {
setSelectedAccount(
Expand Down
26 changes: 14 additions & 12 deletions src/screens/staking/lib/staking_sdk/core/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ export const ethermintNetworks = new Set([

export const keplrNetworks = new Set<StakingNetworkId>(
[
// StakingNetworkId.Akash,
// StakingNetworkId.Celestia,
// StakingNetworkId.CelestiaTestnet,
// StakingNetworkId.ComposableFinance,
// StakingNetworkId.CosmosHub,
// StakingNetworkId.CosmosHubTestnet,
// StakingNetworkId.DyDx,
StakingNetworkId.Akash,
StakingNetworkId.Celestia,
StakingNetworkId.CelestiaTestnet,
StakingNetworkId.ComposableFinance,
StakingNetworkId.CosmosHub,
StakingNetworkId.CosmosHubTestnet,
StakingNetworkId.DyDx,
StakingNetworkId.Dymension,
StakingNetworkId.IslamicCoin,
StakingNetworkId.Injective,
// StakingNetworkId.Kava,
// StakingNetworkId.KavaTestnet,
// StakingNetworkId.Osmosis,
// StakingNetworkId.Stargaze,
// StakingNetworkId.StargazeTestnet,
StakingNetworkId.Kava,
StakingNetworkId.KavaTestnet,
StakingNetworkId.Osmosis,
StakingNetworkId.Stargaze,
StakingNetworkId.StargazeTestnet,
].filter(
ENABLE_TESTNETS ? () => true : (network) => !testnetNetworks.has(network),
),
Expand All @@ -54,3 +54,5 @@ export const cosmosStakingNetworks = new Set([
...Array.from(cosmosWallets.has(WalletId.Keplr) ? keplrNetworks : []),
...Array.from(cosmosWallets.has(WalletId.Leap) ? leapNetworks : []),
]);

export const unsupportedLedgerNetworks = new Set<StakingNetworkId>([]);
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
keplrNetworks,
keplrNonNativeChains,
leapNetworks,
unsupportedLedgerNetworks,
} from "../core/cosmos";
import { stakingClient } from "../staking_client";
import { addToConnectedWallets, getConnectedWallets } from "../utils/storage";
Expand Down Expand Up @@ -453,6 +454,14 @@ export const tryToConnectKeplr = async (
// eslint-disable-next-line no-console
console.log("debug: index.tsx: err", network, err);

if (
(err as any)?.message?.includes(
"Ledger is unsupported for this chain",
)
) {
unsupportedLedgerNetworks.add(network);
}

return [] as Account[];
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,6 @@ const getEIP712DataStructure = (
verifyingContract: "cosmos",
version: "1.0.0",
};
} else if (signDoc.chain_id === StakingNetworkId.IslamicCoin) {
domain = {
// Got chain id from:
// https://github.com/haqq-network/haqq/blob/03bba90ecacd8ecf49921be4196a2805f35f1ce8/app/app.go#L195C25-L195C30
chainId: `0x${(11235).toString(16)}`,
// Got the other domain info from:
// https://github.com/haqq-network/haqq/blob/master/ethereum/eip712/domain.go
name: "Cosmos Web3",
salt: "0",
verifyingContract: "cosmos",
version: "1.0.0",
};
} else {
throw new Error(`Unsupported chain id: ${signDoc.chain_id}`);
}
Expand Down Expand Up @@ -499,6 +487,10 @@ export const signAndBroadcastEthermint = async (
const { isNanoLedger } =
(await walletProvider?.getKey(account.networkId)) ?? {};

if (isNanoLedger && account.wallet !== WalletId.Keplr) {
throw new Error("Ledger is only supported in Keplr");
}

const tx = isNanoLedger
? await getTxForEthermintLedger(
account,
Expand Down

0 comments on commit f83390f

Please sign in to comment.