-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: use subnets explorer url for transaction URLs * feat: refactor URL util * fix: use glacier for C chain txs
- Loading branch information
1 parent
577382f
commit 6c8bf0f
Showing
5 changed files
with
79 additions
and
25 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { getTxURL } from '@/js/Glacier/getTxURL' | ||
|
||
describe('getTxURL', () => { | ||
it('can get mainnet url for X Chain', () => { | ||
const url = getTxURL('hash1', 'X', true) | ||
expect(url).toEqual('https://subnets.avax.network/x-chain/tx/hash1') | ||
}) | ||
|
||
it('can get mainnet url for P Chain', () => { | ||
const url = getTxURL('hash1', 'P', true) | ||
expect(url).toEqual('https://subnets.avax.network/p-chain/tx/hash1') | ||
}) | ||
|
||
it('can get mainnet url for C Chain', () => { | ||
const url = getTxURL('hash1', 'C', true) | ||
expect(url).toEqual('https://avascan.info/blockchain/c/tx/hash1') | ||
}) | ||
|
||
it('can get testnet url for X Chain', () => { | ||
const url = getTxURL('hash1', 'X', false) | ||
expect(url).toEqual('https://subnets-test.avax.network/x-chain/tx/hash1') | ||
}) | ||
}) |
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,25 @@ | ||
import { ChainIdType } from '@/constants' | ||
|
||
const mainnetBase = 'https://subnets.avax.network/' | ||
const fujiBase = 'https://subnets-test.avax.network/' | ||
|
||
const avascanMainnet = `https://avascan.info` | ||
const avascanFuji = `https://testnet.avascan.info` | ||
/** | ||
* Get the URL for the given transaction hash on subnets.avax.network | ||
* @param txHash | ||
* @param chain | ||
* @param isMainnet | ||
*/ | ||
export function getTxURL(txHash: string, chain: ChainIdType, isMainnet: boolean) { | ||
// For C chain use avascan | ||
//TODO: Switch to glacier when ready | ||
if (chain === 'C') { | ||
const base = isMainnet ? avascanMainnet : avascanFuji | ||
return base + `/blockchain/c/tx/${txHash}` | ||
} | ||
|
||
const base = isMainnet ? mainnetBase : fujiBase | ||
const chainPath = chain.toLowerCase() + '-chain' | ||
return `${base}${chainPath}/tx/${txHash}` | ||
} |
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,22 @@ | ||
import { isTransactionP, isTransactionX, TransactionType } from '@/js/Glacier/models' | ||
import { isMainnetNetworkID } from '@/store/modules/network/isMainnetNetworkID' | ||
import { isTestnetNetworkID } from '@/store/modules/network/isTestnetNetworkID' | ||
import { getTxURL } from '@/js/Glacier/getTxURL' | ||
|
||
/** | ||
* Given a glacier transaction, returns its URL on the explorer. | ||
* @param netID The network ID transaction is made on | ||
* @param transaction Transaction data from glacier | ||
*/ | ||
export function getUrlFromTransaction(netID: number, transaction: TransactionType) { | ||
const isMainnet = isMainnetNetworkID(netID) | ||
const isFuji = isTestnetNetworkID(netID) | ||
|
||
if (!isMainnet && !isFuji) return null | ||
|
||
const isX = isTransactionX(transaction) | ||
const isP = isTransactionP(transaction) | ||
|
||
const chainId = isX ? 'X' : isP ? 'P' : 'C' | ||
return getTxURL(transaction.txHash, chainId, isMainnet) | ||
} |