Skip to content

Commit

Permalink
Prefix bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
0xp3gasus committed Feb 6, 2024
1 parent 9f405b3 commit bde40eb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
8 changes: 4 additions & 4 deletions packages/xchain-mayachain/__tests__/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ describe('Mayachain client', () => {
expect(client.getExplorerUrl()).toBe('https://stagenet.mayascan.org')
})
it('Should get address url', () => {
expect(client.getExplorerAddressUrl('maya1x4827nqnrwk96jfpxalfkwvhtdaq8uyudl5m53')).toBe(
'https://stagenet.mayascan.org/address/maya1x4827nqnrwk96jfpxalfkwvhtdaq8uyudl5m53',
expect(client.getExplorerAddressUrl('smaya18z343fsdlav47chtkyp0aawqt6sgxsh3ctcu6u')).toBe(
'https://stagenet.mayascan.org/address/smaya18z343fsdlav47chtkyp0aawqt6sgxsh3ctcu6u',
)
})
it('Should get transaction url', () => {
Expand Down Expand Up @@ -127,13 +127,13 @@ describe('Mayachain client', () => {
describe('Stagenet', () => {
it('Should validate address', () => {
const client = new Client({ network: Network.Stagenet })
expect(client.validateAddress('maya1fmecyfrrwsm98m59nv9y88urgur8p32g27kha6')).toBeTruthy()
expect(client.validateAddress('smaya18z343fsdlav47chtkyp0aawqt6sgxsh3ctcu6u')).toBeTruthy()
expect(client.validateAddress('0x42D5B09a92A31AfB875e1E40ae4b06f2A60890FC')).toBeFalsy()
})
it('Should change network and validate address', () => {
const client = new Client()
client.setNetwork(Network.Stagenet)
expect(client.validateAddress('maya1fmecyfrrwsm98m59nv9y88urgur8p32g27kha6')).toBeTruthy()
expect(client.validateAddress('smaya18z343fsdlav47chtkyp0aawqt6sgxsh3ctcu6u')).toBeTruthy()
})
})
})
Expand Down
6 changes: 3 additions & 3 deletions packages/xchain-mayachain/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
decodeTxRaw,
} from '@cosmjs/proto-signing'
import { SigningStargateClient } from '@cosmjs/stargate'
import { AssetInfo, PreparedTx, TxHash, TxParams } from '@xchainjs/xchain-client'
import { AssetInfo, Network, PreparedTx, TxHash, TxParams } from '@xchainjs/xchain-client'
import {
Client as CosmosSDKClient,
CosmosSdkClientParams,
Expand Down Expand Up @@ -71,8 +71,8 @@ export class Client extends CosmosSDKClient implements MayachainClient {
* Get address prefix by network
* @returns the address prefix
*/
protected getPrefix(): string {
return getPrefix()
protected getPrefix(network: Network): string {
return getPrefix(network)
}

/**
Expand Down
11 changes: 10 additions & 1 deletion packages/xchain-mayachain/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,13 @@ export const getChainId = async (nodeUrl: string): Promise<string> => {
* Get address prefix by network
* @returns the address prefix
*/
export const getPrefix = () => 'maya'
export const getPrefix = (network: Network) => {
switch (network) {
case Network.Mainnet:
return 'maya'
case Network.Stagenet:
return 'smaya'
case Network.Testnet:
return 'tmaya'
}
}

0 comments on commit bde40eb

Please sign in to comment.