From 0dd2f38bb30e7e4c2b729b82e989233387e69cd5 Mon Sep 17 00:00:00 2001 From: 7alip Date: Mon, 16 Aug 2021 16:00:58 +0200 Subject: [PATCH] feat(rsk): add rsk protocol --- src/app/models/ActionGroup.ts | 36 +++++++++++++++++++ src/app/pages/exchange/exchange.ts | 5 +++ .../pages/health-check/health-check.page.ts | 13 +++++-- .../transaction-prepare.ts | 5 ++- .../pages/walletconnect/walletconnect.page.ts | 3 +- src/app/services/coinlib/coinlib.service.ts | 2 +- src/app/services/guard/protocol.guard.ts | 2 +- src/app/services/iac/iac.service.ts | 2 +- src/app/services/operations/operations.ts | 6 ++-- src/app/services/price/price.service.ts | 5 ++- src/assets/workers/airgap-coin-lib.js | 1 + 11 files changed, 70 insertions(+), 10 deletions(-) diff --git a/src/app/models/ActionGroup.ts b/src/app/models/ActionGroup.ts index 6a45ddb12..8677920a6 100644 --- a/src/app/models/ActionGroup.ts +++ b/src/app/models/ActionGroup.ts @@ -45,6 +45,9 @@ export class ActionGroup { actionMap.set(MainProtocolSymbols.ETH, async () => { return this.getEthereumActions() }) + actionMap.set(MainProtocolSymbols.RBTC, async () => { + return this.getRskActions() + }) actionMap.set(MainProtocolSymbols.COSMOS, async () => { return this.getCosmosActions() }) @@ -210,6 +213,39 @@ export class ActionGroup { return [addTokenButtonAction] } + private getRskActions(): Action[] { + const addTokenButtonAction: ButtonAction = new ButtonAction( + { name: 'account-transaction-list.add-tokens_label', icon: 'add-outline', identifier: 'add-tokens' }, + () => { + const prepareAddTokenActionContext: SimpleAction = new SimpleAction(() => { + return new Promise(async resolve => { + const info = { + subProtocolType: SubProtocolType.TOKEN, + wallet: this.callerContext.wallet, + actionCallback: resolve + } + this.callerContext.dataService.setData(DataServiceKey.DETAIL, info) + this.callerContext.router + .navigateByUrl( + `/sub-account-add/${DataServiceKey.DETAIL}/${info.wallet.publicKey}/${info.wallet.protocol.identifier}/${ + info.wallet.addressIndex + }/${info.subProtocolType}` + ) + .catch(handleErrorSentry(ErrorCategory.NAVIGATION)) + }) + }) + const addTokenAction: LinkedAction = new LinkedAction(prepareAddTokenActionContext, AddTokenAction) + addTokenAction.onComplete = async (): Promise => { + addTokenAction.getLinkedAction().context.location.navigateRoot('') + } + + return addTokenAction + } + ) + + return [addTokenButtonAction] + } + private getPolkadotActions(): Action[] { const delegateButtonAction = this.createDelegateButtonAction() diff --git a/src/app/pages/exchange/exchange.ts b/src/app/pages/exchange/exchange.ts index a1f44189c..b864d68f4 100644 --- a/src/app/pages/exchange/exchange.ts +++ b/src/app/pages/exchange/exchange.ts @@ -3,6 +3,7 @@ import { AirGapMarketWallet, AirGapWalletStatus, EthereumProtocol, + RskProtocol, FeeDefaults, ICoinProtocol, MainProtocolSymbols, @@ -309,6 +310,10 @@ export class ExchangePage { feeCurrentMarketPrice = this.priceService .getCurrentMarketPrice(new EthereumProtocol(), 'USD') .then((price: BigNumber) => price.toNumber()) + } else if (this.selectedFromProtocol.identifier.startsWith(SubProtocolSymbols.RBTC_ERC20)) { + feeCurrentMarketPrice = this.priceService + .getCurrentMarketPrice(new RskProtocol(), 'USD') + .then((price: BigNumber) => price.toNumber()) } else { feeCurrentMarketPrice = (await this.priceService.getCurrentMarketPrice(this.selectedFromProtocol, 'USD')).toNumber() } diff --git a/src/app/pages/health-check/health-check.page.ts b/src/app/pages/health-check/health-check.page.ts index 2439ef04b..c3888c0f6 100644 --- a/src/app/pages/health-check/health-check.page.ts +++ b/src/app/pages/health-check/health-check.page.ts @@ -23,6 +23,13 @@ interface CheckItem { check: () => Promise } +// TODO: Should be provided by the API +const rskHealthMock = { + identifier: MainProtocolSymbols.RBTC, + node: { isHealthy: true }, + explorer: { isHealthy: true } +} + @Component({ selector: 'app-health-check', templateUrl: './health-check.page.html', @@ -45,6 +52,8 @@ export class HealthCheckPage { this.generateCheckItem('Bitcoin', MainProtocolSymbols.BTC, ApiType.NODE), this.generateCheckItem('Ethereum', MainProtocolSymbols.ETH, ApiType.NODE), this.generateCheckItem('Ethereum', MainProtocolSymbols.ETH, ApiType.Explorer), + this.generateCheckItem('RSK', MainProtocolSymbols.RBTC, ApiType.NODE), + this.generateCheckItem('RSK', MainProtocolSymbols.RBTC, ApiType.Explorer), this.generateCheckItem('Polkadot', MainProtocolSymbols.POLKADOT, ApiType.NODE), this.generateCheckItem('Polkadot', MainProtocolSymbols.POLKADOT, ApiType.Explorer), this.generateCheckItem('Kusama', MainProtocolSymbols.KUSAMA, ApiType.NODE), @@ -58,8 +67,8 @@ export class HealthCheckPage { public async ionViewWillEnter() { this.displayLoading() this.coinlibService.checkApiHealth().then((apiHealth) => { - this.apiHealth = apiHealth - this.loadingElement.dismiss() + this.apiHealth = apiHealth.concat(rskHealthMock) // TODO: Api result instead of mock + this.loadingElement?.dismiss() this.runChecks() }) } diff --git a/src/app/pages/transaction-prepare/transaction-prepare.ts b/src/app/pages/transaction-prepare/transaction-prepare.ts index 5493bb208..3f057a1c5 100644 --- a/src/app/pages/transaction-prepare/transaction-prepare.ts +++ b/src/app/pages/transaction-prepare/transaction-prepare.ts @@ -3,10 +3,11 @@ import { AirGapMarketWallet, AirGapNFTWallet, EthereumProtocol, + RskProtocol, IACMessageType, MainProtocolSymbols, SubProtocolSymbols, - TezosProtocol + TezosProtocol, } from '@airgap/coinlib-core' import { FeeDefaults } from '@airgap/coinlib-core/protocols/ICoinProtocol' import { NetworkType } from '@airgap/coinlib-core/utils/ProtocolNetwork' @@ -403,6 +404,8 @@ export class TransactionPreparePage { return this.priceService.getCurrentMarketPrice(new TezosProtocol(), 'USD').then((price: BigNumber) => price.toNumber()) } else if (wallet.protocol.identifier.startsWith(SubProtocolSymbols.ETH_ERC20)) { return this.priceService.getCurrentMarketPrice(new EthereumProtocol(), 'USD').then((price: BigNumber) => price.toNumber()) + } else if (wallet.protocol.identifier.startsWith(SubProtocolSymbols.RBTC_ERC20)) { + return this.priceService.getCurrentMarketPrice(new RskProtocol(), 'USD').then((price: BigNumber) => price.toNumber()) } else { return wallet.getCurrentMarketPrice(this.collectibleID)?.toNumber() ?? 0 } diff --git a/src/app/pages/walletconnect/walletconnect.page.ts b/src/app/pages/walletconnect/walletconnect.page.ts index c23784355..81cae9340 100644 --- a/src/app/pages/walletconnect/walletconnect.page.ts +++ b/src/app/pages/walletconnect/walletconnect.page.ts @@ -98,7 +98,8 @@ export class WalletconnectPage implements OnInit { this.subscription = this.accountService.allWallets$.asObservable().subscribe((wallets: AirGapMarketWallet[]) => { this.selectableWallets = wallets.filter( (wallet: AirGapMarketWallet) => - wallet.protocol.identifier === MainProtocolSymbols.ETH && wallet.status === AirGapWalletStatus.ACTIVE + (wallet.protocol.identifier === MainProtocolSymbols.ETH || wallet.protocol.identifier === MainProtocolSymbols.RBTC) && + wallet.status === AirGapWalletStatus.ACTIVE ) if (this.selectableWallets.length > 0) { this.selectedWallet = this.selectableWallets[0] diff --git a/src/app/services/coinlib/coinlib.service.ts b/src/app/services/coinlib/coinlib.service.ts index 50dfac7f2..56a6120fd 100644 --- a/src/app/services/coinlib/coinlib.service.ts +++ b/src/app/services/coinlib/coinlib.service.ts @@ -24,7 +24,7 @@ export interface ApiHealth { isHealthy: boolean errorDescription?: string } - blockExplorer?: { + explorer?: { isHealthy: boolean errorDescription?: string } diff --git a/src/app/services/guard/protocol.guard.ts b/src/app/services/guard/protocol.guard.ts index 1ea3d8a02..610ae296b 100644 --- a/src/app/services/guard/protocol.guard.ts +++ b/src/app/services/guard/protocol.guard.ts @@ -20,7 +20,7 @@ export class ProtocolGuard implements CanActivate { let subSymbols: string[] = Object.values(SubProtocolSymbols).map((p: SubProtocolSymbols) => p.toString()) if (mainProtocolID !== undefined) { - if (mainProtocolID === MainProtocolSymbols.ETH || mainProtocolID === MainProtocolSymbols.XTZ) { + if (mainProtocolID === MainProtocolSymbols.ETH || mainProtocolID === MainProtocolSymbols.RBTC || mainProtocolID === MainProtocolSymbols.XTZ) { subSymbols = (await this.protocolService.getAllSubProtocols(mainProtocolID)).map((protocol: ICoinProtocol) => protocol.identifier.toString() ) diff --git a/src/app/services/iac/iac.service.ts b/src/app/services/iac/iac.service.ts index e4e80bb57..afea44ca7 100644 --- a/src/app/services/iac/iac.service.ts +++ b/src/app/services/iac/iac.service.ts @@ -150,7 +150,7 @@ export class IACService extends BaseIACService { } if (protocol === MainProtocolSymbols.XTZ) { await this.beaconService.respond(response, cachedRequest[0]) - } else if (protocol === MainProtocolSymbols.ETH) { + } else if (protocol === MainProtocolSymbols.ETH || protocol === MainProtocolSymbols.RBTC) { await this.walletConnectService.approveRequest(response.id, response.signature) } return false diff --git a/src/app/services/operations/operations.ts b/src/app/services/operations/operations.ts index b8d05122e..bff7f1700 100644 --- a/src/app/services/operations/operations.ts +++ b/src/app/services/operations/operations.ts @@ -21,8 +21,9 @@ import { RawAeternityTransaction, RawBitcoinTransaction, RawEthereumTransaction, - RawSubstrateTransaction, - RawTezosTransaction + RawRskTransaction, + RawTezosTransaction, + RawSubstrateTransaction } from '@airgap/coinlib-core/serializer/types' import { Injectable } from '@angular/core' import { FormBuilder } from '@angular/forms' @@ -47,6 +48,7 @@ import { ErrorCategory, handleErrorSentry } from '../sentry-error-handler/sentry export type SerializableTx = | RawTezosTransaction | RawEthereumTransaction + | RawRskTransaction | RawBitcoinTransaction | RawAeternityTransaction | CosmosTransaction diff --git a/src/app/services/price/price.service.ts b/src/app/services/price/price.service.ts index d9da90705..eb0ad5e8d 100644 --- a/src/app/services/price/price.service.ts +++ b/src/app/services/price/price.service.ts @@ -218,7 +218,10 @@ export class PriceService implements AirGapWalletPriceService { yfi: 'yearn-finance', zb: 'zb-token', zil: 'zilliqa', - xchf: 'cryptofranc' + xchf: 'cryptofranc', + rbtc: 'rootstock', + rif: 'rif-token', + sov: 'sovryn' } const id = symbolMapping[protocol.marketSymbol.toLowerCase()] diff --git a/src/assets/workers/airgap-coin-lib.js b/src/assets/workers/airgap-coin-lib.js index aab4864c8..38e14b9ab 100644 --- a/src/assets/workers/airgap-coin-lib.js +++ b/src/assets/workers/airgap-coin-lib.js @@ -7,6 +7,7 @@ airgapCoinLib.addSupportedProtocol(new airgapCoinLib.AeternityProtocol()) airgapCoinLib.addSupportedProtocol(new airgapCoinLib.BitcoinProtocol()) airgapCoinLib.addSupportedProtocol(new airgapCoinLib.BitcoinSegwitProtocol()) airgapCoinLib.addSupportedProtocol(new airgapCoinLib.EthereumProtocol()) +airgapCoinLib.addSupportedProtocol(new airgapCoinLib.RskProtocol()) airgapCoinLib.addSupportedProtocol(new airgapCoinLib.GroestlcoinProtocol()) airgapCoinLib.addSupportedProtocol(new airgapCoinLib.TezosProtocol()) airgapCoinLib.addSupportedProtocol(new airgapCoinLib.CosmosProtocol())