Skip to content

Commit

Permalink
Merge branch 'feat/rsk-ready' into 'develop'
Browse files Browse the repository at this point in the history
Feat/rsk-ready

See merge request papers/airgap/airgap-wallet!686
  • Loading branch information
godenzim committed Aug 10, 2023
2 parents ea591a3 + 33f2c52 commit c4fe22a
Show file tree
Hide file tree
Showing 20 changed files with 619 additions and 589 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class IsolatedModules : Plugin() {
JSObject("""
{
"type": "success",
"value": ${value.get("value")}
"value": ${value.get("value").serialize()}
}
""".trimIndent())
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.getcapacitor.JSArray
import com.getcapacitor.JSObject
import it.airgap.wallet.plugin.isolatedmodules.js.environment.JSEnvironment
import it.airgap.wallet.util.assign
import it.airgap.wallet.util.toJson
import it.airgap.wallet.util.toJS
import java.util.*

sealed interface JSModule {
Expand Down Expand Up @@ -74,7 +74,7 @@ sealed interface JSModuleAction {
override fun toJson(): String = JSObject("""
{
"type": "$TYPE",
"protocolType": ${protocolType?.toString().toJson()},
"protocolType": ${protocolType?.toString().toJS()},
"ignoreProtocols": ${ignoreProtocols ?: "[]"}
}
""".trimIndent()).toString()
Expand Down Expand Up @@ -125,7 +125,7 @@ sealed interface JSModuleAction {
JSCallMethodTarget.OnlineProtocol, JSObject("""
{
protocolIdentifier: "$protocolIdentifier",
networkId: ${networkId.toJson()}
networkId: ${networkId.toJS()}
}
""".trimIndent())
)
Expand All @@ -139,7 +139,7 @@ sealed interface JSModuleAction {
JSCallMethodTarget.BlockExplorer, JSObject("""
{
protocolIdentifier: "$protocolIdentifier",
networkId: ${networkId.toJson()}
networkId: ${networkId.toJS()}
}
""".trimIndent())
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package it.airgap.wallet.util

fun Any.serialize(): Any = when (this) {
is String -> "\"$this\""
else -> toString()
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package it.airgap.wallet.util

fun String?.toJson(): Any = this?.let { "\"$it\"" } ?: JSUndefined
fun String?.toJS(): Any = this?.serialize() ?: JSUndefined
141 changes: 81 additions & 60 deletions copy-builtin-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,59 @@ const browserify = require('browserify')

const rootdir = './'
const assetsdir = path.join(rootdir, 'src/assets')
const modules = [
{ path: path.join(rootdir, 'node_modules/@airgap/aeternity') },
{
path: path.join(rootdir, 'node_modules/@airgap/astar'),
jsenv: {
android: 'webview'
}
},
{
path: path.join(rootdir, 'node_modules/@airgap/bitcoin'),
jsenv: {
android: 'webview'
}
},
{ path: path.join(rootdir, 'node_modules/@airgap/coreum') },
{
path: path.join(rootdir, 'node_modules/@airgap/cosmos'),
jsenv: {
android: 'webview'
}
},
{
path: path.join(rootdir, 'node_modules/@airgap/ethereum'),
jsenv: {
android: 'webview'
}
},
{ path: path.join(rootdir, 'node_modules/@airgap/groestlcoin') },
{
path: path.join(rootdir, 'node_modules/@airgap/icp'),
jsenv: {
android: 'webview'
}
},
{
path: path.join(rootdir, 'node_modules/@airgap/moonbeam'),
jsenv: {
android: 'webview'
}
},
{
path: path.join(rootdir, 'node_modules/@airgap/optimism'),
jsenv: {
android: 'webview'
}
},
{
path: path.join(rootdir, 'node_modules/@airgap/polkadot'),
jsenv: {
android: 'webview'
}
},
{
path: path.join(rootdir, 'node_modules/@airgap/tezos'),
jsenv: {
android: 'webview'
}
}
const airgapModules = [
// { path: path.join(rootdir, 'node_modules/@airgap/aeternity') },
// {
// path: path.join(rootdir, 'node_modules/@airgap/astar'),
// jsenv: {
// android: 'webview'
// }
// },
// { path: path.join(rootdir, 'node_modules/@airgap/bitcoin') },
// { path: path.join(rootdir, 'node_modules/@airgap/cosmos') },
// {
// path: path.join(rootdir, 'node_modules/@airgap/ethereum'),
// jsenv: {
// android: 'webview'
// }
// },
// { path: path.join(rootdir, 'node_modules/@airgap/groestlcoin') },
// {
// path: path.join(rootdir, 'node_modules/@airgap/icp'),
// jsenv: {
// android: 'webview'
// }
// },
// {
// path: path.join(rootdir, 'node_modules/@airgap/moonbeam'),
// jsenv: {
// android: 'webview'
// }
// },
// {
// path: path.join(rootdir, 'node_modules/@airgap/optimism'),
// jsenv: {
// android: 'webview'
// }
// },
// {
// path: path.join(rootdir, 'node_modules/@airgap/polkadot'),
// jsenv: {
// android: 'webview'
// }
// },
// {
// path: path.join(rootdir, 'node_modules/@airgap/tezos'),
// jsenv: {
// android: 'webview'
// }
// }
]
const communityModules = [
{ path: path.join(rootdir, 'node_modules/@airgap-community/iso-rootstock') }
]

function createAssetModule(module) {
function createAirGapModule(module) {
const packageJson = require(`./${path.join(module.path, 'package.json')}`)
const namespace = module.path.split('/').slice(-1)[0]
const outputDir = path.join(assetsdir, `protocol_modules/${namespace}`)
Expand All @@ -83,6 +75,7 @@ function createAssetModule(module) {
version: packageJson.version,
author: packageJson.author,
publicKey: "" /* TODO */,
description: "",
src: {
namespace
},
Expand All @@ -95,4 +88,32 @@ function createAssetModule(module) {
fs.writeFileSync(path.join(outputDir, 'manifest.json'), JSON.stringify(manifest, null, 2), 'utf8')
}

modules.forEach((path) => createAssetModule(path))
function copyCommunityModule(module) {
const namespace = module.path.split('/').slice(-1)[0]
const outputDir = path.join(assetsdir, `protocol_modules/${namespace}`)

fs.mkdirSync(outputDir, { recursive: true })

const manifestPath = path.join(module.path, 'manifest.json')
const manifest = require(`./${manifestPath}`)
manifest.include.forEach((file) => {
fs.copyFileSync(path.join(module.path, file), path.join(outputDir, file))
})

fs.copyFileSync(manifestPath, path.join(outputDir, 'manifest.json'))
fs.copyFileSync(path.join(module.path, 'module.sig'), path.join(outputDir, 'module.sig'))

Object.entries(manifest.res?.symbol ?? {}).forEach(([key, value]) => {
// TODO: improve robustness of the solution
if (!value.startsWith('file://')) {
return
}

const symbolPath = value.slice(7)
const symbolExtension = symbolPath.split('.').slice(-1)
fs.copyFileSync(path.join(module.path, symbolPath), path.join(rootdir, 'node_modules/@airgap/angular-core/src/assets/symbols', `${key}.${symbolExtension}`))
})
}

airgapModules.forEach((module) => createAirGapModule(module))
communityModules.forEach((module) => copyCommunityModule(module))
Loading

0 comments on commit c4fe22a

Please sign in to comment.