Skip to content

Commit 2a150c1

Browse files
authored
Merge pull request #38 from hypersign-protocol/diam
Diam
2 parents f866c6b + a41d0f7 commit 2a150c1

File tree

9 files changed

+490
-160
lines changed

9 files changed

+490
-160
lines changed

src/components/deploy-onchain-kyc-popup/deploy-kyc.vue

Lines changed: 190 additions & 84 deletions
Large diffs are not rendered by default.

src/components/deploy-onchain-kyc-popup/deploy-sbt.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ import { smartContractExecuteRPC } from '@hypersign-protocol/hypersign-kyc-chain
7070
import { smartContractQueryRPC } from '@hypersign-protocol/hypersign-kyc-chains-metadata/cosmos/contract/query'
7171
import { constructInitSbtMsg, constructGetRegistredSBTContractAddressMsg } from '@hypersign-protocol/hypersign-kyc-chains-metadata/cosmos/contract/msg';
7272
import { getCosmosChainConfig } from '@hypersign-protocol/hypersign-kyc-chains-metadata/cosmos/wallet/cosmos-wallet-utils'
73-
import { createNonSigningClient, calculateFee } from '../../utils/cosmos-client'
73+
import { createNonSigningClient, calculateFee } from '../../utils/wallet-client/cosmos-wallet-client'
7474
import UtilsMixin from '../../mixins/utils'
75-
import ConnectWalletButton from "../element/authButtons/ConnectWalletButton.vue";
75+
import ConnectWalletButton from "../element/authButtons/ConnectWalletButtonKeplr.vue";
7676
7777
export default {
7878
name: 'DeploySbt',
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<template>
2+
<div>
3+
<button type="button" class="btn btn-outline-dark btn-lg mb-2" style="width: 100%;" @click="connectWallet()"
4+
:disabled="isDisable || !ifDiamInstalled">
5+
<span><b-avatar :src="getChainDetail().logoUrl" size="30"></b-avatar> Connect DIAM Wallet</span>
6+
7+
8+
9+
</button>
10+
<small style="color:indianred; text-decoration: underline;" v-if="!ifDiamInstalled"><a
11+
href="https://chromewebstore.google.com/detail/diam-wallet/oakkognifoojdbfjaccegangippipdmn?hl=en"
12+
target="_blank">DIAM Wallet extention</a> not installed in your browser</small>
13+
</div>
14+
</template>
15+
<script>
16+
import { mapMutations } from "vuex";
17+
// import { getUserAddressFromOfflineSigner } from '@hypersign-protocol/hypersign-kyc-chains-metadata/cosmos/wallet/cosmos-wallet-utils'
18+
// import { createClient, createNonSigningClient } from '../../../utils/wallet-client/cosmos-wallet-client'
19+
import { getStellarCoinLogo, getStellarChainConfig } from '@hypersign-protocol/hypersign-kyc-chains-metadata/stellar/wallet/stellar-wallet-utils'
20+
import Config from '../../../config';
21+
22+
export default {
23+
props: {
24+
isDisable: {
25+
type: Boolean,
26+
default: false
27+
},
28+
ecosystem: {
29+
type: String,
30+
default: "cosmos"
31+
},
32+
blockchain: {
33+
type: String,
34+
default: "nibiru"
35+
},
36+
chainId: {
37+
type: String,
38+
default: "nibiru-localnet-0"
39+
}
40+
},
41+
computed: {
42+
blockchainlabel() {
43+
return `${this.ecosystem}:${this.blockchain}:${this.chainId}`
44+
},
45+
selectedBlockchainLogo() {
46+
return getStellarCoinLogo(this.blockchainlabel)
47+
},
48+
ifDiamInstalled() {
49+
return window.diam ? true : false;
50+
},
51+
52+
53+
},
54+
methods: {
55+
...mapMutations("walletStore", ['setCosmosConnection', 'setBlockchainUser']),
56+
getChainDetail() {
57+
console.log(this.blockchainlabel)
58+
const config = getStellarChainConfig(this.blockchainlabel)
59+
console.log(config.stakeCurrency.coinImageUrl)
60+
return {
61+
chainName: config.chainName,
62+
chainId: config.chainId,
63+
logoUrl: config.stakeCurrency.coinImageUrl,
64+
tx_explorer: config.txExplorer.txUrl
65+
}
66+
},
67+
async getSigningClient(chainId) {
68+
return (xdr) => {
69+
if (!window.diam) {
70+
throw new Error('DIAM Wallet not installed')
71+
}
72+
return window.diam.sign(xdr, true, chainId)
73+
}
74+
},
75+
async connectWallet() {
76+
77+
console.log('connectWallet() called...')
78+
79+
// const { default: SupportedChains } = await import(`@hypersign-protocol/hypersign-kyc-chains-metadata/${this.ecosystem}/wallet/${this.blockchain}/${this.chainId}/chains`)
80+
81+
// if (!SupportedChains) {
82+
// throw new Error('Ecosysem or blockchain is not supported')
83+
// }
84+
85+
// const requestedChainId = this.chainId// this.getOnChainIssuerConfig.chainId
86+
// const chainConfig = SupportedChains.find(x => x.chainId == requestedChainId);
87+
// if (!chainConfig) {
88+
// throw new Error('Chain not supported for chainId requestedChainId ' + requestedChainId)
89+
// }
90+
91+
// const chainId = chainConfig["chainId"];
92+
93+
94+
if (!window.diam) {
95+
throw new Error("Please install the DIAM wallet extension");
96+
}
97+
98+
const result = await window.diam.connect()
99+
if (result && result.status == 404) {
100+
throw new Error(result.message)
101+
}
102+
103+
const walletAddress = result.walletAddress ? result.walletAddress : result.message[0].diamPublicKey;
104+
console.log({
105+
walletAddress,
106+
result
107+
})
108+
109+
if (!walletAddress) {
110+
throw new Error('No wallet address found')
111+
}
112+
113+
// await window.keplr.enable(chainId);
114+
// const offlineSigner = window.getOfflineSigner(chainId)
115+
// const userAddress = await getUserAddressFromOfflineSigner(offlineSigner);
116+
// console.log("User Address: ", userAddress)
117+
118+
if (walletAddress != "") {
119+
// const chainRPC = chainConfig["rpc"]
120+
121+
// const chainId = "Diamante Testnet 2024"
122+
// const chainId = "testnet"
123+
// window.diam
124+
// .sign(xdr, true, "Diamante Testnet 2024")
125+
console.log({
126+
chainId: this.chainId
127+
})
128+
const signingClient = await this.getSigningClient(this.chainId); // createClient(chainRPC, offlineSigner);
129+
const nonSigningClient = await this.getSigningClient(this.chainId);
130+
131+
// console.log(signingClient)
132+
/// Usage...
133+
// await signingClient('AAAAAgAAAADnQe1c0mPWMcsias/JKXj9+LOaN6TpSSmer+tM9L9YIgAAArwAEF6hAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcAAAABAAAAAARrgWTah39cp1XFq8V9twPrO4cbtwlEQRH9c5tVfEVdAAAAAQAAAADnQe1c0mPWMcsias/JKXj9+LOaN6TpSSmer+tM9L9YIgAAAAAAAAAAAAACWAAAAAEAAAAA50HtXNJj1jHLImrPySl4/fizmjek6Ukpnq/rTPS/WCIAAAAAAAAAADZihU/1kaxP59KjPQQFdIVYlloceck0k6CfwMOmRAldAAAAAAAAAAoAAAABAAAAAARrgWTah39cp1XFq8V9twPrO4cbtwlEQRH9c5tVfEVdAAAABgAAAAJreWNBc3NldAAAAAAAAAAANmKFT/WRrE/n0qM9BAV0hViWWhx5yTSToJ/Aw6ZECV1//////////wAAAAEAAAAABGuBZNqHf1ynVcWrxX23A+s7hxu3CURBEf1zm1V8RV0AAAAGAAAAAmt5Y0Fzc2V0AAAAAAAAAAA2YoVP9ZGsT+fSoz0EBXSFWJZaHHnJNJOgn8DDpkQJXX//////////AAAAAQAAAAA2YoVP9ZGsT+fSoz0EBXSFWJZaHHnJNJOgn8DDpkQJXQAAAAoAAAAIa3ljQXNzZXQAAAABAAAADkVuY3J5cHRlZCBkYXRhAAAAAAABAAAAADZihU/1kaxP59KjPQQFdIVYlloceck0k6CfwMOmRAldAAAAAQAAAAAEa4Fk2od/XKdVxavFfbcD6zuHG7cJREER/XObVXxFXQAAAAJreWNBc3NldAAAAAAAAAAANmKFT/WRrE/n0qM9BAV0hViWWhx5yTSToJ/Aw6ZECV0AAAAAAAAAAQAAAAEAAAAANmKFT/WRrE/n0qM9BAV0hViWWhx5yTSToJ/Aw6ZECV0AAAAFAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC9L9YIgAAAEDh7+7E103vH3o+uLOwzWw0IjU3Fs/MG9m+mEczwklASYFlENeBRsq53fbW1N6CkYEBnpbZd24P7sTh5eRKNpsMpkQJXQAAAEDc/YdrP5x9lF4DPTDXtRHYZ7Z5kqxtnzc4bp5rxaUYypjc0bO8NwAzPcEJKnrPI9D4ANDgCxlNevUbUU2xeYIM')
134+
135+
this.setCosmosConnection({
136+
signingClient,
137+
nonSigningClient,
138+
offlineSigner: null,
139+
})
140+
141+
this.setBlockchainUser({
142+
walletAddress: walletAddress,
143+
chainId: this.chainId,
144+
ecosystem: this.ecosystem,
145+
blockchain: this.blockchain
146+
})
147+
148+
this.$emit('authEvent', {
149+
provider: Config.AUTH_PROVIDERS.STELLAR,
150+
user: {
151+
walletAddress: walletAddress
152+
},
153+
status: 'success'
154+
})
155+
}
156+
157+
}
158+
}
159+
160+
}
161+
162+
163+
</script>

src/components/element/authButtons/ConnectWalletButton.vue renamed to src/components/element/authButtons/ConnectWalletButtonKeplr.vue

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@
1010
<script>
1111
import { mapMutations } from "vuex";
1212
import { getUserAddressFromOfflineSigner } from '@hypersign-protocol/hypersign-kyc-chains-metadata/cosmos/wallet/cosmos-wallet-utils'
13-
import { createClient, createNonSigningClient } from '../../../utils/cosmos-client'
13+
import { createClient, createNonSigningClient } from '../../../utils/wallet-client/cosmos-wallet-client'
1414
import { getCosmosCoinLogo } from '@hypersign-protocol/hypersign-kyc-chains-metadata/cosmos/wallet/cosmos-wallet-utils'
15-
export const AUTH_PROVIDERS = Object.freeze({
16-
GOOGLE: 'google',
17-
KEPLR: 'keplr',
18-
METAMASK: 'metamask',
19-
})
15+
import Config from '../../../config';
2016
2117
export default {
2218
props: {
@@ -99,7 +95,7 @@ export default {
9995
})
10096
10197
this.$emit('authEvent', {
102-
provider: AUTH_PROVIDERS.KEPLR,
98+
provider: Config.AUTH_PROVIDERS.KEPLR,
10399
user: {
104100
walletAddress: userAddress
105101
},

src/config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,10 @@ config['GRANT_TYPES_ENUM'] = Object.freeze({
7373
'CAVACH_API': 'access_service_kyc'
7474
})
7575

76+
config['AUTH_PROVIDERS'] = Object.freeze({
77+
GOOGLE: 'google',
78+
KEPLR: 'keplr',
79+
METAMASK: 'metamask',
80+
})
81+
7682
export default config

src/store/mainStore.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ const mainStore = {
836836
return reject(new Error('Tenant url is null or empty, service is not selected'))
837837
}
838838
const url = `${sanitizeUrl(getters.getSelectedService.tenantUrl)}/api/v1/e-kyc/verification/onchainkyc-config`;
839-
// const url = `http://localhost:3001/api/v1/e-kyc/verification/onchainkyc-config`
839+
//const url = `http://localhost:3001/api/v1/e-kyc/verification/onchainkyc-config`
840840
const authToken = getters.getSelectedService.access_token
841841
const headers = UtilsMixin.methods.getHeader(authToken);
842842
fetch(url, {
@@ -1022,6 +1022,33 @@ const mainStore = {
10221022
})
10231023
},
10241024

1025+
createMasterWallet: ({ getters }, payload) => {
1026+
return new Promise((resolve, reject) => {
1027+
if (!getters.getSelectedService || !getters.getSelectedService.tenantUrl) {
1028+
return reject(new Error('Tenant url is null or empty, service is not selected'))
1029+
}
1030+
const url = `${sanitizeUrl(getters.getSelectedService.tenantUrl)}/api/v1/wallet`;
1031+
// const url = `http://localhost:3001/api/v1/wallet`
1032+
const authToken = getters.getSelectedService.access_token
1033+
const headers = UtilsMixin.methods.getHeader(authToken);
1034+
1035+
fetch(url, {
1036+
method: 'POST',
1037+
headers,
1038+
body: JSON.stringify(payload)
1039+
}).then(response => response.json())
1040+
.then(json => {
1041+
if (json.error) {
1042+
return reject(new Error(json.error.details.join(' ')))
1043+
}
1044+
// commit('setWebhookConfig', json.data);
1045+
resolve(json.data)
1046+
}).catch((e) => {
1047+
return reject(`Error while fetching apps ` + e.message);
1048+
})
1049+
})
1050+
},
1051+
10251052
fetchAppWebhookConfig: ({ commit, getters }) => {
10261053
return new Promise((resolve, reject) => {
10271054
if (!getters.getSelectedService || !getters.getSelectedService.tenantUrl) {
@@ -1171,8 +1198,6 @@ const mainStore = {
11711198
},
11721199

11731200
// - KYC Credit
1174-
1175-
11761201
async fetchKYCCredits({ getters, commit }) {
11771202

11781203
if (!getters.getSelectedService || !getters.getSelectedService.tenantUrl) {

src/utils/cosmos-client.js renamed to src/utils/wallet-client/cosmos-wallet-client.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// import { SigningCosmWasmClient, CosmWasmClient } from '@cosmjs/cosmwasm-stargate'
2-
31
import { Uint53 } from "@cosmjs/math";
42
import {
53
GasPrice, coins

src/views/playground/OnChainKycSystems.vue

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,10 @@ h5 span {
172172
<tr v-for="row in onchainconfigs" :key="row._id">
173173
<td>
174174
<span>
175-
176-
<b-avatar :src="getChainDetail(row.blockchainLabel).logoUrl" size="30"></b-avatar>
177-
<!-- <img :src="getChainDetail(row.blockchainLabel).logoUrl" width="20" height="20"> -->
175+
<b-avatar badge-top badge-offset="-2px" :src="getChainDetail(row.blockchainLabel).logoUrl" size="30">
176+
<template #badge v-if="getChainDetail(row.blockchainLabel).chainName.indexOf('test') < 0"><b-icon
177+
icon="star-fill"></b-icon></template>
178+
</b-avatar>
178179
</span>
179180
{{ getChainDetail(row.blockchainLabel).chainName }}
180181
</td>
@@ -227,6 +228,7 @@ import HfButtons from "../../components/element/HfButtons.vue"
227228
import StudioSideBar from "../../components/element/StudioSideBar.vue";
228229
import DeployOnChainKYC from "../../components/deploy-onchain-kyc-popup/deploy.vue";
229230
import { getCosmosChainConfig } from '@hypersign-protocol/hypersign-kyc-chains-metadata/cosmos/wallet/cosmos-wallet-utils'
231+
import { getStellarChainConfig } from '@hypersign-protocol/hypersign-kyc-chains-metadata/stellar/wallet/stellar-wallet-utils'
230232
import HFBeta from '../../components/element/HFBeta.vue';
231233
import { mapState, mapActions, mapMutations } from "vuex";
232234
@@ -314,7 +316,16 @@ export default {
314316
this.$root.$emit("bv::toggle::collapse", "sidebar-right");
315317
},
316318
getChainDetail(blockchainlabel = 'cosmos:comdex:test') {
317-
const config = getCosmosChainConfig(blockchainlabel)
319+
let config;
320+
if (blockchainlabel.indexOf('cosmos') >= 0) {
321+
config = getCosmosChainConfig(blockchainlabel)
322+
} else {
323+
console.log({
324+
blockchainlabel
325+
})
326+
config = getStellarChainConfig(blockchainlabel)
327+
}
328+
318329
return {
319330
chainName: config.chainName,
320331
chainId: config.chainId,

0 commit comments

Comments
 (0)