Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
2 changes: 1 addition & 1 deletion src/account-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import prefixForNetwork from './prefix-for-network'

export = function getAccountLink(address: string, network: string): string {
const prefix = prefixForNetwork(network)
return `https://${prefix}etherscan.io/address/${address}`
return prefix !== null ? `https://${prefix}etherscan.io/address/${address}` : '';
}
2 changes: 1 addition & 1 deletion src/explorer-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import prefixForNetwork from './prefix-for-network'

export = function getExplorerLink(hash: string, network: string): string {
const prefix = prefixForNetwork(network)
return `https://${prefix}etherscan.io/tx/${hash}`
return prefix !== null ? `https://${prefix}etherscan.io/tx/${hash}`: '';
}
4 changes: 2 additions & 2 deletions src/prefix-for-network.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export = function getPrefixForNetwork(network: string): string {
export = function getPrefixForNetwork(network: string): string | null {
const net = parseInt(network)
let prefix;

Expand All @@ -19,7 +19,7 @@ export = function getPrefixForNetwork(network: string): string {
prefix = 'kovan.'
break
default:
prefix = ''
prefix = null
}
return prefix
}
7 changes: 4 additions & 3 deletions src/token-tracker-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export = function getTokenTrackerLink(
holderAddress?: string,
): string {
const prefix = prefixForNetwork(network)
return `https://${prefix}etherscan.io/token/${tokenAddress}${
holderAddress ? `?a=${ holderAddress }` : ''
}`
return prefix !== null ?
`https://${prefix}etherscan.io/token/${tokenAddress}${
holderAddress ? `?a=${ holderAddress }` : '' }`
: '';
}
15 changes: 15 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ describe('account-link', function () {
const result = createAccountLink('foo', '3')
assert.strictEqual(result, 'https://ropsten.etherscan.io/address/foo', 'should handle ropsten')
})

it('should have null as a prefix', function () {
const result = createAccountLink('foo', '3234')
assert.strictEqual(result, '', 'should return an empty string')
})
})

// `https://${prefix}etherscan.io/tx/${hash}`
Expand All @@ -29,6 +34,11 @@ describe('explorer-link', function () {
const result = createExplorerLink('foo', '3')
assert.strictEqual(result, 'https://ropsten.etherscan.io/tx/foo', 'should handle ropsten')
})

it('should have null as a prefix', function () {
const result = createExplorerLink('foo', '10')
assert.strictEqual(result, '', 'should return an empty string')
})
})

/**
Expand Down Expand Up @@ -56,4 +66,9 @@ describe('token-tracker-link', function () {
const result = createTokenTrackerLink('foo', '3', '0xabc')
assert.strictEqual(result, 'https://ropsten.etherscan.io/token/foo?a=0xabc', 'should handle ropsten')
})

it('should null has a prefix', function () {
const result = createTokenTrackerLink('foo', '3654', '0xabc')
assert.strictEqual(result, '', 'should return an empty string')
})
})