Skip to content

Commit

Permalink
fix(bridge-ui): bigint conversion (#17534)
Browse files Browse the repository at this point in the history
  • Loading branch information
KorbinianK committed Jun 9, 2024
1 parent 006e522 commit 4279ccd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
56 changes: 27 additions & 29 deletions packages/bridge-ui/src/libs/relayer/RelayerAPIService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,30 @@ function setupMocks() {
vi.mock('axios');
vi.mock('@wagmi/core');
vi.mock('@web3modal/wagmi');
vi.mock('$customToken', () => {
return {
customToken: [
{
name: 'Bull Token',
addresses: {
'31336': '0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0',
'167002': '0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE',
},
symbol: 'BLL',
decimals: 18,
type: 'ERC20',
logoURI: 'ipfs://QmezMTpT6ovJ3szb3SKDM9GVGeQ1R8DfjYyXG12ppMe2BY',
mintable: true,
},
{
name: 'Horse Token',
addresses: {
'31336': '0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e',
'167002': '0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1',
},
symbol: 'HORSE',
decimals: 18,
type: 'ERC20',
logoURI: 'ipfs://QmU52ZxmSiGX24uDPNUGG3URyZr5aQdLpACCiD6tap4Mgc',
mintable: true,
vi.mock('$bridgeConfig', () => ({
routingContractsMap: {
1: {
167000: { bridgeAddress: '0xd60247c6848b7ca29eddf63aa924e53db6ddd8ec' },
},
167000: {
1: {
bridgeAddress: '',
},
],
};
});
},
},
}));
}

describe('RelayerAPIService', () => {
beforeEach(() => {
setupMocks();
});

afterEach(() => {
vi.clearAllMocks();
vi.resetAllMocks();
});

// Given
const mockedAxios = vi.mocked(axios, true);

Expand Down Expand Up @@ -78,6 +65,17 @@ describe('RelayerAPIService', () => {
const paginationParams = { page: 1, size: 10 };
const chainID = 1;

const mockResponse = {
data: {
page: 1,
size: 10,
total: 100,
items: [],
},
status: 200,
};
mockedAxios.get.mockResolvedValue(mockResponse);

// When
const result = await relayerAPIService.getAllBridgeTransactionByAddress(address, paginationParams, chainID);

Expand Down
12 changes: 7 additions & 5 deletions packages/bridge-ui/src/libs/relayer/RelayerAPIService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export class RelayerAPIService {
}

const items = RelayerAPIService._filterDuplicateAndWrongBridge(apiTxs.items);

const txs: BridgeTransaction[] = items.map((tx: APIResponseTransaction) => {
let data: string | Hex = tx.data.Message.Data;
if (data === '') {
Expand All @@ -178,11 +179,10 @@ export class RelayerAPIService {
}

const tokenType: TokenType = _eventToTokenType(tx.eventType);
const value = tokenType === TokenType.ETH ? BigInt(tx.amount) : BigInt(0);

const transformedTx = {
status: tx.status,
amount: BigInt(tx.amount),
amount: BigInt(tx.amount.toString()),
symbol: tx.canonicalTokenSymbol || 'ETH',
decimals: tx.canonicalTokenDecimals,
hash: tx.data.Raw.transactionHash,
Expand All @@ -200,11 +200,11 @@ export class RelayerAPIService {
data: data as Hex,
srcOwner: tx.data.Message.SrcOwner,
from: tx.data.Message.From,
gasLimit: Number(tx.data.Message.GasLimit),
value: value,
gasLimit: tx.data.Message.GasLimit,
value: BigInt(tx.data.Message.Value.toString()),
srcChainId: BigInt(tx.data.Message.SrcChainId),
destChainId: BigInt(tx.data.Message.DestChainId),
fee: BigInt(tx.data.Message.Fee),
fee: BigInt(tx.data.Message.Fee.toString()),
},
} satisfies BridgeTransaction;

Expand All @@ -213,6 +213,7 @@ export class RelayerAPIService {

const txsPromises = txs.map(async (bridgeTx) => {
if (!bridgeTx) return;

if (bridgeTx.from.toLowerCase() !== address.toLowerCase()) return;
const { destChainId, srcChainId, hash, msgHash } = bridgeTx;

Expand All @@ -237,6 +238,7 @@ export class RelayerAPIService {

// Update the status
bridgeTx.msgStatus = msgStatus;

return bridgeTx;
});

Expand Down

0 comments on commit 4279ccd

Please sign in to comment.