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!709
  • Loading branch information
godenzim committed Sep 25, 2023
2 parents 94ce974 + 6f08016 commit 60e644e
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ class FileExplorer private constructor(

fun loadInstalledModules(): List<JSModule.Installed> = loadModules(filesExplorer, JSModule.Installed.constructor)

fun loadAssetModule(identifier: String): JSModule.Asset {
val manifest = JSObject(assetsExplorer.readModuleManifest(identifier).decodeToString())

return loadModule(identifier, manifest, JSModule.Asset.constructor)
}

fun loadInstalledModule(identifier: String): JSModule.Installed {
val manifest = JSObject(filesExplorer.readModuleManifest(identifier).decodeToString())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,30 @@ class IsolatedModules : Plugin() {
}
}

@PluginMethod
fun readAssetModule(call: PluginCall) {
call.executeCatching {
assertReceived(Param.IDENTIFIER)

activity.lifecycleScope.launch {
executeCatching {
val module = fileExplorer.loadAssetModule(identifier)
val manifest = fileExplorer.readModuleManifest(module)

resolve(
JSObject(
"""
{
"manifest": ${JSObject(manifest.decodeToString())}
}
""".trimIndent()
)
)
}
}
}
}

@PluginMethod
fun loadAllModules(call: PluginCall) {
activity.lifecycleScope.launch {
Expand Down
12 changes: 8 additions & 4 deletions ios/App/App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
88BD9D1325F0CE4800780458 /* PluginCall+Additions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88BD9D1225F0CE4800780458 /* PluginCall+Additions.swift */; };
A084ECDBA7D38E1E42DFC39D /* Pods_App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AF277DCFFFF123FFC6DF26C7 /* Pods_App.framework */; };
A35472FF29EDA1F700AFD5A7 /* Hex.swift in Sources */ = {isa = PBXBuildFile; fileRef = A35472FE29EDA1F700AFD5A7 /* Hex.swift */; };
A3BD9A0F2AA5EB9000666155 /* Dictionary+Additions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3BD9A0E2AA5EB9000666155 /* Dictionary+Additions.swift */; };
A3FCA8F329E5B5500012FE3C /* JSValue+Additions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3FCA8F229E5B5500012FE3C /* JSValue+Additions.swift */; };
A3FCA8F529E5B5680012FE3C /* WK_Additions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3FCA8F429E5B5680012FE3C /* WK_Additions.swift */; };
A3FCA8F529E5B5680012FE3C /* WK+Additions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3FCA8F429E5B5680012FE3C /* WK+Additions.swift */; };
A3FCA8F729E5B57C0012FE3C /* Sequence+Additions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3FCA8F629E5B57C0012FE3C /* Sequence+Additions.swift */; };
A3FCA8F929E5B5870012FE3C /* JS.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3FCA8F829E5B5870012FE3C /* JS.swift */; };
A3FCA8FB29E5B5980012FE3C /* Filesystem.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3FCA8FA29E5B5980012FE3C /* Filesystem.swift */; };
Expand Down Expand Up @@ -59,8 +60,9 @@
88BD9D0D25F0CDF900780458 /* SaplingNative.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SaplingNative.m; sourceTree = "<group>"; };
88BD9D1225F0CE4800780458 /* PluginCall+Additions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PluginCall+Additions.swift"; sourceTree = "<group>"; };
A35472FE29EDA1F700AFD5A7 /* Hex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Hex.swift; sourceTree = "<group>"; };
A3BD9A0E2AA5EB9000666155 /* Dictionary+Additions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Dictionary+Additions.swift"; sourceTree = "<group>"; };
A3FCA8F229E5B5500012FE3C /* JSValue+Additions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "JSValue+Additions.swift"; sourceTree = "<group>"; };
A3FCA8F429E5B5680012FE3C /* WK_Additions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WK_Additions.swift; sourceTree = "<group>"; };
A3FCA8F429E5B5680012FE3C /* WK+Additions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WK+Additions.swift"; sourceTree = "<group>"; };
A3FCA8F629E5B57C0012FE3C /* Sequence+Additions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Sequence+Additions.swift"; sourceTree = "<group>"; };
A3FCA8F829E5B5870012FE3C /* JS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JS.swift; sourceTree = "<group>"; };
A3FCA8FA29E5B5980012FE3C /* Filesystem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Filesystem.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -184,8 +186,9 @@
children = (
88BD9D1225F0CE4800780458 /* PluginCall+Additions.swift */,
A3FCA8F229E5B5500012FE3C /* JSValue+Additions.swift */,
A3FCA8F429E5B5680012FE3C /* WK_Additions.swift */,
A3FCA8F429E5B5680012FE3C /* WK+Additions.swift */,
A3FCA8F629E5B57C0012FE3C /* Sequence+Additions.swift */,
A3BD9A0E2AA5EB9000666155 /* Dictionary+Additions.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -363,10 +366,11 @@
A3FCA90C29E5C2A40012FE3C /* JSModule.swift in Sources */,
881CF03124530A4D007A5381 /* AppInfo.swift in Sources */,
A3FCA90129E5C2890012FE3C /* IsolatedModules.swift in Sources */,
A3BD9A0F2AA5EB9000666155 /* Dictionary+Additions.swift in Sources */,
A3FCA8F329E5B5500012FE3C /* JSValue+Additions.swift in Sources */,
A3FCA8F729E5B57C0012FE3C /* Sequence+Additions.swift in Sources */,
88BD9D0E25F0CDF900780458 /* SaplingNative.m in Sources */,
A3FCA8F529E5B5680012FE3C /* WK_Additions.swift in Sources */,
A3FCA8F529E5B5680012FE3C /* WK+Additions.swift in Sources */,
88BD9D1325F0CE4800780458 /* PluginCall+Additions.swift in Sources */,
A3FCA8F929E5B5870012FE3C /* JS.swift in Sources */,
A3FCA90029E5C2890012FE3C /* FileExplorer.swift in Sources */,
Expand Down
26 changes: 26 additions & 0 deletions ios/App/App/Helpers/Extensions/Dictionary+Additions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Dictionary+Additions.swift
// App
//
// Created by Julia Samol on 04.09.23.
//

import Foundation

extension Dictionary {
@inlinable subscript(key: Key, setDefault defaultValue: @autoclosure () -> Value) -> Value {
mutating get {
guard let value = self[key] else {
let value = defaultValue()
self[key] = value

return value
}

return value
}
set {
self[key] = newValue
}
}
}
14 changes: 10 additions & 4 deletions ios/App/App/IsolatedModules/FileExplorer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,22 @@ struct FileExplorer {
try loadModules(using: assetsExplorer, creatingModuleWith: JSModule.Asset.getInit())
}

func loadInstalledModules() throws -> [JSModule.Installed] {
try loadModules(using: documentExplorer, creatingModuleWith: JSModule.Installed.getInit(using: documentExplorer))
}

func loadAssetModule(_ identifier: String) throws -> JSModule.Asset {
let manifest = try assetsExplorer.readModuleManifest(identifier)

return try loadModule(identifier, fromManifest: manifest, creatingModuleWith: JSModule.Asset.getInit())
}

func loadInstalledModule(_ identifier: String) throws -> JSModule.Installed {
let manifest = try documentExplorer.readModuleManifest(identifier)

return try loadModule(identifier, fromManifest: manifest, creatingModuleWith: JSModule.Installed.getInit(using: documentExplorer))
}

func loadInstalledModules() throws -> [JSModule.Installed] {
try loadModules(using: documentExplorer, creatingModuleWith: JSModule.Installed.getInit(using: documentExplorer))
}

func loadPreviewModule(atPath path: String, locatedIn directory: Directory) throws -> JSModule.Preview {
guard let directory = fileManager.getDirectory(from: directory),
let url = fileManager.urls(for: directory, in: .userDomainMask).first?.appendingPathComponent(path) else {
Expand Down
1 change: 1 addition & 0 deletions ios/App/App/IsolatedModules/IsolatedModules.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
CAP_PLUGIN_METHOD(registerDynamicModule, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(readDynamicModule, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(removeDynamicModules, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(readAssetModule, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(loadAllModules, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(callMethod, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(batchCallMethod, CAPPluginReturnPromise);
Expand Down
25 changes: 25 additions & 0 deletions ios/App/App/IsolatedModules/IsolatedModules.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,31 @@ public class IsolatedModules: CAPPlugin {
}
}

@objc func readAssetModule(_ call: CAPPluginCall) {
call.assertReceived(forMethod: "readAssetModule", requiredParams: Param.IDENTIFIER)

do {
guard let identifier = call.identifier else {
throw Error.invalidData
}

Task {
do {
let module = try fileExplorer.loadAssetModule(identifier)
let manifest = try fileExplorer.readModuleManifest(.asset(module))

call.resolve([
"manifest": try JSONSerialization.jsonObject(with: manifest)
])
} catch {
call.reject("Error: \(error)")
}
}
} catch {
call.reject("Error: \(error)")
}
}

@objc func loadAllModules(_ call: CAPPluginCall) {
Task {
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class WebViewEnvironment: NSObject, JSEnvironment, WKNavigationDelegate {
);
"""

webView.evaluateJavaScript(script, completionHandler: nil)
try await webView.evaluateJavaScriptAsync(script)
guard let result = try await jsAsyncResult.awaitResultWithID(resultID) as? [String: Any] else {
throw Error.invalidResult
}
Expand Down Expand Up @@ -72,7 +72,7 @@ class WebViewEnvironment: NSObject, JSEnvironment, WKNavigationDelegate {

private actor WebViewManager {
private(set) var webViews: [String: [String: WKWebViewExtended]] = [:]
@MainActor private var activeTasks: [String: Task<WKWebViewExtended, Swift.Error>] = [:]
@MainActor private var activeTasks: [String: [String: Task<WKWebViewExtended, Swift.Error>]] = [:]

func add(
runRef: String,
Expand All @@ -81,11 +81,7 @@ class WebViewEnvironment: NSObject, JSEnvironment, WKNavigationDelegate {
userContentController: WKUserContentController,
jsAsyncResult: JSAsyncResult
) {
if webViews[runRef] == nil {
webViews[runRef] = .init()
}

webViews[runRef]![module.identifier] = (webView, userContentController, jsAsyncResult)
webViews[runRef, setDefault: .init()][module.identifier] = (webView, userContentController, jsAsyncResult)
}

@MainActor
Expand All @@ -94,7 +90,7 @@ class WebViewEnvironment: NSObject, JSEnvironment, WKNavigationDelegate {
and module: JSModule,
using env: WebViewEnvironment
) async throws -> WKWebViewExtended {
if let runRef = runRef, let activeTask = activeTasks[runRef] {
if let runRef = runRef, let activeTask = activeTasks[runRef]?[module.identifier] {
return try await activeTask.value
}

Expand Down Expand Up @@ -153,7 +149,7 @@ class WebViewEnvironment: NSObject, JSEnvironment, WKNavigationDelegate {
}

if let runRef = runRef {
activeTasks[runRef] = task
activeTasks[runRef, setDefault: .init()][module.identifier] = task
}

return try await task.value
Expand All @@ -173,10 +169,16 @@ class WebViewEnvironment: NSObject, JSEnvironment, WKNavigationDelegate {

func remove(at runRef: String) {
webViews.removeValue(forKey: runRef)
Task { @MainActor in
activeTasks.removeValue(forKey: runRef)
}
}

func removeAll() {
webViews.removeAll()
Task { @MainActor in
activeTasks.removeAll()
}
}

@MainActor
Expand Down
30 changes: 15 additions & 15 deletions 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
},
"dependencies": {
"@airgap/aeternity": "0.13.20",
"@airgap/angular-core": "0.0.41",
"@airgap/angular-ngrx": "0.0.41",
"@airgap/angular-core": "0.0.42",
"@airgap/angular-ngrx": "0.0.42",
"@airgap/astar": "0.13.20",
"@airgap/beacon-sdk": "3.1.5-beta.0",
"@airgap/bitcoin": "0.13.20",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export enum IsolatedModulesDetailsMode {
INSTALL,
UPDATE,
VIEW_INSTALLED
VIEW_INSTALLED,
VIEW_ASSET
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CommonModule } from '@angular/common'
import { Injector, NgModule } from '@angular/core'
import { FormsModule } from '@angular/forms'
import { IonicModule } from '@ionic/angular'
import { PushPipe } from '@ngrx/component'
import { LetDirective, PushPipe } from '@ngrx/component'
import { TranslateModule } from '@ngx-translate/core'

import { ComponentsModule } from '../../components/components.module'
Expand All @@ -18,6 +18,7 @@ import { IsolatedModulesListPage } from './isolated-modules-list.page'
IonicModule,
IsolatedModulesListPageRoutingModule,
TranslateModule,
LetDirective,
PushPipe,
ComponentsModule,
AirGapAngularCoreModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ export class IsolatedModulesListPage implements OnInit, ViewWillEnter, ViewWillL
}

public async onModuleSelected(metadata: IsolatedModuleMetadata): Promise<void> {
const mode = metadata.type === 'asset' ? IsolatedModulesDetailsMode.VIEW_ASSET : IsolatedModulesDetailsMode.VIEW_INSTALLED
this.dataService.setData(DataServiceKey.DETAIL, {
metadata,
mode: IsolatedModulesDetailsMode.VIEW_INSTALLED
mode
})
this.router
.navigateByUrl(`/isolated-modules-details/${DataServiceKey.DETAIL}/${IsolatedModulesDetailsMode.INSTALL}`)
.navigateByUrl(`/isolated-modules-details/${DataServiceKey.DETAIL}/${mode}`)
.catch(handleErrorSentry(ErrorCategory.NAVIGATION))
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,14 @@
</ion-item>
</ion-list>

<!-- <ion-list lines="none">
<ion-list lines="none">
<ion-list-header class="ion-no-margin" lines="none">
<ion-label>{{ 'settings.add-ons_settings.label' | translate }}</ion-label>
</ion-list-header>
<ion-item (click)="goToIsolatedModules()" detail="true">
<ion-icon name="cube-outline" slot="start"></ion-icon>
{{ 'settings.add-ons_settings.isolated-modules_text' | translate }}
</ion-item>
</ion-list> -->
</ion-list>
</ion-grid>
</ion-content>
1 change: 1 addition & 0 deletions src/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ transaction-item {

airgap-currency-symbol {
img {
aspect-ratio: 1/1;
border-radius: 50%;
}
}
Expand Down

0 comments on commit 60e644e

Please sign in to comment.