Skip to content

Commit

Permalink
feat(rsk): add rsk protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
7alip committed Nov 19, 2021
1 parent b067d77 commit f9d7e1e
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 10 deletions.
36 changes: 36 additions & 0 deletions src/app/models/ActionGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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 @@ -202,6 +205,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>(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<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 @@ -3,6 +3,7 @@ import {
AirGapMarketWallet,
AirGapWalletStatus,
EthereumProtocol,
RskProtocol,
FeeDefaults,
ICoinProtocol,
MainProtocolSymbols,
Expand Down Expand Up @@ -307,6 +308,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()
}
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
5 changes: 4 additions & 1 deletion src/app/pages/transaction-prepare/transaction-prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { AddressService, AmountConverterPipe, ClipboardService } from '@airgap/a
import {
AirGapMarketWallet,
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'
Expand Down Expand Up @@ -375,6 +376,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.currentMarketPrice.toNumber()
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/pages/walletconnect/walletconnect.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
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 @@ -149,7 +149,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
Expand Down
6 changes: 4 additions & 2 deletions src/app/services/operations/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -47,6 +48,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 @@ -219,7 +219,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 @@ -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())
Expand Down

0 comments on commit f9d7e1e

Please sign in to comment.