Skip to content

Commit

Permalink
fix: remove memo and handle connection popup
Browse files Browse the repository at this point in the history
  • Loading branch information
icfor committed Apr 15, 2024
1 parent 144bd27 commit bf59b12
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { getAccountNormalisedBalance } from "@src/screens/staking/lib/staking_sd
import {
getEmptyCoin,
getIsCoin,
normaliseCoin,
} from "@src/screens/staking/lib/staking_sdk/utils/coins";
import { getUnbondingTimeForNetwork } from "@src/screens/staking/lib/staking_sdk/utils/networks";
import {
Expand Down Expand Up @@ -119,6 +120,7 @@ const StakingModal = () => {
}

const minimumStakeAmount = minimumStakeAmountMap[selectedAccount.networkId];
const normalised = normaliseCoin(minimumStakeAmount);

Check failure on line 123 in src/screens/staking/components/staking_section/staking_modal.tsx

View workflow job for this annotation

GitHub Actions / Lint

'normalised' is assigned a value but never used

if (minimumStakeAmount && amountNum.lt(minimumStakeAmount.amount)) {
return t("stakingModal.amountError.notEnough", {
Expand Down
39 changes: 25 additions & 14 deletions src/screens/staking/lib/staking_sdk/wallet_operations/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Transaction,
} from "@solana/web3.js";
import Solflare from "@solflare-wallet/sdk";
import BigNumber from "bignumber.js";

import { toastError } from "@src/components/notification";

Expand Down Expand Up @@ -141,7 +142,14 @@ export const tryToConnectSolflare = async (
await Promise.all([
hasMainnetWallet ? mainnetWallet.connect() : Promise.resolve(),
hasDevnetWallet ? devnetWallet.connect() : Promise.resolve(),
]);
]).catch((err) => {
if (!err) {
// This means that the user closed the popup or rejected the connection
resolve(false);
}

reject(err);
});
});
};

Expand All @@ -161,7 +169,11 @@ export const tryToConnectPhantom = async (
const resp = await provider.connect();

publicKey = resp.publicKey.toString();
} catch (error) {
} catch (error: any) {
if (error?.message?.includes("User rejected the request")) {
return false;
}

toastError({
title: walletErrorMap.phantomCreateWallet,
});
Expand Down Expand Up @@ -214,12 +226,12 @@ export const tryToConnectPhantom = async (
// In mainnet less than 0.01 SOL it gives an error from the wallet estimation.
export const minimumSolanaStakeAmount: { [key in StakingNetworkId]?: Coin } = {
[StakingNetworkId.Solana]: {
amount: (LAMPORTS_PER_SOL * 0.01).toString(),
denom: "lamports",
amount: "0.01",
denom: "SOL",
},
[StakingNetworkId.SolanaDevnet]: {
amount: (LAMPORTS_PER_SOL * 0.001).toString(),
denom: "lamports",
amount: "0.001",
denom: "SOL",
},
};

Expand Down Expand Up @@ -263,24 +275,23 @@ export const stakeAmountSolana = async ({

const stakeKeyPair = Keypair.generate();

const amountToStake = Number(amount) * LAMPORTS_PER_SOL;

const minimumAmount = minimumSolanaStakeAmount[account.networkId] || {
amount: "0",
denom: "lamports",
denom: "SOL",
};

if (amountToStake < Number(minimumAmount)) {
const amountBN = new BigNumber(amount);

if (amountBN.lt(normaliseCoin(minimumAmount).amount)) {
return {
coin: normaliseCoin({
amount: minimumAmount.toString(),
denom: "LAMPORTS",
}),
coin: minimumAmount,
error: StakeError.MinimumAmount,
success: false,
};
}

const amountToStake = amountBN.times(LAMPORTS_PER_SOL).toNumber();

const newTx = StakeProgram.createAccount({
authorized: new Authorized(accountKey, accountKey),
fromPubkey: accountKey,
Expand Down

0 comments on commit bf59b12

Please sign in to comment.