-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: added contatct selection in interaction-page
- Loading branch information
Showing
8 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<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> |
Empty file.
24 changes: 24 additions & 0 deletions
24
src/app/components/add-address/add-address.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | ||
import { IonicModule } from '@ionic/angular'; | ||
|
||
import { AddAddressComponent } from './add-address.component'; | ||
|
||
describe('AddAddressComponent', () => { | ||
let component: AddAddressComponent; | ||
let fixture: ComponentFixture<AddAddressComponent>; | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ AddAddressComponent ], | ||
imports: [IonicModule.forRoot()] | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(AddAddressComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
})); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { IAirGapTransaction } from '@airgap/coinlib-core/interfaces/IAirGapTransaction'; | ||
import { Component, Input, OnInit } from '@angular/core'; | ||
import { AddType, ContactsService } from 'src/app/services/contacts/contacts.service'; | ||
import { ErrorCategory, handleErrorLocal } from 'src/app/services/error-handler/error-handler.service'; | ||
import { NavigationService } from 'src/app/services/navigation/navigation.service'; | ||
|
||
@Component({ | ||
selector: 'airgap-add-address', | ||
templateUrl: './add-address.component.html', | ||
styleUrls: ['./add-address.component.scss'], | ||
}) | ||
export class AddAddressComponent implements OnInit { | ||
public addressesNotOnContactBook: string[] = [] | ||
@Input() private airGapTxs: IAirGapTransaction[] = [] | ||
// selectTransactionsDetails | ||
// this.transactionsDetails$ = this.store.select(fromDeserializedDetail.selectTransactionsDetails) | ||
|
||
constructor(private readonly navigationService: NavigationService, private readonly contactsService: ContactsService) { } | ||
|
||
async ngOnInit() { | ||
await 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 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
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 onClickAddContact(address: string) { | ||
this.navigationService | ||
.routeWithState('/contact-book-contacts-detail', { isNew: true, address, addType: AddType.SIGNING }) | ||
.catch(handleErrorLocal(ErrorCategory.IONIC_NAVIGATION)) | ||
} | ||
|
||
async onClickDisableContact() { | ||
await this.contactsService.setBookEnable(false) | ||
this.addressesNotOnContactBook = [] | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters