Skip to content

Commit

Permalink
chore: fix code conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryz0nd committed Aug 5, 2024
1 parent aa6d78a commit 0a2f03b
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 132 deletions.
8 changes: 6 additions & 2 deletions src/hooks/useAccountBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ import { getBalances, getStakingBalances } from '@/state/accountSelectors';
import { getSelectedDydxChainId } from '@/state/appSelectors';
import { useAppSelector } from '@/state/appTypes';

import { SUPPORTED_COSMOS_CHAINS } from '@/lib/graz';
import {
getNeutronChainId,
getNobleChainId,
getOsmosisChainId,
SUPPORTED_COSMOS_CHAINS,
} from '@/lib/graz';
import { MustBigNumber } from '@/lib/numbers';
import { getNeutronChainId, getNobleChainId, getOsmosisChainId } from '@/lib/squid';

import { useAccounts } from './useAccounts';
import { useEndpointsConfig } from './useEndpointsConfig';
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useAccounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { useAppDispatch, useAppSelector } from '@/state/appTypes';

import abacusStateManager from '@/lib/abacus';
import { isBlockedGeo } from '@/lib/compliance';
import { getNobleChainId } from '@/lib/squid';
import { getNobleChainId } from '@/lib/graz';
import { log } from '@/lib/telemetry';
import { testFlags } from '@/lib/testFlags';
import { sleep } from '@/lib/timeUtils';
Expand Down
27 changes: 23 additions & 4 deletions src/hooks/useNotificationTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,6 @@ export const notificationTypes: NotificationTypeConfig[] = [
// eslint-disable-next-line no-restricted-syntax
for (const transfer of transferNotifications) {
const { id, fromChainId, status, txHash, toAmount, type, isExchange } = transfer;
const isFinished =
(Boolean(status) && status?.squidTransactionStatus !== 'ongoing') || isExchange;
const icon = <Icon iconName={isFinished ? IconName.Transfer : IconName.Clock} />;

const transferType =
type ??
(fromChainId === selectedDydxChainId
Expand All @@ -233,6 +229,29 @@ export const notificationTypes: NotificationTypeConfig[] = [
<Icon iconName={isFinished ? IconName.Transfer : IconName.Clock} />
);

const title = isCosmosDeposit
? // TODO: Need to add localization
'Confirm Pending Deposit'
: stringGetter({
key: {
deposit: isFinished ? STRING_KEYS.DEPOSIT : STRING_KEYS.DEPOSIT_IN_PROGRESS,
withdrawal: isFinished ? STRING_KEYS.WITHDRAW : STRING_KEYS.WITHDRAW_IN_PROGRESS,
}[transferType],
});

const toChainEta = status?.toChain?.chainData?.estimatedRouteDuration ?? 0;
// TODO: remove typeguards once skip implements estimatedrouteduration
// https://linear.app/dydx/issue/OTE-475/[web]-migration-followup-estimatedrouteduration
const estimatedDuration =
typeof toChainEta === 'string' ? toChainEta : formatSeconds(Math.max(toChainEta, 0));
const body = stringGetter({
key: STRING_KEYS.DEPOSIT_STATUS,
params: {
AMOUNT_USD: `${toAmount} ${DydxChainAsset.USDC.toUpperCase()}`,
ESTIMATED_DURATION: estimatedDuration,
},
});

trigger(
id ?? txHash,
{
Expand Down
2 changes: 2 additions & 0 deletions src/lib/abacus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ class AbacusStateManager {
if (hdkey) this.chainTransactions.setHdkey(hdkey);
if (walletType === WalletType.Keplr) {
this.stateManager.cosmosWalletConnected = true;
} else {
this.stateManager.cosmosWalletConnected = false;
}
}
};
Expand Down
16 changes: 14 additions & 2 deletions src/lib/graz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,30 @@ import { BECH32_PREFIX, NOBLE_BECH32_PREFIX } from '@dydxprotocol/v4-client-js';
import { WalletType as GrazWalletType, type ConfigureGrazArgs } from 'graz';

import { LocalStorageKey } from '@/constants/localStorage';
import { DEFAULT_APP_ENVIRONMENT, ENVIRONMENT_CONFIG_MAP } from '@/constants/networks';
import { DEFAULT_APP_ENVIRONMENT, ENVIRONMENT_CONFIG_MAP, isMainnet } from '@/constants/networks';

import { getLocalStorage } from './localStorage';
import { validateAgainstAvailableEnvironments } from './network';
import { getNeutronChainId, getNobleChainId, getOsmosisChainId } from './squid';

const selectedNetwork = getLocalStorage({
key: LocalStorageKey.SelectedNetwork,
defaultValue: DEFAULT_APP_ENVIRONMENT,
validateFn: validateAgainstAvailableEnvironments,
});
const dydxChainId = ENVIRONMENT_CONFIG_MAP[selectedNetwork].dydxChainId;

export const getNobleChainId = () => {
return isMainnet ? 'noble-1' : 'grand-1';
};

export const getOsmosisChainId = () => {
return isMainnet ? 'osmosis-1' : 'osmo-test-5';
};

export const getNeutronChainId = () => {
return isMainnet ? 'neutron-1' : 'pion-1';
};

const osmosisChainId = getOsmosisChainId();
const nobleChainId = getNobleChainId();
const neutronChainId = getNeutronChainId();
Expand Down
12 changes: 0 additions & 12 deletions src/lib/squid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,6 @@ export const fetchSquidStatus = async (
return response.json();
};

export const getNobleChainId = () => {
return isMainnet ? 'noble-1' : 'grand-1';
};

export const getOsmosisChainId = () => {
return isMainnet ? 'osmosis-1' : 'osmo-test-5';
};

export const getNeutronChainId = () => {
return isMainnet ? 'neutron-1' : 'pion-1';
};

type SkipStatusParams = {
transactionHash: string;
chainId: string | undefined;
Expand Down
30 changes: 13 additions & 17 deletions src/views/dialogs/ConfirmPendingDepositDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const ConfirmPendingDepositDialog = ({
const selectedDydxChainId = useAppSelector(getSelectedDydxChainId);
const { dydxAddress } = useAccounts();

const { setAllTransferNotifications } = useLocalNotifications();
const { transferNotifications, addOrUpdateTransferNotification } = useLocalNotifications();
const stringGetter = useStringGetter();

const { deposit } = useSubaccount();
Expand All @@ -54,22 +54,18 @@ export const ConfirmPendingDepositDialog = ({
if (tx && dydxAddress) {
await refetchQuery();

setAllTransferNotifications((transferNotification) => {
return {
...transferNotification,
[dydxAddress]: transferNotification[dydxAddress].map((notification) => {
const isCosmosDeposit =
SUPPORTED_COSMOS_CHAINS.includes(notification.fromChainId ?? '') &&
notification.fromChainId !== selectedDydxChainId;
if (isCosmosDeposit) {
return {
...notification,
isSubaccountDepositCompleted: true,
};
}
return notification;
}),
};
transferNotifications.forEach((notification) => {
const isCosmosPendingDeposit =
SUPPORTED_COSMOS_CHAINS.includes(notification.fromChainId ?? '') &&
notification.fromChainId !== selectedDydxChainId &&
notification.isSubaccountDepositCompleted !== true;
if (isCosmosPendingDeposit) {
const updatedNotification = {
...notification,
isSubaccountDepositCompleted: true,
};
addOrUpdateTransferNotification(updatedNotification);
}
});
setIsOpen(false);
}
Expand Down
35 changes: 13 additions & 22 deletions src/views/dialogs/CosmosDepositDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@ import { GreenCheckCircle } from '@/components/GreenCheckCircle';
import { Icon, IconName } from '@/components/Icon';
import { LoadingSpinner } from '@/components/Loading/LoadingSpinner';

import {
getNeutronChainId,
getNobleChainId,
getOsmosisChainId,
MAX_TRACK_TX_ATTEMPTS,
trackSkipTxWithTenacity,
} from '@/lib/squid';
import { getNeutronChainId, getNobleChainId, getOsmosisChainId } from '@/lib/graz';
import { MAX_TRACK_TX_ATTEMPTS, trackSkipTxWithTenacity } from '@/lib/squid';

type ElementProps = {
setIsOpen: (open: boolean) => void;
Expand All @@ -46,7 +41,7 @@ export const CosmosDepositDialog = ({ setIsOpen, toAmount, txHash, fromChainId }

const [txStatus, setTxStatus] = useState<'success' | 'error' | 'pending'>('pending');

const { setAllTransferNotifications } = useLocalNotifications();
const { transferNotifications, addOrUpdateTransferNotification } = useLocalNotifications();

const depositToSubaccount = useCallback(async () => {
try {
Expand All @@ -73,19 +68,15 @@ export const CosmosDepositDialog = ({ setIsOpen, toAmount, txHash, fromChainId }
throw new Error('Transaction failed');
}

setAllTransferNotifications((transferNotification) => {
return {
...transferNotification,
[dydxAddress]: transferNotification[dydxAddress].map((notification) => {
if (notification.txHash === txHash) {
return {
...notification,
isSubaccountDepositCompleted: true,
};
}
return notification;
}),
};
const notification = transferNotifications.find((n) => n.txHash === txHash);

if (!notification) {
throw new Error('Notification not found');
}

addOrUpdateTransferNotification({
...notification,
isSubaccountDepositCompleted: true,
});

setTxStatus('success');
Expand Down Expand Up @@ -117,8 +108,8 @@ export const CosmosDepositDialog = ({ setIsOpen, toAmount, txHash, fromChainId }
setIsOpen?.(false);
};

const osmosisChainId = getOsmosisChainId();
const nobleChainId = getNobleChainId();
const osmosisChainId = getOsmosisChainId();
const neutronChainId = getNeutronChainId();
const chainName = (() => {
if (fromChainId === nobleChainId) {
Expand Down
10 changes: 5 additions & 5 deletions src/views/forms/AccountManagementForms/DepositForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ import { getTransferInputs } from '@/state/inputsSelectors';

import abacusStateManager from '@/lib/abacus';
import { track } from '@/lib/analytics';
import { SUPPORTED_COSMOS_CHAINS } from '@/lib/graz';
import { MustBigNumber } from '@/lib/numbers';
import {
getNeutronChainId,
getNobleChainId,
getOsmosisChainId,
NATIVE_TOKEN_ADDRESS,
} from '@/lib/squid';
SUPPORTED_COSMOS_CHAINS,
} from '@/lib/graz';
import { MustBigNumber } from '@/lib/numbers';
import { NATIVE_TOKEN_ADDRESS } from '@/lib/squid';
import { log } from '@/lib/telemetry';
import { parseWalletError } from '@/lib/wallet';

Expand Down Expand Up @@ -392,7 +392,7 @@ export const DepositForm = ({ onDeposit, onError }: DepositFormProps) => {
const txHash = tx?.transactionHash;

if (txHash) {
addTransferNotification({
addOrUpdateTransferNotification({
txHash,
toChainId: selectedDydxChainId,
fromChainId: chainIdStr || undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/views/forms/AccountManagementForms/TokenSelectMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { Tag } from '@/components/Tag';
import { useAppSelector } from '@/state/appTypes';
import { getTransferInputs } from '@/state/inputsSelectors';

import { getNeutronChainId, getNobleChainId, getOsmosisChainId } from '@/lib/squid';
import { getNeutronChainId, getNobleChainId, getOsmosisChainId } from '@/lib/graz';

import { LowestFeesDecoratorText } from './LowestFeesText';

Expand Down
2 changes: 1 addition & 1 deletion src/views/forms/AccountManagementForms/WithdrawForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ import abacusStateManager from '@/lib/abacus';
import { validateCosmosAddress } from '@/lib/addressUtils';
import { track } from '@/lib/analytics';
import { getRouteErrorMessageOverride } from '@/lib/errors';
import { getNeutronChainId, getNobleChainId, getOsmosisChainId } from '@/lib/graz';
import { MustBigNumber } from '@/lib/numbers';
import { getNeutronChainId, getNobleChainId, getOsmosisChainId } from '@/lib/squid';
import { log } from '@/lib/telemetry';

import { TokenSelectMenu } from './TokenSelectMenu';
Expand Down
2 changes: 1 addition & 1 deletion src/views/menus/AccountMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const AccountMenu = () => {
const showConfirmPendingDeposit =
walletType === WalletType.Keplr &&
MustBigNumber(usdcBalance).toNumber() > AMOUNT_RESERVED_FOR_GAS_USDC &&
MustBigNumber(usdcBalance).toFixed(2) !== '0.00';
MustBigNumber(usdcBalance).minus(AMOUNT_RESERVED_FOR_GAS_USDC).toFixed(2) !== '0.00';

let walletIcon;
if (onboardingState === OnboardingState.WalletConnected) {
Expand Down
Loading

0 comments on commit 0a2f03b

Please sign in to comment.