|
| 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 | +} |
0 commit comments