Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@keystonehq/hw-app-eth": "0.4.4",
"@keystonehq/hw-transport-webusb": "0.5.1",
"@keystonehq/ur-decoder": "0.9.2",
"@layerzerolabs/lz-v2-utilities": "3.0.17",
"@metamask/eth-sig-util": "4.0.1",
"@metamask/rpc-errors": "6.3.0",
"@noble/curves": "1.6.0",
Expand Down
22 changes: 21 additions & 1 deletion apps/legacy/src/pages/Bridge/BridgeTransactionStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,26 @@ const BridgeTransactionStatus = () => {

const hasOffBoardingDelay = typeof offboardingDelay === 'number';

/**
* For Unified Bridge, the source transfer is complete when the source
* confirmation count is greater than or equal to the source required
* confirmation count. This is because it can much longer for the target
* transaction to be created so we can't rely on targetStartedAt
*/
const isBridgeSourceTransferComplete = useMemo(() => {
if (!bridgeTransaction) {
return false;
}
if (isUnifiedBridgeTransfer(bridgeTransaction)) {
return (
bridgeTransaction.sourceConfirmationCount >=
bridgeTransaction.sourceRequiredConfirmationCount
);
}

return Boolean(bridgeTransaction.targetStartedAt);
}, [bridgeTransaction]);

if (!activeAccount) {
history.push('/home');
return null;
Expand Down Expand Up @@ -277,7 +297,7 @@ const BridgeTransactionStatus = () => {
</Card>
<BridgeCard // from chain (Middle Card)
isWaiting={false} // starts immediately
isDone={Boolean(bridgeTransaction.targetStartedAt)}
isDone={isBridgeSourceTransferComplete}
isTransferComplete={isComplete}
>
<Stack
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { getEstimatedBridgingTime } from '@avalabs/bridge-unified';
import { BridgeType } from '@avalabs/bridge-unified';
import {
AlertCircleIcon,
Stack,
Typography,
useTheme,
} from '@avalabs/core-k2-components';
import { NetworkWithCaipId } from '@core/types';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';

interface BridgeTimeWarningProps {
bridgeType?: BridgeType;
targetChain?: NetworkWithCaipId;
}

export const BridgeEstimatedTimeWarning = ({
bridgeType,
targetChain,
}: BridgeTimeWarningProps) => {
const { t } = useTranslation();
const [estimatedTime, setEstimatedTime] = useState<number>();
const theme = useTheme();

useEffect(() => {
if (bridgeType) {
setEstimatedTime(getEstimatedBridgingTime(bridgeType));
}
}, [bridgeType]);

if (!bridgeType || !estimatedTime || !targetChain) {
return null;
}

return (
<Stack direction="row" alignItems="center" gap={1}>
<Typography variant="caption" color={theme.palette.error.main}>
{t(
'Bridging to {{targetChain}} can take up to {{estimatedTime}} hours',
{
targetChain: targetChain?.chainName,
estimatedTime,
},
)}
</Typography>

<AlertCircleIcon size={16} color={theme.palette.error.main} />
</Stack>
);
};
8 changes: 7 additions & 1 deletion apps/legacy/src/pages/Bridge/components/BridgeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { NetworkFee } from '@core/types';
import { findMatchingBridgeAsset, isBitcoinNetwork } from '@core/common';
import { BridgeTypeFootnote } from './BridgeTypeFootnote';
import { NetworkSelector } from './NetworkSelector';
import { BridgeEstimatedTimeWarning } from './BridgeEstimatedTimeWarning';

export type BridgeFormProps = ReturnType<typeof useBridge> & {
isPending: boolean;
Expand Down Expand Up @@ -335,7 +336,7 @@ export const BridgeForm = ({
pointerEvents: isPending ? 'none' : 'auto',
}}
>
<Stack ref={cardRef} sx={{ p: 0, overflow: 'unset' }}>
<Stack ref={cardRef} sx={{ p: 0, overflow: 'unset', gap: 1 }}>
<Stack sx={{ width: '100%' }}>
{/* From section */}
<Card
Expand Down Expand Up @@ -537,6 +538,11 @@ export const BridgeForm = ({
</Card>
</Slide>
</Stack>

<BridgeEstimatedTimeWarning
bridgeType={bridgeType}
targetChain={targetChain}
/>
Comment on lines +542 to +545
Copy link
Member

@meeh0w meeh0w Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be displayed in the BridgeTransactionStatus too (please disregard the rest of the UI on the right screenshot, we will not be changing anything in there besides adding the red note at the bottom - ideally in between the source and target network cards).

Image

</Stack>
</Stack>
{withFeeBox && neededGas && (
Expand Down
13 changes: 10 additions & 3 deletions packages/common/src/utils/getEnabledBridgeTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BridgeType } from '@avalabs/bridge-unified';
import { FeatureFlags, FeatureGates } from '@core/types';
import { type FeatureFlags, FeatureGates } from '@core/types';

export const getEnabledBridgeTypes = (featureFlags: Partial<FeatureFlags>) => {
const enabled: BridgeType[] = [];
Expand All @@ -13,10 +13,17 @@ export const getEnabledBridgeTypes = (featureFlags: Partial<FeatureFlags>) => {
if (featureFlags[FeatureGates.UNIFIED_BRIDGE_AB_EVM]) {
enabled.push(BridgeType.AVALANCHE_EVM);
}
if (featureFlags[FeatureGates.UNIFIED_BRIDGE_AB_BTC_TO_AVA]) {
if (featureFlags[FeatureGates.UNIFIED_BRIDGE_LOMBARD_BTC_TO_AVA]) {
enabled.push(BridgeType.LOMBARD_BTC_TO_BTCB);
} else if (featureFlags[FeatureGates.UNIFIED_BRIDGE_AB_BTC_TO_AVA]) {
// Make sure to not enable both at the same time
enabled.push(BridgeType.AVALANCHE_BTC_AVA);
}
if (featureFlags[FeatureGates.UNIFIED_BRIDGE_AB_AVA_TO_BTC]) {

if (featureFlags[FeatureGates.UNIFIED_BRIDGE_LOMBARD_AVA_TO_BTC]) {
enabled.push(BridgeType.LOMBARD_BTCB_TO_BTC);
} else if (featureFlags[FeatureGates.UNIFIED_BRIDGE_AB_AVA_TO_BTC]) {
// Make sure to not enable both at the same time
enabled.push(BridgeType.AVALANCHE_AVA_BTC);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/service-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"argon2-browser": "1.18.0",
"bip32": "2.0.6",
"bip39": "3.0.4",
"bitcoinjs-lib": "5.2.0",
"bitcoinjs-lib": "6.1.5",
"bn.js": "5.2.1",
"buffer": "6.0.3",
"date-fns": "2.28.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/service-worker/rsbuild.worker.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default defineConfig(() => {
// Joi by default goes to browser-specific version which does not include the list of TLDS (which we need for email validation)
joi: require.resolve('joi/lib/index.js'),
},
dedupe: ['bn.js', 'bitcoinjs-lib', 'ledger-bitcoin'],
dedupe: ['bn.js', 'ledger-bitcoin'],
fallback: {
path: false,
fs: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ export class UnifiedBridgeService implements OnStorageReady {
async sign() {
return '0x' as const;
},
async signMessage() {
return '0x' as const;
},
};

switch (type) {
Expand All @@ -153,6 +156,15 @@ export class UnifiedBridgeService implements OnStorageReady {
signer: dummySigner,
bitcoinFunctions: bitcoinProvider,
};

case BridgeType.LOMBARD_BTC_TO_BTCB:
case BridgeType.LOMBARD_BTCB_TO_BTC:
return {
type,
evmSigner: dummySigner,
btcSigner: dummySigner,
bitcoinFunctions: bitcoinProvider,
};
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/service-worker/src/services/wallet/WalletService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,10 @@ export class WalletService implements OnUnlock {
return { signedTx: signingResult.toHex() };
}

if ('toHex' in signingResult && typeof signingResult.toHex === 'function') {
return { signedTx: signingResult.toHex() as string };
}

return signingResult;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export enum FeatureGates {
UNIFIED_BRIDGE_AB_EVM = 'unified-bridge-ab-evm',
UNIFIED_BRIDGE_AB_AVA_TO_BTC = 'unified-bridge-ab-ava-to-btc',
UNIFIED_BRIDGE_AB_BTC_TO_AVA = 'unified-bridge-ab-btc-to-ava',
UNIFIED_BRIDGE_LOMBARD_BTC_TO_AVA = 'unified-bridge-lombard-btc-to-ava',
UNIFIED_BRIDGE_LOMBARD_AVA_TO_BTC = 'unified-bridge-lombard-ava-to-btc',
DEBANK_TRANSACTION_PARSING = 'debank-transaction-parsing',
DEBANK_TRANSACTION_PRE_EXECUTION = 'debank-transaction-pre-execution',
PRIMARY_ACCOUNT_REMOVAL = 'primary-account-removal',
Expand Down
74 changes: 72 additions & 2 deletions packages/ui/src/contexts/UnifiedBridgeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
BtcSigner,
Chain,
Environment,
EvmSigner,
EvmSignerWithMessage,
GasSettings,
TokenType,
ErrorCode as UnifiedBridgeErrorCode,
Expand Down Expand Up @@ -58,6 +58,7 @@ import { useAccountsContext } from './AccountsProvider';
import { useConnectionContext } from './ConnectionProvider';
import { useFeatureFlagContext } from './FeatureFlagsProvider';
import { useNetworkContext } from './NetworkProvider';
import { hex, utf8 } from '@scure/base';

export interface UnifiedBridgeContext {
estimateTransferGas(
Expand Down Expand Up @@ -163,8 +164,56 @@ export function UnifiedBridgeProvider({ children }: PropsWithChildren) {
const [activeBridgeTypes, setActiveBridgeTypes] =
useState<BridgeServicesMap>();

const evmSigner: EvmSigner = useMemo(
const evmSigner: EvmSignerWithMessage = useMemo(
() => ({
signMessage: async (
data: { message: string; address: `0x${string}`; chainId: number },
_,
{ currentSignature, requiredSignatures },
) => {
const { message, address, chainId } = data;

assert(message, UnifiedBridgeError.InvalidTxPayload);
assert(address, UnifiedBridgeError.InvalidTxPayload);

try {
const result = await request(
{
method: RpcMethod.PERSONAL_SIGN,
params: [`0x${hex.encode(utf8.decode(message))}`, address],
},
{
scope: `eip155:${chainId}`,
context: {
customApprovalScreenTitle: t('Confirm Bridge'),
alert:
requiredSignatures > currentSignature
? {
type: 'info',
title: t(
'This operation requires {{total}} approvals.',
{
total: requiredSignatures,
},
),
notice: t(
'You will be prompted {{remaining}} more time(s).',
{
remaining: requiredSignatures - currentSignature,
},
),
}
: undefined,
},
},
);

return result as `0x${string}`;
} catch (err) {
console.error(err);
throw err;
}
},
sign: async (
{ from, data, to, value },
_,
Expand Down Expand Up @@ -331,6 +380,22 @@ export function UnifiedBridgeProvider({ children }: PropsWithChildren) {
signer: btcSigner,
bitcoinFunctions,
};

case BridgeType.LOMBARD_BTC_TO_BTCB:
return {
type,
evmSigner,
btcSigner,
bitcoinFunctions,
};

case BridgeType.LOMBARD_BTCB_TO_BTC:
return {
type,
evmSigner,
btcSigner,
bitcoinFunctions,
};
}
},
[evmSigner, btcSigner],
Expand Down Expand Up @@ -684,6 +749,11 @@ export function UnifiedBridgeProvider({ children }: PropsWithChildren) {
case UnifiedBridgeErrorCode.TIMEOUT:
return t('The transaction timed out');

case UnifiedBridgeErrorCode.NOTARIZATION_FAILED:
return t(
'Notarization failed for deposit. Your deposit is safe, please contact support to complete the bridge.',
);

case UnifiedBridgeErrorCode.TRANSACTION_REVERTED:
return t('The transaction has been reverted');
}
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/hooks/usePendingBridgeTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const usePendingBridgeTransactions = () => {
const {
state: { pendingTransfers: unifiedBridgeTransfers },
} = useUnifiedBridgeContext();

const bridgeTransactions = useMemo(() => {
return [
...Object.values(legacyBridgeTransfers),
Expand Down
Loading