Skip to content

Commit

Permalink
fix: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
isordo committed Jul 14, 2023
1 parent 3683b9c commit 1820ebf
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<h5>
{{
aggregatedInfo.totalAmount.toFixed()
| amountConverter: { protocol: airGapTxs[0].protocolIdentifier, maxDigits: undefined }
| amountConverter : { protocol: airGapTxs[0].protocolIdentifier, maxDigits: undefined }
| async
}}
</h5>
Expand All @@ -13,7 +13,7 @@ <h5>
<h5>{{ aggregatedInfo.numberOfTxs }}</h5>
</ion-col>
<ion-col size="4" class="content--align__center-center">
<h5>{{ aggregatedInfo.totalFees.toFixed() | feeConverter: { protocol: airGapTxs[0].protocolIdentifier } | async }}</h5>
<h5>{{ aggregatedInfo.totalFees.toFixed() | feeConverter : { protocol: airGapTxs[0].protocolIdentifier } | async }}</h5>
</ion-col>
<ion-col size="4">
<small>Amount</small>
Expand All @@ -32,22 +32,6 @@ <h5>{{ aggregatedInfo.totalFees.toFixed() | feeConverter: { protocol: airGapTxs[
<airgap-from-to class="ion-padding-horizontal" [transaction]="airGapTx" [hideNetwork]="true"></airgap-from-to>
</ng-container>

<ng-container *ngFor="let address of addressesNotOnContactBook">
<div class="suggestion-wrapper">
<p>This address is not in your address book:</p>
<div class="divider">
<airgap-identicon class="image" [address]="address"></airgap-identicon>
<span>{{ address }}</span>
</div>
<p>Do you want to add it?</p>
<div class="divider-buttons">
<ion-button class="button" color="tertiary" (click)="onClickDontAddContact(address)">No</ion-button>
<ion-button class="button" color="tertiary" (click)="onClickAddContact(address)">Yes</ion-button>
</div>
<ion-button class="button" color="primary" (click)="onClickDisableContact()">No, disable address book feature</ion-button>
</div>
</ng-container>

<ng-container *ngIf="fallbackActivated">
<ion-row>
<ion-col size="2" class="ion-margin-top">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +0,0 @@
.suggestion-wrapper {
display: flex;
flex-direction: column;
border: 1px solid var(--ion-color-primary);
padding: 12px;
border-radius: 12px;

p {
margin-top: 0px;
color: var(--ion-color-primary);
margin-bottom: 12px;
font-weight: 500;
}

span {
color: white;
}

.divider {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 12px;

span {
flex: 1;
line-break: anywhere;
font-size: 14px;
font-weight: 600;
}

.image {
width: 50px;
height: 50px;
}
}

.divider-buttons {
display: flex;
align-items: center;
gap: 4px;
}

ion-button {
flex: 1;
font-size: 14px;
--padding-bottom: 12px;
--padding-top: 12px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import { TokenService } from 'src/app/services/token/TokenService'
import { SecretsService } from 'src/app/services/secrets/secrets.service'
import { IACMessageDefinitionObjectV3 } from '@airgap/serializer'
import { TezosSaplingProtocol } from '@airgap/tezos'
import { NavigationService } from 'src/app/services/navigation/navigation.service'
import { ContactsService } from 'src/app/services/contacts/contacts.service'
import { ErrorCategory, handleErrorLocal } from 'src/app/services/error-handler/error-handler.service'
import { AddType } from 'src/app/services/contacts/contacts.service'

@Component({
selector: 'airgap-signed-transaction',
Expand All @@ -23,7 +19,6 @@ export class SignedTransactionComponent {
@Input()
public syncProtocolString: string

public addressesNotOnContactBook: string[] = []
public airGapTxs: IAirGapTransaction[]
public fallbackActivated: boolean = false
public rawTxData: string
Expand All @@ -39,9 +34,7 @@ export class SignedTransactionComponent {
private readonly protocolService: ProtocolService,
private readonly serializerService: SerializerService,
private readonly tokenService: TokenService,
private readonly secretsService: SecretsService,
private readonly navigationService: NavigationService,
private readonly contactsService: ContactsService
private readonly secretsService: SecretsService
) {
//
}
Expand Down Expand Up @@ -105,50 +98,15 @@ export class SignedTransactionComponent {
this.rawTxData = (this.signedTxs[0].payload as SignedTransaction).transaction
}
}

this.checkAdressesNames()
}

public async checkAdressesNames() {
// Check for addresses in contact book
if (this.airGapTxs && this.airGapTxs.length > 0) {
const isBookenabled = await this.contactsService.isBookEnabled()
if (isBookenabled) {
this.addressesNotOnContactBook = []
for (let i = 0; i < this.airGapTxs.length; i++) {
this.airGapTxs[i].extra = { names: {} }
const transaction = this.airGapTxs[i]
const toAddresses = transaction.to
for (let j = 0; j < toAddresses.length; j++) {
const toAddress = toAddresses[j]
const hasContactBookAddress = await this.contactsService.isAddressInContacts(toAddress)
if (!hasContactBookAddress) this.addressesNotOnContactBook.push(toAddress)
else {
const name = await this.contactsService.getContactName(toAddress)
if (name) this.airGapTxs[i].extra.names[toAddress] = name
}
}
const fromAddresses = transaction.from
for (let j = 0; j < fromAddresses.length; j++) {
const fromAddress = fromAddresses[j]
const hasContactBookAddress = await this.contactsService.isAddressInContacts(fromAddress)
if (!hasContactBookAddress && !this.addressesNotOnContactBook.includes(fromAddress))
this.addressesNotOnContactBook.push(fromAddress)
else {
const name = await this.contactsService.getContactName(fromAddress)
if (name) this.airGapTxs[i].extra.names[fromAddress] = name
}
}
}
}
}
}

private async checkIfSaplingTransaction(transaction: SignedTransaction, protocolIdentifier: ProtocolSymbols): Promise<boolean> {
if (protocolIdentifier === MainProtocolSymbols.XTZ) {
try {
const saplingAdapter: ICoinProtocolAdapter<TezosSaplingProtocol> = await this.getSaplingProtocol()
const txDetails: IAirGapTransaction[] = await saplingAdapter.getTransactionDetailsFromSigned(transaction, { transactionOwner: protocolIdentifier })
const txDetails: IAirGapTransaction[] = await saplingAdapter.getTransactionDetailsFromSigned(transaction, {
transactionOwner: protocolIdentifier
})
const recipients: string[] = txDetails
.map((details) => details.to)
.reduce((flatten: string[], next: string[]) => flatten.concat(next), [])
Expand All @@ -172,23 +130,4 @@ export class SignedTransactionComponent {

return protocol as ICoinProtocolAdapter<TezosSaplingProtocol>
}

async onClickAddContact(address: string) {
this.navigationService
.routeWithState('/contact-book-contacts-detail', { isNew: true, address, addType: AddType.SIGNING })
.catch(handleErrorLocal(ErrorCategory.IONIC_NAVIGATION))
}

async onClickDontAddContact(address: string) {
await this.contactsService.addSuggestion(address)
const index = this.addressesNotOnContactBook.findIndex((address) => address === address)
if (index >= 0) {
this.addressesNotOnContactBook.splice(index, 1)
}
}

async onClickDisableContact() {
await this.contactsService.setBookEnable(false)
this.addressesNotOnContactBook = []
}
}
7 changes: 1 addition & 6 deletions src/app/pages/transaction-signed/transaction-signed.page.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Component, ViewChild } from '@angular/core'
import { Component } from '@angular/core'
import { AirGapWallet } from '@airgap/coinlib-core'
import { MessageSignResponse } from '@airgap/serializer'
import { TranslateService } from '@ngx-translate/core'

import { ErrorCategory, handleErrorLocal } from '../../services/error-handler/error-handler.service'
import { NavigationService } from '../../services/navigation/navigation.service'
import { SignedTransactionComponent } from 'src/app/components/signed-transaction/signed-transaction.component'

enum TransactionQRType {
SignedAirGap = 0,
Expand All @@ -18,9 +17,6 @@ enum TransactionQRType {
styleUrls: ['./transaction-signed.page.scss']
})
export class TransactionSignedPage {
@ViewChild(SignedTransactionComponent)
private transactionComponent: SignedTransactionComponent

public signedTxs: string[]
public interactionUrl: string

Expand Down Expand Up @@ -52,7 +48,6 @@ export class TransactionSignedPage {
const temp = this.interactionUrl
this.interactionUrl = null
this.interactionUrl = temp
this.transactionComponent?.checkAdressesNames()
}

public done(): void {
Expand Down

0 comments on commit 1820ebf

Please sign in to comment.