Skip to content

Commit

Permalink
Merge pull request #38 from nabla-studio/DavideSegullo/feat-wallet_re…
Browse files Browse the repository at this point in the history
…gistry

feat(wallet-registry): ✨ add wallet registry setup
  • Loading branch information
DavideSegullo authored Dec 18, 2023
2 parents d180ad9 + d39121e commit e7bf169
Show file tree
Hide file tree
Showing 26 changed files with 1,050 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "packages/chain-registry/chain-registry"]
path = packages/chain-registry/chain-registry
url = [email protected]:cosmos/chain-registry.git
[submodule "packages/wallet-registry/wallet-registry"]
path = packages/wallet-registry/wallet-registry
url = [email protected]:cosmos/wallet-registry.git
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"store",
"vue",
"examples-vue3",
"nuxt"
"nuxt",
"wallet-registry"
]
}
33 changes: 33 additions & 0 deletions packages/wallet-registry/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"ignoredFiles": [
"{projectRoot}/vite.config.{js,ts,mjs,mts}",
"{projectRoot}/scripts/*.{js,ts,mjs,mts}"
]
}
]
}
}
]
}
11 changes: 11 additions & 0 deletions packages/wallet-registry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# wallet-registry

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build wallet-registry` to build the library.

## Running unit tests

Run `nx test wallet-registry` to execute the unit tests via [Jest](https://jestjs.io).
21 changes: 21 additions & 0 deletions packages/wallet-registry/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@nabla-studio/wallet-registry",
"repository": "nabla-studio/quirks",
"keywords": [
"blockchain",
"cosmos",
"cosmos-sdk",
"registry",
"osmosis",
"juno",
"desmos",
"evmos"
],
"version": "0.0.1",
"sideEffects": false,
"type": "module",
"dependencies": {},
"main": "./index.js",
"module": "./index.js",
"typings": "./index.d.ts"
}
65 changes: 65 additions & 0 deletions packages/wallet-registry/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"name": "wallet-registry",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/wallet-registry/src",
"projectType": "library",
"targets": {
"ts-gen": {
"command": "node tools/scripts/schema-wallet.mjs"
},
"data-gen": {
"command": "ts-node packages/wallet-registry/scripts/generate.mts -b packages/wallet-registry/tsconfig.scripts.json && eslint --fix packages/wallet-registry/src && prettier packages/wallet-registry/src --write"
},
"build": {
"executor": "@nx/vite:build",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/wallet-registry"
}
},
"test": {
"executor": "@nx/vite:test",
"outputs": ["{options.reportsDirectory}"],
"options": {
"passWithNoTests": true,
"reportsDirectory": "../../coverage/packages/wallet-registry"
}
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
"packages/wallet-registry/**/*.ts",
"packages/wallet-registry/package.json"
]
}
},
"version": {
"executor": "@jscutlery/semver:version",
"options": {
"preset": "conventional",
"tagPrefix": "{projectName}@",
"trackDeps": true,
"push": true,
"noVerify": true,
"postTargets": ["wallet-registry:github", "wallet-registry:npm"]
},
"dependsOn": ["^build"]
},
"github": {
"executor": "@jscutlery/semver:github",
"options": {
"tag": "{tag}",
"notes": "{notes}"
}
},
"npm": {
"executor": "ngx-deploy-npm:deploy",
"options": {
"access": "public"
}
}
},
"tags": []
}
32 changes: 32 additions & 0 deletions packages/wallet-registry/scripts/generate.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { mkdir, readFile, writeFile, rm } from 'fs/promises';
import { glob } from 'glob';
import { URL } from 'url';
import { processWallets } from './utils.mts';

const __dirname = new URL('../', import.meta.url).pathname;
const walletRegistryPath = `${__dirname}wallet-registry/`;
const walletsPath = `${__dirname}src/wallets`;

async function getFiles(path: string, ignore: string[] = []) {
const files = await glob(path, {
ignore: ignore.map((ignoredPath) => walletRegistryPath + ignoredPath),
withFileTypes: true,
});
return files;
}

const [wallets] = await Promise.all([
getFiles(`${walletRegistryPath}wallets/**/*.json`),
]);

await rm(walletsPath, { recursive: true, force: true });
await mkdir(walletsPath);

const walletsFiles = await processWallets(wallets, walletsPath);

await writeFile(
`${walletsPath}/index.ts`,
Array.from(walletsFiles.keys())
.map((chain) => `export * from './${chain}'`)
.join('\n'),
);
43 changes: 43 additions & 0 deletions packages/wallet-registry/scripts/utils.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { appendFile, readFile, writeFile } from 'fs/promises';
import { Path } from 'glob';
import camelCase from 'camelcase';

export function buildWalletName(originalChainName: string): string {
const startNumberRegex = /^\d+/;
const matches = startNumberRegex.exec(originalChainName);
const chainNameSuffix = matches != null ? matches[0] : '';
return originalChainName.replace(startNumberRegex, '') + chainNameSuffix;
}

export async function processWallets(wallets: Path[], outputPath: string) {
const walletDataMap = new Set();

for (const wallet of wallets) {
if (!wallet.parent) {
continue;
}

const chainName = buildWalletName(wallet.parent.name);

const data = await readFile(`${wallet.path}/${wallet.name}`, 'utf-8');
const filename = `${outputPath}/${chainName}.ts`;

if (!walletDataMap.has(chainName)) {
await writeFile(
filename,
`import type { CosmosWallet } from '../types'\n\n`,
);
}

let suffix = ': CosmosWallet';

await appendFile(
filename,
`export const ${camelCase(chainName)}${suffix} = ${data}\n\n`,
);

walletDataMap.add(chainName);
}

return walletDataMap;
}
2 changes: 2 additions & 0 deletions packages/wallet-registry/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './types';
export * from './wallets';
1 change: 1 addition & 0 deletions packages/wallet-registry/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './wallet';
93 changes: 93 additions & 0 deletions packages/wallet-registry/src/types/wallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* eslint-disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/

/**
* Cosmos Wallet.json is a metadata file that contains information about a wallet of a specific platform and which chains it supports, either natively or via custom client-side addition.
*/
export interface CosmosWallet {
$schema: string;
wallet_name: string;
pretty_name: string;
website?: string;
git_repo?: string;
supported_chains: string[];
features?: ('suggest_chain' | 'get_supported_chains' | 'icns')[];
platforms: {
device: 'mobile' | 'tablet' | 'desktop' | 'other';
type: 'application' | 'extension';
platform:
| 'chrome'
| 'firefox'
| 'ios'
| 'android'
| 'otherOS'
| 'otherBrowser';
install_link?: string;
}[];
images: {
png?: string;
svg?: string;
theme?: {
primary_color_hex?: string;
circle?: boolean;
dark_mode?: boolean;
};
/**
* logomark == icon only; logotype == text only; logo == icon + text.
*/
layout: 'logo' | 'logomark' | 'logotype';
/**
* Indicates in which position the text is placed, in case the layout is 'icon' type, it's required only in this case.
*/
text_position?: 'top' | 'bottom' | 'left' | 'right' | 'integrated';
}[];
wallet_connect?: {
/**
* define all the properties related to deeplink functionality.
*/
deeplink?: {
/**
* it is the path of the deelink URL that will trigger wallet connect actions within a mobile wallet.
*/
path?: {
ios?: string;
android?: string;
universal?: string;
};
};
};
mobile?: {
android?: {
/**
* The package name for your Android standalone app. You make it up, but it needs to be unique on the Play Store. See this [StackOverflow question](https://stackoverflow.com/questions/6273892/android-package-name-convention).
*/
package_name?: string;
/**
* Custom schema that provide a way to reference resources inside an app, documented [here](https://developer.android.com/training/app-links/deep-linking).
*/
schema?: string;
/**
* Universal schema for universal deeplink that provide a way to reference resources inside an app, documented [here](https://developer.android.com/training/app-links).
*/
universal_schema?: string;
};
ios?: {
/**
* The bundle identifier for your iOS standalone app. You make it up, but it needs to be unique on the App Store. See this [StackOverflow question](https://stackoverflow.com/questions/11347470/what-does-bundle-identifier-mean-in-an-ios-project).
*/
bundle_identifier?: string;
/**
* Custom URL schemes provide a way to reference resources inside an app, documented [here](https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app).
*/
schema?: string;
/**
* Universal schema for universal deeplink that provide a way to reference resources inside an app, documented [here](https://developer.apple.com/ios/universal-links/).
*/
universal_schema?: string;
};
};
}
Loading

0 comments on commit e7bf169

Please sign in to comment.