Skip to content

Commit

Permalink
solana-contrib: Add support for solscan link generation for `Transact…
Browse files Browse the repository at this point in the history
…ionReceipt` (#664)

* add solscan link for explorer and rename generateSolanaExplorerLink to generateTXLink

* fix: build error with default return string

* throw an error instead of default string

* put prev explorer link method again
  • Loading branch information
h0lme3 committed Aug 13, 2022
1 parent ad0ea11 commit ab18349
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion packages/solana-contrib/src/transaction/TransactionReceipt.ts
Expand Up @@ -19,6 +19,11 @@ export type TransactionLike =
| PendingTransaction
| TransactionReceipt;

export enum ExplorerType {
SOLANA_EXPLORER = "solana-explorer",
SOLSCAN = "solscan",
}

/**
* Confirms a transaction, returning its receipt.
*
Expand Down Expand Up @@ -97,6 +102,20 @@ export class TransactionReceipt {
* @returns
*/
generateSolanaExplorerLink(cluster: Cluster = "mainnet-beta"): string {
return `https://explorer.solana.com/tx/${this.signature}?cluster=${cluster}`;
return this.generateTXLink(cluster);
}

generateTXLink(
cluster: Cluster = "mainnet-beta",
explorerType: string = ExplorerType.SOLANA_EXPLORER
): string {
switch (explorerType) {
case ExplorerType.SOLANA_EXPLORER:
return `https://explorer.solana.com/tx/${this.signature}?cluster=${cluster}`;
case ExplorerType.SOLSCAN:
return `https://solscan.io/tx/${this.signature}?cluster=${cluster}`;
default:
throw new Error(`Explorer type ${explorerType} is not supported.`);
}
}
}

0 comments on commit ab18349

Please sign in to comment.