-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
11 changed files
with
115 additions
and
43 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
packages/checkout/sdk/src/blockExplorer/blockExplorer.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* eslint @typescript-eslint/naming-convention: off */ | ||
|
||
import { BLOCKSCOUT_CHAIN_URL_MAP } from '../env'; | ||
import { ChainId } from '../types'; | ||
import { BlockExplorerService } from './blockExplorer'; | ||
|
||
describe('BlockExplorerService', () => { | ||
it('Should not return link for unknown chainId', () => { | ||
const url = BlockExplorerService.getTransactionLink('unknown' as unknown as ChainId, '0x123'); | ||
expect(url).toBe(undefined); | ||
}); | ||
|
||
it('Should return link for known chainId', () => { | ||
const expectedUrl = BLOCKSCOUT_CHAIN_URL_MAP[ChainId.IMTBL_ZKEVM_TESTNET].url; | ||
const url = BlockExplorerService.getTransactionLink(ChainId.IMTBL_ZKEVM_TESTNET, '0x123'); | ||
expect(url).toBe(`${expectedUrl}/tx/0x123`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { BLOCKSCOUT_CHAIN_URL_MAP } from '../env'; | ||
import { ChainId } from '../types'; | ||
|
||
export class BlockExplorerService { | ||
/** | ||
* getTransationLink returns the link to the transaction on blockscout | ||
* @param hash transaction hash | ||
* @returns link to the transaction on blockscout | ||
*/ | ||
public static getTransactionLink(chainId: ChainId, hash: string): string | undefined { | ||
const url = BLOCKSCOUT_CHAIN_URL_MAP?.[chainId]?.url; | ||
if (!url || !hash) return undefined; | ||
|
||
return `${url}/tx/${hash}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { BlockExplorerService } from './blockExplorer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters