Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rsk): RSK Protocol & ERC20 #99

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -210,6 +213,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 @@ -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()
}
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 @@ -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'
Expand Down Expand Up @@ -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
}
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 @@ -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
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 @@ -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 @@ -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