Skip to content

Commit

Permalink
Merge branch 'fix/release-3.8.0' into 'develop'
Browse files Browse the repository at this point in the history
fix/release-3.8.0

See merge request papers/airgap/airgap-common-components!77
  • Loading branch information
godenzim committed Jul 29, 2021
2 parents 5a86035 + d6fc90c commit ddf4ef1
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 59 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.0.14",
"version": "0.0.15",
"packages": [
"packages/*"
],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@airgap/angular-ngrx": "file:packages/ngrx"
},
"devDependencies": {
"@airgap/coinlib-core": "^0.11.5",
"@airgap/coinlib-core": "^0.11.7",
"@angular-devkit/build-angular": "~0.1102.8",
"@angular-devkit/core": "^11.2.9",
"@angular-eslint/eslint-plugin": "2.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airgap/angular-core",
"version": "0.0.14",
"version": "0.0.15",
"publishConfig": {
"access": "public"
},
Expand All @@ -20,7 +20,7 @@
"tslib": "^2.2.0"
},
"peerDependencies": {
"@airgap/coinlib-core": "^0.11.5",
"@airgap/coinlib-core": "^0.11.7",
"@angular/animations": "^11.2.9",
"@angular/common": "^11.2.9",
"@angular/core": "^11.2.9",
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/assets/i18n-common/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
"title": "Oops",
"message": "It looks like you don't have {{otherApp.name}} installed on this device.",
"ok": "Ok"
},
"invalid": {
"title": "Oops",
"message": "It looks like the deeplink could not be generated",
"ok": "Ok"
}
},
"qr-settings": {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/assets/symbols/uusd.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/core/src/assets/symbols/you.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
(click)="copyToClipboard()"
></airgap-qr>

<ion-select slot="end" [ngModel]="qrType" interface="popover" (ngModelChange)="updateGenerator($event)">
<p *ngIf="qrError">{{ qrError }}</p>

<ion-select *ngIf="availableQRTypes.length > 0" slot="end" [ngModel]="qrType" interface="popover" (ngModelChange)="updateGenerator($event)">
<ion-select-option *ngFor="let availableQRType of availableQRTypes" [value]="availableQRType">
<ion-text>
{{ availableQRType }}
Expand Down
55 changes: 37 additions & 18 deletions packages/core/src/lib/components/iac-qr/iac-qr.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { Component, Input, OnDestroy, Inject } from '@angular/core'

import { QRCodeErrorCorrectionLevel } from 'angularx-qrcode'
import { ClipboardService } from '../../services/clipboard/clipboard.service'
import { SerializerDefaults, SerializerService } from '../../services/serializer/serializer.service'
import { SerializerService } from '../../services/serializer/serializer.service'
import { APP_CONFIG, AppConfig } from '../../config/app-config'
import { IACQrGenerator } from '../../services/iac/qr-generator'
import { SerializerV3Generator } from '../../services/qr/qr-generators/serializer-v3-generator'
import { SerializerV2Generator } from '../../services/qr/qr-generators/serializer-v2-generator'
import { IACMessageDefinitionObjectV3 } from '@airgap/coinlib-core'
import { defaultValues } from '../../services/storage/storage.service'

export enum QRType {
V2 = 'QR Code V2',
Expand All @@ -20,15 +21,15 @@ export enum QRType {
styleUrls: ['./iac-qr.component.scss']
})
export class IACQrComponent implements OnDestroy {
public availableQRTypes = [QRType.V2, QRType.V3]
public availableQRTypes: QRType[] = []
public numberOfParts: number = 0

private readonly generatorsMap: Map<string, IACQrGenerator>
private readonly generatorsMap: Map<string, IACQrGenerator> = new Map()

private readonly singleChunkSize: number = SerializerDefaults.SINGLE
private readonly multiChunkSize: number = SerializerDefaults.MULTI
private readonly singleChunkSize: number = defaultValues.SETTINGS_SERIALIZER_SINGLE_CHUNK_SIZE
private readonly multiChunkSize: number = defaultValues.SETTINGS_SERIALIZER_MULTI_CHUNK_SIZE

private activeGenerator: IACQrGenerator
private activeGenerator: IACQrGenerator | undefined
@Input()
public level: keyof typeof QRCodeErrorCorrectionLevel = 'L'

Expand All @@ -44,33 +45,41 @@ export class IACQrComponent implements OnDestroy {
this.convertToDataArray()
}

public qrdataArray: string[] = ['']

public qrType: QRType = QRType.V3
public qrType: QRType
public qrdata: string = ''

public qrError: string = ''

private _messageDefinitionObjects: IACMessageDefinitionObjectV3[] = []

private readonly timeout: NodeJS.Timeout
private timeout?: NodeJS.Timeout

constructor(
private readonly clipboardService: ClipboardService,
private readonly serializerService: SerializerService,
@Inject(APP_CONFIG) private readonly appConfig: AppConfig
) {
this.singleChunkSize = this.serializerService.singleChunkSize
this.multiChunkSize = this.serializerService.multiChunkSize
this.generatorsMap = new Map()

const v3Generator = new SerializerV3Generator()
const v2Generator = new SerializerV2Generator()

this.generatorsMap.set(QRType.V3, v3Generator)
this.availableQRTypes.push(QRType.V3)
this.generatorsMap.set(QRType.V2, v2Generator)
this.availableQRTypes.push(QRType.V2)

this.activeGenerator = v3Generator

if (!this.serializerService.useV3) {
if (this.serializerService.useV3) {
this.activeGenerator = v3Generator
this.qrType = QRType.V3
} else {
this.activeGenerator = v2Generator
this.qrType = QRType.V2
}
}

ngOnInit() {
this.timeout = setInterval(async () => {
this.qrdata = this.activeGenerator ? await this.activeGenerator.nextPart() : ''
}, this.serializerService.displayTimePerChunk)
Expand All @@ -81,6 +90,8 @@ export class IACQrComponent implements OnDestroy {
if (generator) {
this.activeGenerator = generator
this.convertToDataArray()
} else {
console.error('NO GENERATOR FOUND FOR ', value)
}
}

Expand All @@ -91,18 +102,26 @@ export class IACQrComponent implements OnDestroy {
}

public async copyToClipboard(): Promise<void> {
let copyString: string = await this.activeGenerator.getSingle(this.appConfig.otherApp.urlScheme)
let copyString: string = this.activeGenerator ? await this.activeGenerator.getSingle(this.appConfig.otherApp.urlScheme) : ''

await this.clipboardService.copyAndShowToast(copyString)
}

private async convertToDataArray(): Promise<void> {
this.qrError = ''
if (this.activeGenerator) {
await this.activeGenerator.create(this._messageDefinitionObjects, this.multiChunkSize, this.singleChunkSize)
this.qrdata = await this.activeGenerator.nextPart()
this.numberOfParts = await this.activeGenerator.getNumberOfParts()
try {
await this.activeGenerator.create(this._messageDefinitionObjects, this.multiChunkSize, this.singleChunkSize)
this.qrdata = await this.activeGenerator.nextPart()
this.qrError = ''
this.numberOfParts = await this.activeGenerator.getNumberOfParts()
} catch (e) {
console.log('QR generation error', e)
this.qrError = 'Message is not compatible with the selected QR code type. Please select another one.'
}
} else {
this.qrdata = ''
this.qrError = 'No QR type selected.'
this.numberOfParts = 0
}
}
Expand Down
17 changes: 14 additions & 3 deletions packages/core/src/lib/services/deeplink/deeplink.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,21 @@ export class DeeplinkService {

public async sameDeviceDeeplink(data: string | IACMessageDefinitionObjectV3[]): Promise<void> {
let deeplinkUrl = ''
let generator: IACQrGenerator
if (data && typeof data !== 'string') {
const generator: IACQrGenerator = this.serializerService.useV3 ? new SerializerV3Generator() : new SerializerV2Generator()
await generator.create(data, Number.MAX_SAFE_INTEGER)
deeplinkUrl = await generator.getSingle(this.appConfig.otherApp.urlScheme)
try {
generator = this.serializerService.useV3 ? new SerializerV3Generator() : new SerializerV2Generator()
await generator.create(data, Number.MAX_SAFE_INTEGER)
} catch (error) {
try {
generator = this.serializerService.useV3 ? new SerializerV2Generator() : new SerializerV3Generator()
await generator.create(data, Number.MAX_SAFE_INTEGER)
} catch (error) {
this.uiEventElementsService.invalidDeeplinkAlert().catch(console.error)
}
}

deeplinkUrl = await generator!.getSingle(this.appConfig.otherApp.urlScheme)
} else if (typeof data === 'string') {
deeplinkUrl = data
}
Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/lib/services/protocol/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import {
EthereumERC20ProtocolOptions,
EthereumProtocolNetwork,
EthereumERC20ProtocolConfig,
TezosUUSD,
TezosYOU,
TezosBTC,
TezosUSD,
SubProtocolSymbols
SubProtocolSymbols,
} from '@airgap/coinlib-core'
import { Token } from '../../types/Token'
import { ethTokens } from './tokens'
Expand All @@ -34,7 +36,7 @@ export function getDefaultActiveProtocols(): ICoinProtocol[] {
new TezosProtocol(),
new CosmosProtocol(),
new PolkadotProtocol(),
new KusamaProtocol()
new KusamaProtocol(),
]
}

Expand All @@ -47,6 +49,8 @@ export function getDefaultActiveSubProtocols(): [ICoinProtocol, ICoinSubProtocol
const ethereumProtocol = new EthereumProtocol()

return [
[tezosProtocol, new TezosUUSD()],
[tezosProtocol, new TezosYOU()],
[tezosProtocol, new TezosBTC()],
[tezosProtocol, new TezosUSD()],
[tezosProtocol, new TezosKtProtocol()],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
SubProtocolSymbols,
NetworkType,
ProtocolNetwork,
ICoinProtocol
ICoinProtocol,
} from '@airgap/coinlib-core'
import { duplicatesRemoved } from '../../utils/array'
import { getIdentifiers, getSubIdentifiers } from './utils/test'
Expand All @@ -35,7 +35,7 @@ import {
getDefaultPassiveSubProtocols
} from './defaults'

describe('ProtocolService', () => {
fdescribe('ProtocolService', () => {
let service: ProtocolService

let tezosTestnet: TezosProtocolNetwork
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ export class SerializerV2Handler implements IACMessageHandler<IACMessageDefiniti
await this.serializer.deserialize([part])
return true
} catch (error) {
if (error.availablePages && error.totalPages) {
try {
await this.serializer.deserialize(part.split(','))
return true
} else {
return false
} catch (error) {
if (error.availablePages && error.totalPages) {
return true
} else {
return false
}
}
}
}
Expand Down
31 changes: 13 additions & 18 deletions packages/core/src/lib/services/serializer/serializer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@ import {
SerializerV3
} from '@airgap/coinlib-core'
import { parseIACUrl } from '../../utils/utils'
import { InternalStorageKey, InternalStorageService } from '../storage/storage.service'
import { defaultValues, InternalStorageKey, InternalStorageService } from '../storage/storage.service'
import { IACMessages as IACMessagesV3 } from '@airgap/coinlib-core/serializer-v3/message' // TODO: Import from index
import { IACMessages as IACMessagesV2 } from '@airgap/coinlib-core/serializer/message' // TODO: Import from index
import { AccountShareResponse as AccountShareResponseV3 } from '@airgap/coinlib-core/serializer-v3/schemas/definitions/account-share-response' // TODO: Import from index
import { AccountShareResponse as AccountShareResponseV2 } from '@airgap/coinlib-core/serializer/schemas/definitions/account-share-response' // TODO: Import from index

export enum SerializerDefaults {
SINGLE = 500,
MULTI = 250,
TIME = 200
}

export const convertV2ToV3 = async (chunks: IACMessageDefinitionObject[]): Promise<IACMessageDefinitionObjectV3[]> => {
return chunks.map((message: IACMessageDefinitionObject) => {
let newPayload: IACMessagesV3
Expand Down Expand Up @@ -78,14 +72,14 @@ export const convertV3ToV2 = async (chunks: IACMessageDefinitionObjectV3[]): Pro
providedIn: 'root'
})
export class SerializerService {
public _singleChunkSize: number = SerializerDefaults.SINGLE
public _multiChunkSize: number = SerializerDefaults.MULTI
public _singleChunkSize: number = defaultValues.SETTINGS_SERIALIZER_SINGLE_CHUNK_SIZE
public _multiChunkSize: number = defaultValues.SETTINGS_SERIALIZER_MULTI_CHUNK_SIZE

private readonly serializer: Serializer = new Serializer()
private readonly serializerV3: SerializerV3 = new SerializerV3()

private _useV3: boolean = false
private _displayTimePerChunk: number = SerializerDefaults.TIME
private _useV3: boolean = defaultValues.SETTINGS_SERIALIZER_ENABLE_V3
private _displayTimePerChunk: number = defaultValues.SETTINGS_SERIALIZER_CHUNK_TIME

public get useV3(): boolean {
return this._useV3
Expand Down Expand Up @@ -128,20 +122,21 @@ export class SerializerService {
}

constructor(private readonly internalStorageService: InternalStorageService) {
this.useV3 = true

// eslint-disable-next-line no-console
this.loadSettings().catch(console.error)
}

public async resetSettings(): Promise<void> {
this._singleChunkSize = SerializerDefaults.SINGLE
this._multiChunkSize = SerializerDefaults.MULTI
this._displayTimePerChunk = SerializerDefaults.TIME
this._useV3 = defaultValues.SETTINGS_SERIALIZER_ENABLE_V3
this._singleChunkSize = defaultValues.SETTINGS_SERIALIZER_SINGLE_CHUNK_SIZE
this._multiChunkSize = defaultValues.SETTINGS_SERIALIZER_MULTI_CHUNK_SIZE
this._displayTimePerChunk = defaultValues.SETTINGS_SERIALIZER_CHUNK_TIME

await Promise.all([
this.internalStorageService.set(InternalStorageKey.SETTINGS_SERIALIZER_SINGLE_CHUNK_SIZE, SerializerDefaults.SINGLE),
this.internalStorageService.set(InternalStorageKey.SETTINGS_SERIALIZER_MULTI_CHUNK_SIZE, SerializerDefaults.MULTI)
this.internalStorageService.delete(InternalStorageKey.SETTINGS_SERIALIZER_ENABLE_V3),
this.internalStorageService.delete(InternalStorageKey.SETTINGS_SERIALIZER_SINGLE_CHUNK_SIZE),
this.internalStorageService.delete(InternalStorageKey.SETTINGS_SERIALIZER_MULTI_CHUNK_SIZE),
this.internalStorageService.delete(InternalStorageKey.SETTINGS_SERIALIZER_CHUNK_TIME)
])
}

Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/lib/services/storage/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ interface InternalStorageKeyReturnType {

type InternalStorageKeyReturnDefaults = { [key in InternalStorageKey]: InternalStorageKeyReturnType[key] }

const defaultValues: InternalStorageKeyReturnDefaults = {
[InternalStorageKey.SETTINGS_SERIALIZER_ENABLE_V3]: false,
[InternalStorageKey.SETTINGS_SERIALIZER_CHUNK_TIME]: 500,
[InternalStorageKey.SETTINGS_SERIALIZER_SINGLE_CHUNK_SIZE]: 350,
[InternalStorageKey.SETTINGS_SERIALIZER_MULTI_CHUNK_SIZE]: 100
export const defaultValues: InternalStorageKeyReturnDefaults = {
[InternalStorageKey.SETTINGS_SERIALIZER_ENABLE_V3]: true,
[InternalStorageKey.SETTINGS_SERIALIZER_CHUNK_TIME]: 200,
[InternalStorageKey.SETTINGS_SERIALIZER_SINGLE_CHUNK_SIZE]: 500,
[InternalStorageKey.SETTINGS_SERIALIZER_MULTI_CHUNK_SIZE]: 250
}

@Injectable({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ export class UiEventElementsService {
})
}

public async invalidDeeplinkAlert(): Promise<void> {
await this.uiEventService.showTranslatedAlert({
header: 'deeplink.invalid.title',
message: 'deeplink.invalid.message',
buttons: [
{
text: 'deeplink.invalid.ok',
role: 'cancel'
}
]
})
}

public async showOtherAppNotFoundAlert(): Promise<void> {
await this.uiEventService.showTranslatedAlert({
header: 'deeplink.app-not-found.title',
Expand Down
Loading

0 comments on commit ddf4ef1

Please sign in to comment.