Skip to content

Commit

Permalink
Merge branch 'dev' into 94-event-tracking-add-mixpanel-event-tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
tombeckenham committed Nov 30, 2024
2 parents 175a490 + 0a66ce8 commit 7170e3c
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import { INTERNAL_REQUEST_ORIGIN, EVENTS, KEYRING_TYPE } from 'consts';

import { fclTestnetConfig, fclMainnetConfig } from '../fclConfig';
import placeholder from '../images/placeholder.png';
import type { CoinItem } from '../service/coinList';
import { type CoinItem } from '../service/coinList';
import DisplayKeyring from '../service/keyring/display';
import type { NFTData, NFTModel, StorageInfo, WalletResponse } from '../service/networkModel';
import type { ConnectedSite } from '../service/permission';
Expand Down Expand Up @@ -4017,10 +4017,12 @@ export class WalletController extends BaseController {
// Check the storage status
checkStorageStatus = async ({
transferAmount,
coin,
movingBetweenEVMAndFlow,
}: {
transferAmount?: number;
movingBetweenEVMAndFlow?: boolean;
transferAmount?: number; // amount in coins
coin?: string; // coin name
movingBetweenEVMAndFlow?: boolean; // are we moving between EVM and Flow?
} = {}): Promise<{
isStorageSufficient: boolean;
isStorageSufficientAfterAction: boolean;
Expand All @@ -4031,6 +4033,7 @@ export class WalletController extends BaseController {
await this.storageEvaluator.evaluateStorage(
address!,
transferAmount,
coin,
movingBetweenEVMAndFlow
);
return {
Expand Down
3 changes: 2 additions & 1 deletion src/background/service/storage-evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class StorageEvaluator {
async evaluateStorage(
address: string,
sendAmount?: number,
coin?: string,
movingBetweenEVMAndFlow?: boolean
): Promise<EvaluateStorageResult> {
// Get storage info from openapi service
Expand All @@ -32,7 +33,7 @@ export class StorageEvaluator {
if (sendAmount !== undefined) {
// This is the amount of flow that will be used by the transaction
const flowUsed =
sendAmount +
(coin === 'flow' ? sendAmount : 0) +
(movingBetweenEVMAndFlow ? StorageEvaluator.FIXED_MOVE_FEE : 0) +
StorageEvaluator.AVERAGE_TX_FEE;

Expand Down
14 changes: 9 additions & 5 deletions src/ui/utils/useStorageCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ interface StorageCheckResult {
}

interface UseStorageCheckProps {
transferAmount?: number | undefined;
transferAmount?: number;
coin?: string;
movingBetweenEVMAndFlow?: boolean;
}
export const useStorageCheck = ({
transferAmount,
movingBetweenEVMAndFlow,
transferAmount, // amount in coins
coin, // coin name
movingBetweenEVMAndFlow = false, // are we moving between EVM and Flow?
}: UseStorageCheckProps = {}): StorageCheckResult => {
const wallet = useWallet();

Expand All @@ -26,6 +28,7 @@ export const useStorageCheck = ({
undefined
);
const [storageInfo, setStorageInfo] = useState<StorageInfo | undefined>(undefined);

// Check general storage status
const checkStorageStatus = useCallback(async (): Promise<{
sufficient: boolean;
Expand All @@ -35,7 +38,8 @@ export const useStorageCheck = ({
try {
const { isStorageSufficient, isStorageSufficientAfterAction, storageInfo } =
await wallet.checkStorageStatus({
transferAmount,
transferAmount: transferAmount,
coin,
movingBetweenEVMAndFlow,
});

Expand All @@ -52,7 +56,7 @@ export const useStorageCheck = ({
storageInfo: { available: 0, used: 0, capacity: 0 },
}; // Default to true to not block transactions on error
}
}, [movingBetweenEVMAndFlow, transferAmount, wallet]);
}, [movingBetweenEVMAndFlow, transferAmount, wallet, coin]);

// Initial storage check
useEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions src/ui/views/EvmMove/MoveFromChild/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const MoveFromChild = (props: TransferConfirmationProps) => {
const [minAmount, setMinAmount] = useState<any>(0.001);
const { sufficient: isSufficient, sufficientAfterAction } = useStorageCheck({
transferAmount: Number(amount) || 0,
coin: currentCoin,
movingBetweenEVMAndFlow: true,
});

Expand Down
1 change: 1 addition & 0 deletions src/ui/views/EvmMove/MoveFromEvm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const MoveFromEvm = (props: TransferConfirmationProps) => {

const { sufficient: isSufficient, sufficientAfterAction } = useStorageCheck({
transferAmount: Number(amount) || 0,
coin: currentCoin,
movingBetweenEVMAndFlow: true,
});

Expand Down
1 change: 1 addition & 0 deletions src/ui/views/EvmMove/MoveFromFlow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const MoveFromFlow = (props: TransferConfirmationProps) => {

const { sufficient: isSufficient, sufficientAfterAction } = useStorageCheck({
transferAmount: Number(amount) || 0,
coin: currentCoin,
movingBetweenEVMAndFlow: true,
});

Expand Down
1 change: 1 addition & 0 deletions src/ui/views/EvmMove/MoveFromParent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const MoveFromParent = (props: TransferConfirmationProps) => {
const [minAmount, setMinAmount] = useState<any>(0.001);
const { sufficient: isSufficient, sufficientAfterAction } = useStorageCheck({
transferAmount: Number(amount) || 0,
coin: currentCoin,
movingBetweenEVMAndFlow: true,
});

Expand Down
1 change: 1 addition & 0 deletions src/ui/views/NFT/SendNFT/MovefromParent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const MovefromParent = (props: SendNFTConfirmationProps) => {
const [selectedAccount, setSelectedChildAccount] = useState(null);
const { sufficient: isSufficient, sufficientAfterAction } = useStorageCheck({
transferAmount: 0,
coin: 'flow',
movingBetweenEVMAndFlow: selectedAccount
? isValidEthereumAddress(selectedAccount!['address'])
: false,
Expand Down
1 change: 1 addition & 0 deletions src/ui/views/Send/SendEth/EvmConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const ToEthConfirmation = (props: ToEthConfirmationProps) => {
const movingBetweenEVMAndFlow = true;
const { sufficient: isSufficient, sufficientAfterAction } = useStorageCheck({
transferAmount,
coin: props.data?.coinInfo?.coin,
movingBetweenEVMAndFlow,
});

Expand Down
1 change: 1 addition & 0 deletions src/ui/views/Send/SendEth/ToEthConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const ToEthConfirmation = (props: ToEthConfirmationProps) => {
const [count, setCount] = useState(0);
const { sufficient: isSufficient, sufficientAfterAction } = useStorageCheck({
transferAmount: 0,
coin: props.data?.coinInfo?.coin,
movingBetweenEVMAndFlow: true,
});

Expand Down
1 change: 1 addition & 0 deletions src/ui/views/Send/TransferConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const TransferConfirmation = (props: TransferConfirmationProps) => {
const { sufficient: isSufficient, sufficientAfterAction: isSufficientAfterAction } =
useStorageCheck({
transferAmount,
coin: props.data?.coinInfo?.coin,
movingBetweenEVMAndFlow,
});

Expand Down

0 comments on commit 7170e3c

Please sign in to comment.