Skip to content

Commit 5b971aa

Browse files
authored
Merge pull request #5004 from BitGo/WIN-3599
feat(sdk-coin-xrp): add xrpToken skeleton
2 parents d389ee5 + 441ec50 commit 5b971aa

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

modules/sdk-coin-xrp/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './txrp';
33
export * from './register';
44
export * from './lib/iface';
55
export * from './lib/utils';
6+
export * from './xrpToken';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { BitGoBase } from '@bitgo/sdk-core';
22
import { Txrp } from './txrp';
33
import { Xrp } from './xrp';
4+
import { XrpToken } from './xrpToken';
45

56
export const register = (sdk: BitGoBase): void => {
67
sdk.register('xrp', Xrp.createInstance);
78
sdk.register('txrp', Txrp.createInstance);
9+
XrpToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
10+
sdk.register(name, coinConstructor);
11+
});
812
};
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { coins, XrpTokenConfig, tokens } from '@bitgo/statics';
2+
import { Xrp } from './xrp';
3+
import { BitGoBase, CoinConstructor, NamedCoinConstructor } from '@bitgo/sdk-core';
4+
5+
export class XrpToken extends Xrp {
6+
public readonly tokenConfig: XrpTokenConfig;
7+
8+
constructor(bitgo: BitGoBase, tokenConfig: XrpTokenConfig) {
9+
const staticsCoin = tokenConfig.network === 'Mainnet' ? coins.get('xrp') : coins.get('txrp');
10+
super(bitgo, staticsCoin);
11+
this.tokenConfig = tokenConfig;
12+
}
13+
14+
static createTokenConstructor(config: XrpTokenConfig): CoinConstructor {
15+
return (bitgo: BitGoBase) => new XrpToken(bitgo, config);
16+
}
17+
18+
static createTokenConstructors(): NamedCoinConstructor[] {
19+
const tokensCtors: NamedCoinConstructor[] = [];
20+
for (const token of [...tokens.bitcoin.xrp.tokens, ...tokens.testnet.xrp.tokens]) {
21+
const tokenConstructor = XrpToken.createTokenConstructor(token);
22+
tokensCtors.push({ name: token.type, coinConstructor: tokenConstructor });
23+
}
24+
return tokensCtors;
25+
}
26+
27+
get name(): string {
28+
return this.tokenConfig.name;
29+
}
30+
31+
get coin(): string {
32+
return this.tokenConfig.coin;
33+
}
34+
35+
get network(): string {
36+
return this.tokenConfig.network;
37+
}
38+
39+
get issuerAddress(): string {
40+
return this.tokenConfig.issuerAddress;
41+
}
42+
43+
get currencyCode(): string {
44+
return this.tokenConfig.currencyCode;
45+
}
46+
47+
get domain(): string {
48+
return this.tokenConfig.domain || '';
49+
}
50+
51+
get decimalPlaces(): number {
52+
return this.tokenConfig.decimalPlaces;
53+
}
54+
55+
getChain(): string {
56+
return this.tokenConfig.type;
57+
}
58+
59+
getBaseChain(): string {
60+
return this.coin;
61+
}
62+
63+
getFullName(): string {
64+
return 'Xrp Token';
65+
}
66+
67+
getBaseFactor(): number {
68+
return Math.pow(10, this.tokenConfig.decimalPlaces);
69+
}
70+
}

modules/statics/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ export {
1919
HederaToken,
2020
TronErc20Coin,
2121
SuiCoin,
22+
XrpCoin,
2223
} from './account';
2324
export { CoinMap } from './map';

0 commit comments

Comments
 (0)