Skip to content

Commit

Permalink
chore: further fixes, sdk update, added blocklist support
Browse files Browse the repository at this point in the history
  • Loading branch information
meeh0w committed Nov 6, 2024
1 parent 96f5d51 commit 10f45d4
Show file tree
Hide file tree
Showing 16 changed files with 222 additions and 228 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@avalabs/avalanche-module": "0.11.2",
"@avalabs/avalanchejs": "4.1.0-alpha.7",
"@avalabs/bitcoin-module": "0.11.2",
"@avalabs/bridge-unified": "0.0.0-feat-ab-missing-features-20241105143650",
"@avalabs/bridge-unified": "3.1.0",
"@avalabs/core-bridge-sdk": "3.1.0-alpha.10",
"@avalabs/core-chains-sdk": "3.1.0-alpha.10",
"@avalabs/core-coingecko-sdk": "3.1.0-alpha.10",
Expand Down
12 changes: 12 additions & 0 deletions src/background/services/featureFlags/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export enum FeatureGates {
SEEEDLESS_MFA_SETTINGS = 'seedless-mfa-settings',
SEEDLESS_OPTIONAL_MFA = 'seedless-optional-mfa',
UNIFIED_BRIDGE_CCTP = 'unified-bridge-cctp',
UNIFIED_BRIDGE_ICTT = 'unified-bridge-ictt',
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',
DEBANK_TRANSACTION_PARSING = 'debank-transaction-parsing',
DEBANK_TRANSACTION_PRE_EXECUTION = 'debank-transaction-pre-execution',
PRIMARY_ACCOUNT_REMOVAL = 'primary-account-removal',
Expand Down Expand Up @@ -76,6 +80,10 @@ export const DISABLED_FLAG_VALUES: FeatureFlags = {
[FeatureGates.SEEEDLESS_MFA_SETTINGS]: false,
[FeatureGates.SEEDLESS_OPTIONAL_MFA]: false,
[FeatureGates.UNIFIED_BRIDGE_CCTP]: false,
[FeatureGates.UNIFIED_BRIDGE_ICTT]: false,
[FeatureGates.UNIFIED_BRIDGE_AB_EVM]: false,
[FeatureGates.UNIFIED_BRIDGE_AB_AVA_TO_BTC]: false,
[FeatureGates.UNIFIED_BRIDGE_AB_BTC_TO_AVA]: false,
[FeatureGates.DEBANK_TRANSACTION_PARSING]: false,
[FeatureGates.DEBANK_TRANSACTION_PRE_EXECUTION]: false,
[FeatureGates.PRIMARY_ACCOUNT_REMOVAL]: false,
Expand Down Expand Up @@ -121,6 +129,10 @@ export const DEFAULT_FLAGS: FeatureFlags = {
[FeatureGates.SEEEDLESS_MFA_SETTINGS]: true,
[FeatureGates.SEEDLESS_OPTIONAL_MFA]: true,
[FeatureGates.UNIFIED_BRIDGE_CCTP]: true,
[FeatureGates.UNIFIED_BRIDGE_ICTT]: true,
[FeatureGates.UNIFIED_BRIDGE_AB_EVM]: true,
[FeatureGates.UNIFIED_BRIDGE_AB_AVA_TO_BTC]: true,
[FeatureGates.UNIFIED_BRIDGE_AB_BTC_TO_AVA]: true,
[FeatureGates.DEBANK_TRANSACTION_PARSING]: false,
[FeatureGates.DEBANK_TRANSACTION_PRE_EXECUTION]: false,
[FeatureGates.PRIMARY_ACCOUNT_REMOVAL]: true,
Expand Down
35 changes: 16 additions & 19 deletions src/background/services/unifiedBridge/UnifiedBridgeService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('src/background/services/unifiedBridge/UnifiedBridgeService', () => {
isMainnet: jest.fn(),
getNetwork: jest.fn(),
getProviderForNetwork: jest.fn(),
getBitcoinProvider: jest.fn(),
sendTransaction: jest.fn(),
} as any;

Expand All @@ -41,6 +42,10 @@ describe('src/background/services/unifiedBridge/UnifiedBridgeService', () => {
featureFlags: {
[FeatureGates.IMPORT_FIREBLOCKS]: true,
[FeatureGates.UNIFIED_BRIDGE_CCTP]: true,
[FeatureGates.UNIFIED_BRIDGE_ICTT]: true,
[FeatureGates.UNIFIED_BRIDGE_AB_AVA_TO_BTC]: true,
[FeatureGates.UNIFIED_BRIDGE_AB_BTC_TO_AVA]: true,
[FeatureGates.UNIFIED_BRIDGE_AB_EVM]: true,
},
addListener: jest.fn(),
} as any;
Expand All @@ -64,6 +69,7 @@ describe('src/background/services/unifiedBridge/UnifiedBridgeService', () => {
networkService.getNetwork.mockImplementation(async (chainId) => ({
chainId,
}));
networkService.getBitcoinProvider.mockResolvedValue({} as any);
});

it('creates core instance with proper environment', async () => {
Expand Down Expand Up @@ -118,6 +124,10 @@ describe('src/background/services/unifiedBridge/UnifiedBridgeService', () => {
// Toggle an irrelevant flag off
mockFeatureFlagChanges({
[FeatureGates.UNIFIED_BRIDGE_CCTP]: true,
[FeatureGates.UNIFIED_BRIDGE_ICTT]: true,
[FeatureGates.UNIFIED_BRIDGE_AB_AVA_TO_BTC]: true,
[FeatureGates.UNIFIED_BRIDGE_AB_BTC_TO_AVA]: true,
[FeatureGates.UNIFIED_BRIDGE_AB_EVM]: true,
[FeatureGates.IMPORT_FIREBLOCKS]: false,
});

Expand All @@ -127,6 +137,10 @@ describe('src/background/services/unifiedBridge/UnifiedBridgeService', () => {
// Toggle a relevant flag off
mockFeatureFlagChanges({
[FeatureGates.UNIFIED_BRIDGE_CCTP]: false,
[FeatureGates.UNIFIED_BRIDGE_ICTT]: true,
[FeatureGates.UNIFIED_BRIDGE_AB_AVA_TO_BTC]: true,
[FeatureGates.UNIFIED_BRIDGE_AB_BTC_TO_AVA]: true,
[FeatureGates.UNIFIED_BRIDGE_AB_EVM]: true,
[FeatureGates.IMPORT_FIREBLOCKS]: false,
});

Expand Down Expand Up @@ -180,30 +194,13 @@ describe('src/background/services/unifiedBridge/UnifiedBridgeService', () => {
});

new UnifiedBridgeService(networkService, storageService, flagsService);
await jest.runAllTimersAsync();
await jest.runAllTicks();

expect(getEnabledBridgeServices).toHaveBeenCalledTimes(1);
expect(getEnabledBridgeServices).toHaveBeenCalledTimes(4);
expect(wait).toHaveBeenNthCalledWith(1, 2000);

jest.advanceTimersByTime(2000);
await jest.runOnlyPendingTimers();
await jest.runAllTicks();

expect(getEnabledBridgeServices).toHaveBeenCalledTimes(2);
expect(wait).toHaveBeenNthCalledWith(2, 4000);

jest.advanceTimersByTime(4000);
await jest.runOnlyPendingTimers();
await jest.runAllTicks();

expect(getEnabledBridgeServices).toHaveBeenCalledTimes(3);
expect(wait).toHaveBeenNthCalledWith(3, 8000);

jest.advanceTimersByTime(8000);
await jest.runOnlyPendingTimers();
await jest.runAllTicks();

expect(getEnabledBridgeServices).toHaveBeenCalledTimes(4);
expect(createUnifiedBridgeService).toHaveBeenCalled();
});
});
Expand Down
12 changes: 4 additions & 8 deletions src/background/services/unifiedBridge/UnifiedBridgeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
import sentryCaptureException, {
SentryExceptionTypes,
} from '@src/monitoring/sentryCaptureException';
import { getEnabledBridgeTypes } from '@src/utils/getEnabledBridgeTypes';

@singleton()
export class UnifiedBridgeService implements OnStorageReady {
Expand Down Expand Up @@ -115,14 +116,9 @@ export class UnifiedBridgeService implements OnStorageReady {
#getBridgeInitializers(
bitcoinProvider: BitcoinProvider
): BridgeInitializer[] {
// TODO: feature flag those
return [
BridgeType.CCTP,
BridgeType.ICTT_ERC20_ERC20,
BridgeType.AVALANCHE_EVM,
BridgeType.AVALANCHE_AVA_BTC,
BridgeType.AVALANCHE_BTC_AVA,
].map((type) => this.#getInitializerForBridgeType(type, bitcoinProvider));
return getEnabledBridgeTypes(this.#flagStates).map((type) =>
this.#getInitializerForBridgeType(type, bitcoinProvider)
);
}

#getInitializerForBridgeType(
Expand Down
8 changes: 7 additions & 1 deletion src/background/services/unifiedBridge/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ export type UnifiedBridgeState = {
pendingTransfers: Record<string, BridgeTransfer>;
};

export const UNIFIED_BRIDGE_TRACKED_FLAGS = [FeatureGates.UNIFIED_BRIDGE_CCTP];
export const UNIFIED_BRIDGE_TRACKED_FLAGS = [
FeatureGates.UNIFIED_BRIDGE_CCTP,
FeatureGates.UNIFIED_BRIDGE_ICTT,
FeatureGates.UNIFIED_BRIDGE_AB_AVA_TO_BTC,
FeatureGates.UNIFIED_BRIDGE_AB_BTC_TO_AVA,
FeatureGates.UNIFIED_BRIDGE_AB_EVM,
];

export const UNIFIED_BRIDGE_DEFAULT_STATE: UnifiedBridgeState = {
pendingTransfers: {},
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/CustomFees.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ export function CustomFees({
<Stack sx={{ py: 0.5 }}>
<Typography variant="caption" sx={{ color: 'error.main' }}>
<Trans
i18nKey="Insufficient balance to cover gas costs. <br />Please add {{tokenSymbol}}."
i18nKey="Insufficient balance to cover gas costs. Please add {{tokenSymbol}}."
values={{ tokenSymbol: network?.networkToken.symbol }}
/>
</Typography>
Expand Down
9 changes: 8 additions & 1 deletion src/contexts/FeatureFlagsProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isEqual } from 'lodash';
import {
DEFAULT_FLAGS,
FeatureGates,
Expand Down Expand Up @@ -30,7 +31,13 @@ export function FeatureFlagsContextProvider({ children }: { children: any }) {
map((evt) => evt.value)
)
.subscribe((result) => {
setFeatureFlags(result);
setFeatureFlags((prevFlags) => {
if (isEqual(prevFlags, result)) {
// Prevent re-renders when nothing changed
return prevFlags;
}
return result;
});
});
return () => {
subscription.unsubscribe();
Expand Down
Loading

0 comments on commit 10f45d4

Please sign in to comment.