Skip to content

Commit

Permalink
Feature: Added support for rootstock protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
adil651 committed Apr 28, 2023
1 parent 458b443 commit d97119b
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 8 deletions.
36 changes: 36 additions & 0 deletions src/app/models/ActionGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand Down Expand Up @@ -251,6 +254,39 @@ export class ActionGroup {
return [addTokenButtonAction]
}

private getRskActions(): Action<any, any>[] {
const addTokenButtonAction: ButtonAction<void, void> = new ButtonAction(
{ name: 'account-transaction-list.add-tokens_label', icon: 'add-outline', identifier: 'add-tokens' },
() => {
const prepareAddTokenActionContext: SimpleAction<AddTokenActionContext> = new SimpleAction(() => {
return new Promise<AddTokenActionContext>(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<void, AddTokenActionContext> = new LinkedAction(prepareAddTokenActionContext, AddTokenAction)
addTokenAction.onComplete = async (): Promise<void> => {
addTokenAction.getLinkedAction().context.location.navigateRoot('')
}

return addTokenAction
}
)

return [addTokenButtonAction]
}

private getPolkadotActions(): Action<any, any>[] {
const delegateButtonAction = this.createDelegateButtonAction()

Expand Down
5 changes: 5 additions & 0 deletions src/app/pages/exchange/exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ProtocolSymbols,
SubProtocolSymbols
} from '@airgap/coinlib-core'
import { RskProtocol } from '@airgap/rsk'
import { NetworkType } from '@airgap/coinlib-core/utils/ProtocolNetwork'
import { EthereumProtocol } from '@airgap/ethereum'
import { Component, NgZone, OnDestroy, OnInit } from '@angular/core'
Expand Down Expand Up @@ -361,6 +362,10 @@ export class ExchangePage implements OnInit, OnDestroy {
feeCurrentMarketPrice = await this.priceService
.getCurrentMarketPrice(new TezosProtocol(), '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()
}
Expand Down
13 changes: 11 additions & 2 deletions src/app/pages/health-check/health-check.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ interface CheckItem {
check: () => Promise<boolean>
}

// 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',
Expand All @@ -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),
Expand All @@ -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()
})
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/pages/transaction-prepare/transaction-prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AirGapMarketWallet, AirGapNFTWallet, MainProtocolSymbols, SubProtocolSy
import { FeeDefaults } from '@airgap/coinlib-core/protocols/ICoinProtocol'
import { NetworkType } from '@airgap/coinlib-core/utils/ProtocolNetwork'
import { EthereumProtocol } from '@airgap/ethereum'
import { RskProtocol } from '@airgap/rsk'
import { IACMessageType } from '@airgap/serializer'
import { SubstrateProtocol } from '@airgap/substrate'
import { TezosProtocol } from '@airgap/tezos'
Expand Down Expand Up @@ -401,6 +402,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
}
Expand Down
5 changes: 3 additions & 2 deletions src/app/pages/walletconnect/walletconnect.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ export class WalletconnectPage implements OnInit {
public async ngOnInit(): Promise<void> {
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: AirGapMarketWallet) =>
(wallet.protocol.identifier === MainProtocolSymbols.ETH || wallet.protocol.identifier === MainProtocolSymbols.RBTC) &&
wallet.status === AirGapWalletStatus.ACTIVE
)
if (this.selectableWallets.length > 0) {
this.selectedWallet = this.selectableWallets[0]
Expand Down
2 changes: 1 addition & 1 deletion src/app/services/coinlib/coinlib.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface ApiHealth {
isHealthy: boolean
errorDescription?: string
}
blockExplorer?: {
explorer?: {
isHealthy: boolean
errorDescription?: string
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/services/guard/protocol.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Expand Down
2 changes: 1 addition & 1 deletion src/app/services/iac/iac.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class IACService extends BaseIACService {
signature: messageSignResponse.signature,
signingType: SigningType.RAW
}
if (protocol === MainProtocolSymbols.XTZ) {
if (protocol === MainProtocolSymbols.XTZ || protocol === MainProtocolSymbols.RBTC) {
await this.beaconService.respond(response, cachedRequest[0])
} else if (protocol === MainProtocolSymbols.ETH) {
await this.walletConnectService.approveRequest(response.id, response.signature)
Expand Down
2 changes: 2 additions & 0 deletions src/app/services/operations/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
SubProtocolSymbols
} from '@airgap/coinlib-core'
import { CosmosTransaction } from '@airgap/cosmos'
import { RawRskTransaction } from '@airgap/rsk'
import { RawEthereumTransaction } from '@airgap/ethereum'
import { IACMessageDefinitionObjectV3, IACMessageType } from '@airgap/serializer'
import { RawSubstrateTransaction } from '@airgap/substrate'
Expand Down Expand Up @@ -43,6 +44,7 @@ import { ErrorCategory, handleErrorSentry } from '../sentry-error-handler/sentry
export type SerializableTx =
| RawTezosTransaction
| RawEthereumTransaction
| RawRskTransaction
| RawBitcoinTransaction
| RawAeternityTransaction
| CosmosTransaction
Expand Down
5 changes: 4 additions & 1 deletion src/app/services/price/price.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down
1 change: 1 addition & 0 deletions src/assets/workers/airgap-coin-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const protocols = [
new airgapCoinLibBitcoin.BitcoinProtocol(),
new airgapCoinLibBitcoin.BitcoinSegwitProtocol(),
new airgapCoinLibEthereum.EthereumProtocol(),
new airgapCoinLib.addSupportedProtocol(new airgapCoinLib.RskProtocol()),
new airgapCoinLibGroestlcoin.GroestlcoinProtocol(),
new airgapCoinLibTezos.TezosProtocol(),
new airgapCoinLibCosmos.CosmosProtocol(),
Expand Down

0 comments on commit d97119b

Please sign in to comment.