1
- import { ClipboardService , DeeplinkService , UiEventService } from '@airgap/angular-core'
2
- import { AirGapWallet , IACMessageDefinitionObjectV3 } from '@airgap/coinlib-core'
3
- import { Component } from '@angular/core'
4
- import { PopoverController } from '@ionic/angular'
1
+ import { ClipboardService , DeeplinkService , QRType , UiEventService } from '@airgap/angular-core'
2
+ import { AirGapWallet , IACMessageDefinitionObjectV3 , MainProtocolSymbols } from '@airgap/coinlib-core'
3
+ import { Component , ViewChild } from '@angular/core'
4
+ import { Router } from '@angular/router'
5
+ import { IonModal , PopoverController } from '@ionic/angular'
5
6
6
7
import { ErrorCategory , handleErrorLocal } from '../../services/error-handler/error-handler.service'
7
8
import { InteractionOperationType , InteractionService } from '../../services/interaction/interaction.service'
@@ -12,18 +13,55 @@ import { isWalletMigrated } from '../../utils/migration'
12
13
13
14
import { AccountEditPopoverComponent } from './account-edit-popover/account-edit-popover.component'
14
15
16
+ // TODO: add wallet definition into a service
17
+ export const airgapwallet = {
18
+ icon : 'airgap-wallet-app-logo.png' ,
19
+ name : 'AirGap Wallet' ,
20
+ qrType : QRType . V3
21
+ }
22
+
23
+ const bluewallet = {
24
+ icon : 'bluewallet.png' ,
25
+ name : 'BlueWallet' ,
26
+ qrType : QRType . BC_UR
27
+ }
28
+
29
+ const sparrowwallet = {
30
+ icon : 'sparrowwallet.png' ,
31
+ name : 'Sparrow Wallet' ,
32
+ qrType : QRType . BC_UR
33
+ }
34
+
35
+ const metamask = {
36
+ icon : 'metamask.webp' ,
37
+ name : 'MetaMask' ,
38
+ qrType : QRType . METAMASK
39
+ }
40
+
41
+ export interface CompanionApp {
42
+ icon : string
43
+ name : string
44
+ qrType : QRType
45
+ }
46
+
15
47
@Component ( {
16
48
selector : 'airgap-account-address' ,
17
49
templateUrl : './account-address.page.html' ,
18
50
styleUrls : [ './account-address.page.scss' ]
19
51
} )
20
52
export class AccountAddressPage {
53
+ @ViewChild ( IonModal ) modal : IonModal
54
+
21
55
public wallet : AirGapWallet
22
56
57
+ public syncOptions : CompanionApp [ ]
58
+
23
59
private shareObject ?: IACMessageDefinitionObjectV3 [ ]
24
60
private shareObjectPromise ?: Promise < void >
25
61
private walletShareUrl ?: string
26
62
63
+ presentingElement = null
64
+
27
65
constructor (
28
66
private readonly popoverCtrl : PopoverController ,
29
67
private readonly clipboardService : ClipboardService ,
@@ -32,21 +70,43 @@ export class AccountAddressPage {
32
70
private readonly navigationService : NavigationService ,
33
71
private readonly uiEventService : UiEventService ,
34
72
private readonly migrationService : MigrationService ,
35
- private readonly deepLinkService : DeeplinkService
73
+ private readonly deepLinkService : DeeplinkService ,
74
+ private readonly router : Router
36
75
) {
37
76
this . wallet = this . navigationService . getState ( ) . wallet
77
+
78
+ if ( ! this . wallet ) {
79
+ this . router . navigate ( [ '/' ] )
80
+ throw new Error ( 'No wallet found!' )
81
+ }
82
+
83
+ switch ( this . wallet ?. protocol . identifier ) {
84
+ case MainProtocolSymbols . BTC_SEGWIT :
85
+ this . syncOptions = [ airgapwallet , bluewallet , sparrowwallet ]
86
+ break
87
+ case MainProtocolSymbols . ETH :
88
+ this . syncOptions = [ airgapwallet , metamask ]
89
+ break
90
+ default :
91
+ this . syncOptions = [ airgapwallet ]
92
+ }
93
+ }
94
+
95
+ ngOnInit ( ) {
96
+ this . presentingElement = document . querySelector ( '.ion-page' )
38
97
}
39
98
40
99
public done ( ) : void {
41
100
this . navigationService . routeToAccountsTab ( ) . catch ( handleErrorLocal ( ErrorCategory . IONIC_NAVIGATION ) )
42
101
}
43
102
44
- public async share ( ) : Promise < void > {
103
+ public async share ( companionApp : CompanionApp = airgapwallet ) : Promise < void > {
45
104
await this . waitWalletShareUrl ( )
46
105
47
106
this . interactionService . startInteraction ( {
48
107
operationType : InteractionOperationType . WALLET_SYNC ,
49
- iacMessage : this . shareObject
108
+ iacMessage : this . shareObject ,
109
+ companionApp : companionApp
50
110
} )
51
111
}
52
112
@@ -55,6 +115,9 @@ export class AccountAddressPage {
55
115
component : AccountEditPopoverComponent ,
56
116
componentProps : {
57
117
wallet : this . wallet ,
118
+ openAddressQR : ( ) => {
119
+ this . modal . present ( ) . catch ( handleErrorLocal ( ErrorCategory . IONIC_MODAL ) )
120
+ } ,
58
121
getWalletShareUrl : async ( ) => {
59
122
await this . waitWalletShareUrl ( )
60
123
return this . walletShareUrl
0 commit comments