This commit is contained in:
alexandermake 2025-05-07 19:49:59 +03:00
commit 5acc24e730
17 changed files with 8294 additions and 0 deletions

5
.editorconfig Normal file
View File

@ -0,0 +1,5 @@
[*.{js,jsx,ts,tsx,vue}]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true

23
.eslintrc.cjs Normal file
View File

@ -0,0 +1,23 @@
/* eslint-env node */
require("@rushstack/eslint-patch/modern-module-resolution");
module.exports = {
root: true,
extends: [
"plugin:vue/vue3-essential",
"eslint:recommended",
"@vue/eslint-config-typescript",
"@vue/eslint-config-prettier/skip-formatting"
],
overrides: [
{
files: ["cypress/e2e/**/*.{cy,spec}.{js,ts,jsx,tsx}", "cypress/support/**/*.{js,ts,jsx,tsx}"]
}
],
parserOptions: {
ecmaVersion: "latest"
},
rules: {
"vue/multi-word-component-names": "off"
}
};

28
.gitignore vendored Normal file
View File

@ -0,0 +1,28 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
.yarn
yarn.lock
node_modules
.DS_Store
dist
dist-ssr
coverage
*.local
# Editor directories and files
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
*.tsbuildinfo
vite.config.ts.timestamp-*.mjs

4
.husky/pre-commit Normal file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npm run lint

9
.prettierrc.json Normal file
View File

@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"semi": true,
"tabWidth": 2,
"singleQuote": false,
"singleAttributePerLine": true,
"printWidth": 120,
"trailingComma": "none"
}

3
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"recommendations": ["EditorConfig.EditorConfig", "Vue.volar", "esbenp.prettier-vscode"]
}

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"editor.formatOnSave": true
}

2
env.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
/// <reference types="vite/client" />
/// <reference types="vite-svg-loader" />

35
index.html Normal file
View File

@ -0,0 +1,35 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<meta
name="mobile-web-app-capable"
content="yes"
/>
<title>title</title>
</head>
<script type="text/javascript">
const vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty("--vh", `${vh}px`);
window.addEventListener("resize", () => {
const vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty("--vh", `${vh}px`);
});
</script>
<body>
<div id="app"></div>
<noscript>
<strong> no script</strong>
</noscript>
<script
type="module"
src="/src/main.ts"
></script>
</body>
</html>

7934
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

38
package.json Normal file
View File

@ -0,0 +1,38 @@
{
"name": "test",
"license": "Apache-2.0",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"serve": "vite --port 8080 --mode serve --host"
},
"dependencies": {
"@walletconnect/sign-client": "^2.20.2",
"cosmjs-types": "^0.9.0",
"vue": "^3.5.13"
},
"devDependencies": {
"@tsconfig/node20": "^20.1.4",
"@types/jsdom": "^21.1.6",
"@types/node": "^22.8.6",
"@vitejs/plugin-vue": "^5.2.3",
"@vue/eslint-config-prettier": "^9.0.0",
"@vue/eslint-config-typescript": "^13.0.0",
"@vue/test-utils": "^2.4.6",
"@vue/tsconfig": "^0.7.0",
"buffer": "^6.0.3",
"eslint": "^8.57.0",
"eslint-plugin-vue": "^9.30.0",
"husky": "^9.1.6",
"npm-run-all2": "^7.0.1",
"prettier": "^3.4.2",
"start-server-and-test": "^2.0.9",
"typescript": "~5.6.3",
"vite": "^5.4.15",
"vite-plugin-node-polyfills": "^0.23.0",
"vite-svg-loader": "^5.1.0",
"vitest": "^2.1.4",
"vue-tsc": "^2.2.8"
}
}

123
src/App.vue Normal file
View File

