Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bridge-ui): bigint conversion #17534

Merged
merged 5 commits into from
Jun 9, 2024
Merged
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
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