Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Develop

See merge request papers/airgap/airgap-wallet!696
  • Loading branch information
godenzim committed Jul 5, 2023
2 parents e6e95b9 + daecf62 commit 0018717
Show file tree
Hide file tree
Showing 17 changed files with 534 additions and 379 deletions.
39 changes: 39 additions & 0 deletions .gitlab/issue_templates/user_issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# User reported issue

**Where the issue was reported** (link to post if available):

****OS used** (Android/iOS):

**Device used** (Model):

**Version** (Wallet and/or Vault, eg 3.28.0):

**Blockchain involved**:

## What the user did:
<!---What the user said he/she wanted to do --->

## What issue the user was confrontend with:
<!---What the user said didn't work as expected --->

## Steps to reproduce:
<!--- How can a developer reproduce this issue --->

## What is the expected _correct_ behavior?
<!--- What you should see instead --->

## Relevant logs, screenshots and/or links
<!--- Paste any relevant logs - please use code blocks (```) to format console output,
logs, and code as it's tough to read otherwise. --->

## Possible fixes / approach
<!--- If you can, link to the line of code that might be responsible for the problem or describe how to solve it --->

## Additional information
<!--- anything that might be important for whoever works with this issue --->

<!--- if you know already how long it takes, add an estimate eg. 2h or 1d --->
/estimate

<!--- these standard labels will be added to this issue>--->
/label ~"type::bug" ~"proj::airgap" ~"community"
524 changes: 262 additions & 262 deletions package-lock.json

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,28 @@
}
},
"dependencies": {
"@airgap/aeternity": "0.13.17",
"@airgap/aeternity": "0.13.18",
"@airgap/angular-core": "0.0.39",
"@airgap/angular-ngrx": "0.0.39",
"@airgap/astar": "0.13.17",
"@airgap/astar": "0.13.18",
"@airgap/beacon-sdk": "3.1.5-beta.0",
"@airgap/bitcoin": "0.13.17",
"@airgap/coinlib-core": "0.13.17",
"@airgap/coreum": "0.13.17",
"@airgap/cosmos": "0.13.17",
"@airgap/cosmos-core": "0.13.17",
"@airgap/crypto": "0.13.17",
"@airgap/ethereum": "0.13.17",
"@airgap/groestlcoin": "0.13.17",
"@airgap/icp": "0.13.17",
"@airgap/module-kit": "0.13.17",
"@airgap/moonbeam": "0.13.17",
"@airgap/optimism": "0.13.17",
"@airgap/polkadot": "0.13.17",
"@airgap/bitcoin": "0.13.18",
"@airgap/coinlib-core": "0.13.18",
"@airgap/coreum": "0.13.18",
"@airgap/cosmos": "0.13.18",
"@airgap/cosmos-core": "0.13.18",
"@airgap/crypto": "0.13.18",
"@airgap/ethereum": "0.13.18",
"@airgap/groestlcoin": "0.13.18",
"@airgap/icp": "0.13.18",
"@airgap/module-kit": "0.13.18",
"@airgap/moonbeam": "0.13.18",
"@airgap/optimism": "0.13.18",
"@airgap/polkadot": "0.13.18",
"@airgap/sapling-wasm": "0.0.7",
"@airgap/serializer": "0.13.17",
"@airgap/substrate": "0.13.17",
"@airgap/tezos": "0.13.17",
"@airgap/serializer": "0.13.18",
"@airgap/substrate": "0.13.18",
"@airgap/tezos": "0.13.18",
"@angular/animations": "^16.1.1",
"@angular/common": "^16.1.1",
"@angular/core": "^16.1.1",
Expand Down
1 change: 1 addition & 0 deletions src/app/components/mt-pelerin/mt-pelerin.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class MtPelerinComponent {
public openMtPelerinLink() {
if (this.url) {
window.open(this.url, '_blank')
this.dismiss()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export interface CheckboxInput {
styleUrls: ['./permission-request.component.scss']
})
export class PermissionRequestComponent implements OnChanges {
public modalRef: HTMLIonModalElement | undefined
public readonly networkType: typeof NetworkType = NetworkType

public wallets: Partial<Record<ProtocolSymbols, AirGapMarketWallet[]>> = {}
Expand Down Expand Up @@ -85,8 +84,6 @@ export class PermissionRequestComponent implements OnChanges {
}

public async changeAccount(): Promise<void> {
this.modalRef = await this.modalController.getTop()

return new Promise(async () => {
if (Object.entries(this.wallets).length === 1 && Object.entries(this.wallets)[0][1].length === 1) {
return
Expand Down Expand Up @@ -129,6 +126,6 @@ export class PermissionRequestComponent implements OnChanges {
}

public async dismiss(): Promise<boolean | void> {
return this.modalRef.dismiss().catch(handleErrorSentry(ErrorCategory.NAVIGATION))
return this.modalController.dismiss().catch(handleErrorSentry(ErrorCategory.NAVIGATION))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,9 @@ export class AccountTransactionListPage {

public async buyMtPerelin() {
this.wallet.protocol.getSymbol().then(async (symbol) => {
const url = `https://buy.mtpelerin.com/?type=direct-link&bdc=${symbol}&addr=${this.wallet.addresses[0]}&rfr=bcH4RmHm`
const url = `https://buy.mtpelerin.com/?type=direct-link&bdc=${symbol}&rfr=bcH4RmHm`
await this.openModal(url)
// window.open(`https://buy.mtpelerin.com/?type=direct-link&bdc=${symbol}&addr=${this.wallet.addresses[0]}&rfr=bcH4RmHm`, '_blank')
// window.open(`https://buy.mtpelerin.com/?type=direct-link&bdc=${symbol}&rfr=bcH4RmHm`, '_blank')
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/beacon-request/beacon-request.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<ion-content class="ion-padding-horizontal ion-padding-bottom">
<ion-grid fixed="true" class="ion-no-padding">
<ng-container *ngIf="request">
<ng-container *ngIf="request.type != 'permission_request'">
<ng-container *ngIf="request.type !== 'permission_request'">
<ion-card class="ion-margin-bottom">
<ion-item lines="none">
<ion-avatar slot="start">
Expand Down
6 changes: 2 additions & 4 deletions src/app/pages/beacon-request/beacon-request.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class BeaconRequestPage implements OnInit {
public selectableWallets: AirGapMarketWallet[] = []
private selectedWallet: AirGapMarketWallet | undefined

public modalRef: HTMLIonModalElement | undefined
public modal: HTMLIonModalElement | undefined

public blake2bHash: string | undefined
private readonly subscription: Subscription
Expand Down Expand Up @@ -84,8 +84,6 @@ export class BeaconRequestPage implements OnInit {
}

public async ngOnInit(): Promise<void> {
this.modalRef = await this.modalController.getTop()

this.requesterName = this.request.appMetadata.name
this.network = await this.getNetworkFromRequest(this.request)
if (this.request && this.request.type === BeaconMessageType.PermissionRequest) {
Expand Down Expand Up @@ -126,7 +124,7 @@ export class BeaconRequestPage implements OnInit {
}

public async dismiss(): Promise<boolean | void> {
return this.modalRef.dismiss().catch(handleErrorSentry(ErrorCategory.NAVIGATION))
return this.modalController.dismiss().catch(handleErrorSentry(ErrorCategory.NAVIGATION))
}

public async done(): Promise<void> {
Expand Down
40 changes: 28 additions & 12 deletions src/app/pages/dapp-confirm/dapp-confirm.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export interface WalletconnectV2Context extends WalletconnectV2HandlerContext {

export type WalletconnectContext = WalletconnectV1Context | WalletconnectV2Context

interface WalletconnectHandlerRegistry {
v1: WalletconnectV1Handler
v2: WalletconnectV2Handler
}

@Component({
selector: 'app-dapp-confirm',
templateUrl: './dapp-confirm.page.html',
Expand All @@ -25,12 +30,30 @@ export class DappConfirmPage implements OnInit {
public context: WalletconnectContext
public result: string

private readonly handlers = {
v1: new WalletconnectV1Handler(),
v2: new WalletconnectV2Handler()
public constructor(private readonly modalController: ModalController) {}

public static async approveRequest(context: WalletconnectContext) {
await DappConfirmPage.getHandler(context).approveRequest(context)
}

public constructor(private readonly modalController: ModalController) {}
private static handlers: WalletconnectHandlerRegistry | undefined = undefined
private static getHandler(context: WalletconnectContext): WalletconnectHandler<any> {
if (DappConfirmPage.handlers === undefined) {
DappConfirmPage.handlers = {
v1: new WalletconnectV1Handler(),
v2: new WalletconnectV2Handler()
}
}

switch (context.version) {
case 1:
return DappConfirmPage.handlers['v1']
case 2:
return DappConfirmPage.handlers['v2']
default:
assertNever('context', context)
}
}

public async ngOnInit(): Promise<void> {
this.result = await this.getHandler().readResult(this.context)
Expand All @@ -51,13 +74,6 @@ export class DappConfirmPage implements OnInit {
}

private getHandler(): WalletconnectHandler<any> {
switch (this.context.version) {
case 1:
return this.handlers['v1']
case 2:
return this.handlers['v2']
default:
assertNever('context', this.context)
}
return DappConfirmPage.getHandler(this.context)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class WalletconnectV2Handler implements WalletconnectHandler<Walletconnec
}

public async approveRequest(context: WalletconnectV2HandlerContext): Promise<void> {
context.client.respondSessionRequest({
await context.client.respondSessionRequest({
topic: context.topic,
response: {
id: context.id,
Expand All @@ -27,7 +27,7 @@ export class WalletconnectV2Handler implements WalletconnectHandler<Walletconnec
}

public async rejectRequest(context: WalletconnectV2HandlerContext): Promise<void> {
context.client.respondSessionRequest({
await context.client.respondSessionRequest({
topic: context.topic,
response: {
id: context.id,
Expand Down
63 changes: 60 additions & 3 deletions src/app/pages/sub-account-add/sub-account-add.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { ProtocolService } from '@airgap/angular-core'
import { ICoinProtocolAdapter, ICoinSubProtocolAdapter, ProtocolService } from '@airgap/angular-core'
import { AirGapCoinWallet, AirGapMarketWallet, MainProtocolSymbols } from '@airgap/coinlib-core'
import { ICoinSubProtocol, SubProtocolType } from '@airgap/coinlib-core/protocols/ICoinSubProtocol'
import { assertNever } from '@airgap/coinlib-core/utils/assert'
import { AirGapOnlineProtocol, Amount, canGetTokenBalances, isSingleTokenSubProtocol, TokenDetails } from '@airgap/module-kit'
import { Component } from '@angular/core'
import { ActivatedRoute } from '@angular/router'
import { NavController } from '@ionic/angular'
import BigNumber from 'bignumber.js'
import { AirGapMarketWalletGroup } from 'src/app/models/AirGapMarketWalletGroup'
import { PriceService } from 'src/app/services/price/price.service'
import { stripV1Wallet } from 'src/app/utils/utils'

import { AddTokenActionContext } from '../../models/actions/AddTokenAction'
import { AccountProvider } from '../../services/account/account.provider'
Expand Down Expand Up @@ -105,9 +108,12 @@ export class SubAccountAddPage {
}

private async loadSubAccounts(subProtocols: ICoinSubProtocol[]) {
const subProtocolsWithTokenDetails: [ICoinSubProtocol, TokenDetails | undefined][] = await this.getTokenDetails(subProtocols)
const balances: Record<string, Amount> = await this.getTokenBalances(subProtocolsWithTokenDetails)

const accounts: IAccountWrapper[] = (
await Promise.all(
subProtocols.map(async (subProtocol) => {
subProtocolsWithTokenDetails.map(async ([subProtocol, tokenDetails]) => {
const walletGroup: AirGapMarketWalletGroup = this.accountProvider.findWalletGroup(this.wallet)
const wallet: AirGapMarketWallet = new AirGapCoinWallet(
subProtocol,
Expand All @@ -122,7 +128,11 @@ export class SubAccountAddPage {
return undefined
}
wallet.addresses = this.wallet.addresses
await wallet.synchronize()
if (tokenDetails && balances[tokenDetails.identifier]) {
wallet.setCurrentBalance(new BigNumber(balances[tokenDetails.identifier].value))
} else {
await wallet.synchronize()
}

return {
wallet,
Expand Down Expand Up @@ -181,4 +191,51 @@ export class SubAccountAddPage {
await this.loadDisplayedAccounts()
event.target.complete()
}

private async getTokenDetails(subProtocols: ICoinSubProtocol[]): Promise<[ICoinSubProtocol, TokenDetails | undefined][]> {
if (!(this.wallet.protocol instanceof ICoinProtocolAdapter) || !canGetTokenBalances(this.wallet.protocol.protocolV1)) {
return subProtocols.map((subProtocol: ICoinSubProtocol) => [subProtocol, undefined])
}

return Promise.all(
subProtocols.map(async (subProtocol: ICoinSubProtocol) => {
if (!(subProtocol instanceof ICoinSubProtocolAdapter)) {
return [subProtocol, undefined]
}

const subProtocolV1: AirGapOnlineProtocol = subProtocol.protocolV1
let tokenDetails: TokenDetails | undefined
if (isSingleTokenSubProtocol(subProtocolV1)) {
const contractAddress: string = await subProtocolV1.getContractAddress()
tokenDetails = {
type: 'single',
identifier: contractAddress,
contractAddress
}
} /* else if (isMultiTokenSubProtocol(subProtocolV1)) { ... } - not supported */

return [subProtocol, tokenDetails]
})
)
}

private async getTokenBalances(
subProtocolsWithTokenDetails: [ICoinSubProtocol, TokenDetails | undefined][]
): Promise<Record<string, Amount>> {
const { adapter, publicKey } = stripV1Wallet(this.wallet)

if (!canGetTokenBalances(adapter.protocolV1)) {
return {}
}

const tokenDetails: TokenDetails[] = subProtocolsWithTokenDetails
.map(([_, tokenDetails]) => tokenDetails)
.filter((tokenDetails) => tokenDetails !== undefined)

if (tokenDetails.length === 0) {
return {}
}

return adapter.protocolV1.getTokenBalancesOfPublicKey(publicKey, tokenDetails)
}
}
3 changes: 2 additions & 1 deletion src/app/pages/transaction-confirm/transaction-confirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ export class TransactionConfirmPage {
if (request) {
// TODO: Type
if (request['transaction']) {
this.walletConnectService.approveRequest(request.id, txId)
await this.walletConnectService.approveRequest(request.id, txId, false)
this.beaconService.clearVaultRequest()
} else {
const response = {
id: request.id,
Expand Down
Loading

0 comments on commit 0018717

Please sign in to comment.