|
| 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> |
0 commit comments