@ -0,0 +1,123 @@
<template>
<button @click="connectWithWalletConnect">Test connection</button>
<img
v-if="src"
:src="src"
width="300"
height="300"
/>
</template>
<script lang="ts" setup>
import SignClient from "@walletconnect/sign-client";
import { computed, ref } from "vue";
import { Buffer } from "buffer";
let client: SignClient | undefined;
const uriRef = ref("");
const src = computed(() =>
uriRef.value.length == 0 ? null : `https://api.aentre.com/qrcode?data=${Buffer.from(uriRef.value).toString("base64")}`
);
async function getClient(): Promise<SignClient> {
if (!client) {
const data = await SignClient.init({
projectId: "ecb32ae5d92fe5e22e9cdc69d0c5b5c0",
metadata: {
name: "Project",
description: "Description",
url: window.location.origin,
icons: []
}
});
data.on("session_connect", (...args) => {
console.log("session_connect", args);
});
client = data;
}
return client!;
}
async function connectWithWalletConnect() {
try {
const chainId = "pirin-1";
const signClient = await getClient();
await signClient.auth.init();
await signClient.session.init();
signClient.on("session_request", (...args) => console.log(args));
let existingPairing = signClient.session.getAll().at(-1);
let session;
if (!existingPairing) {
const { uri, approval } = await signClient.connect({
requiredNamespaces: {
cosmos: {
methods: [
"cosmos_getAccounts",
"cosmos_signDirect",
"cosmos_signAmino",
"keplr_getKey",
"keplr_signAmino",
"keplr_signDirect",
"keplr_signArbitrary",
"keplr_enable",
"keplr_signEthereum",
"keplr_experimentalSuggestChain",
"keplr_suggestToken"
],
chains: [`cosmos:${chainId}`, "cosmos:osmosis-1"],
events: ["accountsChanged", "chainChanged", "keplr_accountsChanged"]
}
}
});
console.log(uri);
uriRef.value = uri!;
session = await approval();
} else {
// const { uri, approval } = await signClient.connect({
// pairingTopic: existingPairing.pairingTopic,
// sessionProperties: existingPairing.sessionProperties,
// topic: existingPairing.topic,
// requiredNamespaces: {
// cosmos: {
// methods: [
// "cosmos_getAccounts",
// "cosmos_signDirect",
// "cosmos_signAmino",
// "keplr_getKey",
// "keplr_signAmino",
// "keplr_signDirect",
// "keplr_signArbitrary",
// "keplr_enable",
// "keplr_signEthereum",
// "keplr_experimentalSuggestChain",
// "keplr_suggestToken"
// ],
// chains: [`cosmos:${chainId}`, "cosmos:osmosis-1"],
// events: ["accountsChanged", "chainChanged", "keplr_accountsChanged"]
// }
// }
// });
// session = await approval();
session = existingPairing;
}
console.log("enter");
const result = await signClient.request({
topic: session!.topic,
chainId: `cosmos:${chainId}`,
request: {
method: "cosmos_getAccounts",
params: {}
}
});
console.log(result);
} catch (e) {
console.log(e);
}
}
</script>

6
src/main.ts Normal file
View File

@ -0,0 +1,6 @@
import { createApp } from "vue";
import App from "@/App.vue";
const app = createApp(App);
app.mount("#app");

17
tsconfig.app.json Normal file
View File

@ -0,0 +1,17 @@
{
"extends": "@vue/tsconfig/tsconfig.dom.json",
"include": ["env.d.ts", "src/**/*.ts", "src/**/*", "src/**/*.vue"],
"exclude": ["src/**/__tests__/*", "node_modules"],
"compilerOptions": {
"composite": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"declaration": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"types": ["@intlify/unplugin-vue-i18n/messages"],
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}

14
tsconfig.json Normal file
View File

@ -0,0 +1,14 @@
{
"files": [],
"references": [
{
"path": "./tsconfig.node.json"
},
{
"path": "./tsconfig.app.json"
}
],
"compilerOptions": {
"module": "NodeNext"
}
}

13
tsconfig.node.json Normal file
View File

@ -0,0 +1,13 @@
{
"extends": "@tsconfig/node20/tsconfig.json",
"include": ["vite.config.*", "vitest.config.*", "cypress.config.*", "nightwatch.conf.*", "playwright.config.*"],
"compilerOptions": {
"composite": true,
"noEmit": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"module": "ESNext",
"moduleResolution": "Bundler",
"types": ["node"]
}
}

37
vite.config.ts Normal file
View File

@ -0,0 +1,37 @@
import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";
import { nodePolyfills } from "vite-plugin-node-polyfills";
import vue from "@vitejs/plugin-vue";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
nodePolyfills({
include: ["stream", "util", "crypto"],
exclude: ["http"],
globals: {
Buffer: true,
global: true,
process: true
}
})
],
server: {
host: "127.0.0.1"
},
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url))
}
},
optimizeDeps: {
exclude: [],
esbuildOptions: {
sourcemap: false,
define: {
global: "globalThis"
}
}
}
});