-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: go to dashboard on account address click
- Loading branch information
1 parent
b302d41
commit 0cad93d
Showing
4 changed files
with
116 additions
and
3 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,53 @@ | ||
import { parseAddress } from './parse-address' | ||
|
||
describe('parse address', () => { | ||
const tests: [string, { networkId: number; type: string }][] = [ | ||
[ | ||
'account_tdx_2_129449mktvws4ww6wyww0dt85fn7md383cdq58307ayfz7g0n9vznfa', | ||
{ networkId: 2, type: 'account' }, | ||
], | ||
[ | ||
'account_tdx_2_128ex28rgvj4nqsqs7vtha0upknrpspzanfr95t6j6nss225dc47nu4', | ||
{ networkId: 2, type: 'account' }, | ||
], | ||
[ | ||
'resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd', | ||
{ | ||
networkId: 1, | ||
type: 'resource', | ||
}, | ||
], | ||
[ | ||
'account_rdx12xezaw0gn9yhld6kplkk3ah7h6y48qgrmjr5e76krxq9hgws4junpr', | ||
{ | ||
networkId: 1, | ||
type: 'account', | ||
}, | ||
], | ||
[ | ||
'account_tdx_21_128wkep7c2mtdv5d0vvj23kp0rreud09384gru64w992pkmqga0nr87', | ||
{ | ||
type: 'account', | ||
networkId: 21, | ||
}, | ||
], | ||
[ | ||
'account_sim1cyyavav59dl55jur4eyxqz9wqyjycp2aua9dzduflfeefrfl623wgc', | ||
{ | ||
networkId: 242, | ||
type: 'account', | ||
}, | ||
], | ||
] | ||
it('should parse address', () => { | ||
tests.forEach(([address, expected]) => { | ||
expect(parseAddress(address)).toEqual(expected) | ||
}) | ||
}) | ||
|
||
it('should throw error on invalid address', () => { | ||
expect(() => parseAddress('invalid')).toThrowError( | ||
'Invalid address invalid', | ||
) | ||
}) | ||
}) |
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,19 @@ | ||
export const parseAddress = ( | ||
address: string, | ||
): { networkId: number; type: string } => { | ||
const match = address.match(/^([a-z]+)_(rdx|sim|tdx_[\d]+_)1(?:[a-z0-9]+)$/) | ||
|
||
if (!match) { | ||
throw new Error(`Invalid address ${address}`) | ||
} | ||
|
||
const [, type, network] = match | ||
|
||
const networkId = | ||
network === 'rdx' ? 1 : network === 'sim' ? 242 : network.split('_')[1] | ||
|
||
return { | ||
networkId: Number(networkId), | ||
type, | ||
} | ||
} |