Skip to content

Commit

Permalink
add sign with WC
Browse files Browse the repository at this point in the history
  • Loading branch information
zlayine committed Oct 10, 2023
1 parent cec39e4 commit fb56f6c
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 29 deletions.
136 changes: 111 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@vuepic/vue-datepicker": "^5.3.0",
"@vueuse/core": "^10.2.0",
"@walletconnect/modal-sign-html": "^2.6.0",
"@walletconnect/sign-client": "^2.10.2",
"@web3modal/html": "^2.7.0",
"eslint-plugin-import": "^2.27.5",
"eventemitter3": "^5.0.0",
Expand Down
4 changes: 2 additions & 2 deletions resources/js/components/SignTransaction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</span>
</div>
</div>
<div v-if="!useAppStore().accounts.length" class="text-center">
<div v-if="!useAppStore().accounts?.length" class="text-center">
<span class="text-sm text-gray-500"> No accounts found. Please connect your wallet. </span>
</div>
</div>
Expand Down Expand Up @@ -94,7 +94,7 @@ const closeModal = () => {
const selectAccount = async (account) => {
try {
isLoading.value = true;
appStore.setAccount(account);
await appStore.setAccount(account);
showAccountsModal.value = false;
const res = await transactionStore.signTransaction(props.transaction);
if (res) {
Expand Down
34 changes: 32 additions & 2 deletions resources/js/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ import { CollectionApi } from '~/api/collection';
import { WalletConnectModalSign } from '@walletconnect/modal-sign-html';
import { wcOptions } from '~/util';
import { wcRequiredNamespaces } from '~/util';
import { getSdkError } from '@walletconnect/utils';
import { getAppMetadata, getSdkError } from '@walletconnect/utils';
import { PolkadotjsWallet, Wallet } from '@talismn/connect-wallets';
import SignClient from '@walletconnect/sign-client';
import { HexString } from '@polkadot/util/types';

const parseConfigURL = (url: string): URL => {
return new URL(url);
};

const initWC2Client = async () => {
return SignClient.init({
projectId: 'a4b92f550ab3039f7e084a879882bc96',
metadata: getAppMetadata(),
});
};

export const useAppStore = defineStore('app', {
state: (): AppState => ({
url: undefined,
Expand Down Expand Up @@ -318,7 +327,28 @@ export const useAppStore = defineStore('app', {
this.provider = '';
}
},
setAccount(account: Wallet) {
async setAccount(account: Wallet) {
if (this.provider === 'wc') {
const signClient = await initWC2Client();
const session = await this.getSession();
account.signer = {
signPayload: async (payload: any) => {
const result = await signClient!.request<{ signature: HexString }>({
chainId: 'polkadot:3af4ff48ec76d2efc8476730f423ac07',
topic: session?.topic,
request: {
method: 'polkadot_signTransaction',
params: {
address: payload.address,
transactionPayload: payload,
},
},
});

return result;
},
};
}
this.account = account;
},
async getAccounts() {
Expand Down

0 comments on commit fb56f6c

Please sign in to comment.