Skip to content

Commit

Permalink
refactor: migrate bridge logic to frontend (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
meeh0w authored Aug 2, 2024
1 parent b865c93 commit 8385aea
Show file tree
Hide file tree
Showing 65 changed files with 3,819 additions and 3,819 deletions.
9 changes: 0 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,7 @@
},
"lavamoat": {
"allowScripts": {
"@avalabs/bridge-sdk>@avalabs/wallets-sdk>@ledgerhq/hw-app-btc>bitcoinjs-lib>bip32>tiny-secp256k1": false,
"@ethereumjs/common>ethereumjs-util>ethereum-cryptography>keccak": false,
"@avalabs/bridge-sdk>@avalabs/wallets-sdk>web3": false,
"@avalabs/bridge-sdk>@avalabs/wallets-sdk>web3>web3-bzz": false,
"@avalabs/bridge-sdk>@avalabs/wallets-sdk>web3>web3-core>web3-core-requestmanager>web3-providers-ws>websocket>bufferutil": false,
"@avalabs/bridge-sdk>@avalabs/wallets-sdk>web3>web3-core>web3-core-requestmanager>web3-providers-ws>websocket>es5-ext": false,
"@avalabs/bridge-sdk>@avalabs/wallets-sdk>web3>web3-core>web3-core-requestmanager>web3-providers-ws>websocket>utf-8-validate": false,
"@avalabs/bridge-sdk>@avalabs/wallets-sdk>web3>web3-shh": false,
"@avalabs/bridge-sdk>@avalabs/wallets-sdk>hdkey>secp256k1": false,
"@lavamoat/preinstall-always-fail": false,
"@types/web3>web3": false,
"@types/web3>web3>web3-bzz": false,
Expand All @@ -240,7 +232,6 @@
"web3>web3-bzz": false,
"web3>web3-shh": false,
"yarn": false,
"@avalabs/bridge-sdk>@avalabs/wallets-sdk>@avalabs/hw-app-avalanche>@ledgerhq/hw-app-eth>@ledgerhq/domain-service>eip55>keccak": false,
"@avalabs/vm-module-types": false,
"@avalabs/vm-module-types>@avalabs/wallets-sdk>@avalabs/hw-app-avalanche>@ledgerhq/hw-app-eth>@ledgerhq/domain-service>eip55>keccak": false,
"@avalabs/vm-module-types>@avalabs/wallets-sdk>@ledgerhq/hw-app-btc>bitcoinjs-lib>bip32>tiny-secp256k1": false,
Expand Down
1 change: 1 addition & 0 deletions src/background/connections/extensionConnection/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export enum ExtensionRequest {
UNIFIED_BRIDGE_GET_FEE = 'unified_bridge_get_fee',
UNIFIED_BRIDGE_ESTIMATE_GAS = 'unified_bridge_estimate_gas',
UNIFIED_BRIDGE_TRANSFER_ASSET = 'unified_bridge_transfer_asset',
UNIFIED_BRIDGE_TRACK_TRANSFER = 'unified_bridge_track_transfer',
UNIFIED_BRIDGE_GET_STATE = 'unified_bridge_get_state',
UNIFIED_BRIDGE_GET_ASSETS = 'unified_bridge_get_assets',

Expand Down
26 changes: 2 additions & 24 deletions src/background/connections/extensionConnection/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { BridgeGetConfigHandler } from '@src/background/services/bridge/handlers
import { BridgeGetStateHandler } from '@src/background/services/bridge/handlers/getBridgeState';
import { BridgeRemoveTransactionHandler } from '@src/background/services/bridge/handlers/removeBridgeTransaction';
import { BridgeSetIsDevEnvHandler } from '@src/background/services/bridge/handlers/setIsDevEnv';
import { BridgeTransferAssetHandler } from '@src/background/services/bridge/handlers/transferAsset';
import { ContactsUpdatedEvents } from '@src/background/services/contacts/events/contactsUpdatedEvent';
import { CreateContactHandler } from '@src/background/services/contacts/handlers/createContact';
import { GetContactsHandler } from '@src/background/services/contacts/handlers/getContacts';
Expand Down Expand Up @@ -75,7 +74,6 @@ import { RemoveFavoriteNetworkHandler } from '@src/background/services/network/h
import { GetNetworksStateHandler } from '@src/background/services/network/handlers/getNetworkState';
import { GetFeatureFlagsHandler } from '@src/background/services/featureFlags/handlers/getFeatureFlags';
import { FeatureFlagsUpdatedEvent } from '@src/background/services/featureFlags/events/featureFlagsUpdatedEvent';
import { GetEthMaxTransferAmountHandler } from '@src/background/services/bridge/handlers/getEthMaxTransferAmount';
import { CloseLedgerTransportHandler } from '@src/background/services/ledger/handlers/closeOpenTransporters';
import { LedgerCloseTransportEvent } from '@src/background/services/ledger/events/ledgerCloseTransport';
import { GetAvaxBalanceHandler } from '@src/background/services/balances/handlers/getAvaxBalance';
Expand Down Expand Up @@ -107,14 +105,10 @@ import { GetRecoveryPhraseExportStateHandler } from '@src/background/services/se
import { InitRecoveryPhraseExportHandler } from '@src/background/services/seedless/handlers/initRecoveryPhraseExport';
import { CompleteRecoveryPhraseExportHandler } from '@src/background/services/seedless/handlers/completeRecoveryPhraseExport';
import { CancelRecoveryPhraseExportHandler } from '@src/background/services/seedless/handlers/cancelRecoveryPhraseExport';
import { UnifiedBridgeTransferAsset } from '@src/background/services/unifiedBridge/handlers/unifiedBridgeTransferAsset';
import { UnifiedBridgeGetFee } from '@src/background/services/unifiedBridge/handlers/unifiedBridgeGetFee';
import { UnifiedBridgeGetState } from '@src/background/services/unifiedBridge/handlers/unifiedBridgeGetState';
import { UnifiedBridgeGetAssets } from '@src/background/services/unifiedBridge/handlers/unifiedBridgeGetAssets';
import { UnifiedBridgeEvents } from '@src/background/services/unifiedBridge/events/unifiedBridgeEvents';
import { GetPrivateKeyHandler } from '@src/background/services/accounts/handlers/getPrivateKey';
import { EstimateGasForBridgeTxHandler } from '@src/background/services/bridge/handlers/estimateGasForBridgeTx';
import { UnifiedBridgeEstimateGas } from '@src/background/services/unifiedBridge/handlers/unifiedBridgeEstimateGas';
import { ImportSeedPhraseHandler } from '@src/background/services/wallet/handlers/importSeedPhrase';
import { ImportLedgerHandler } from '@src/background/services/wallet/handlers/importLedger';
import { GetRecoveryMethodsHandler } from '@src/background/services/seedless/handlers/getRecoveryMethods';
Expand All @@ -134,6 +128,7 @@ import { SetActiveNetworkHandler } from '@src/background/services/network/handle
import { StartBalancesPollingHandler } from '@src/background/services/balances/handlers/startBalancesPolling';
import { StopBalancesPollingHandler } from '@src/background/services/balances/handlers/stopBalancesPolling';
import { BalancesUpdatedEvents } from '@src/background/services/balances/events/balancesUpdatedEvent';
import { UnifiedBridgeTrackTransfer } from '@src/background/services/unifiedBridge/handlers/unifiedBridgeTrackTransfer';

/**
* TODO: GENERATE THIS FILE AS PART OF THE BUILD PROCESS
Expand Down Expand Up @@ -171,11 +166,6 @@ import { BalancesUpdatedEvents } from '@src/background/services/balances/events/
token: 'ExtensionRequestHandler',
useToken: BridgeRemoveTransactionHandler,
},
{ token: 'ExtensionRequestHandler', useToken: BridgeTransferAssetHandler },
{
token: 'ExtensionRequestHandler',
useToken: GetEthMaxTransferAmountHandler,
},
{ token: 'ExtensionRequestHandler', useToken: CreateContactHandler },
{ token: 'ExtensionRequestHandler', useToken: GetContactsHandler },
{ token: 'ExtensionRequestHandler', useToken: UpdateContactHandler },
Expand Down Expand Up @@ -318,20 +308,12 @@ import { BalancesUpdatedEvents } from '@src/background/services/balances/events/
},
{
token: 'ExtensionRequestHandler',
useToken: UnifiedBridgeTransferAsset,
},
{
token: 'ExtensionRequestHandler',
useToken: UnifiedBridgeGetFee,
useToken: UnifiedBridgeTrackTransfer,
},
{
token: 'ExtensionRequestHandler',
useToken: UnifiedBridgeGetState,
},
{
token: 'ExtensionRequestHandler',
useToken: UnifiedBridgeGetAssets,
},
{
token: 'ExtensionRequestHandler',
useToken: GetPrivateKeyHandler,
Expand All @@ -340,10 +322,6 @@ import { BalancesUpdatedEvents } from '@src/background/services/balances/events/
token: 'ExtensionRequestHandler',
useToken: EstimateGasForBridgeTxHandler,
},
{
token: 'ExtensionRequestHandler',
useToken: UnifiedBridgeEstimateGas,
},
{
token: 'ExtensionRequestHandler',
useToken: ImportSeedPhraseHandler,
Expand Down
6 changes: 6 additions & 0 deletions src/background/services/balances/handlers/getNftBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export class GetNftBalancesHandler implements HandlerType {
[TokenType.ERC1155]: undefined,
};
}
if (!scope) {
return {
...request,
error: 'No request scope provided',
};
}
const currentNetwork = await this.networkService.getNetwork(scope);

if (!currentNetwork) {
Expand Down
6 changes: 5 additions & 1 deletion src/background/services/blockaid/BlockaidService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ export class BlockaidService {
from: tx.from,
to: tx.to,
data: tx.data,
value: tx.value,
// BigInt cannot be JSON-stringified
value:
typeof tx.value === 'bigint'
? `0x${tx.value.toString(16)}`
: tx.value,
},
metadata: { domain },
});
Expand Down
Loading

0 comments on commit 8385aea

Please sign in to comment.