Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add error for signing transaction with different address #31

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion resources/js/shims-vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ declare module '*.vue' {

interface Window {
bootstrap: {
hostname: string;
url: string;
daemon: string;
};
}
11 changes: 8 additions & 3 deletions resources/js/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const useAppStore = defineStore('app', {
tenant: false,
webSocket: '',
channel: '',
daemon: '',
},
navigations: [
{ name: 'Collections', to: { name: 'platform.collections' }, pos: 1 },
Expand Down Expand Up @@ -77,7 +78,7 @@ export const useAppStore = defineStore('app', {
if (this.hasMarketplacePackage) this.addMarketplaceNavigation();

this.loggedIn = true;
if (this.isMultiTenant && this.loggedIn) await this.getUser();
if (this.loggedIn) await this.getUser();

return await this.fetchCollectionIds();
} catch (error: any) {
Expand All @@ -101,8 +102,8 @@ export const useAppStore = defineStore('app', {

if (appConfig?.url) {
this.config.url = parseConfigURL(appConfig.url);
} else if (window?.bootstrap?.hostname) {
this.config.url = parseConfigURL(window.location.origin);
} else if (window?.bootstrap?.url) {
this.config.url = parseConfigURL(window?.bootstrap?.url);
} else {
this.config.url = this.url;
}
Expand All @@ -119,6 +120,10 @@ export const useAppStore = defineStore('app', {
if (appConfig.channel.length) {
this.config.channel = appConfig.channel;
}

if (window.bootstrap.daemon) {
this.config.daemon = window.bootstrap.daemon;
}
},
async checkURL(url: URL) {
try {
Expand Down
24 changes: 20 additions & 4 deletions resources/js/store/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import snackbar from '~/util/snackbar';
import { SignerPayloadJSON } from '@polkadot/types/types';
import { markRaw } from 'vue';
import { AccountInfoWithTripleRefCount } from '@polkadot/types/interfaces';
import { publicKeyToAddress } from '~/util/address';

const RPC_URLS = {
canary: 'wss://rpc.matrix.canary.enjin.io',
Expand Down Expand Up @@ -79,22 +80,37 @@ export const useTransactionStore = defineStore('transaction', {
return paymentInfo.partialFee.toHuman();
},
async signTransaction(transaction: any) {
const appStore = useAppStore();
if (appStore.user?.account || appStore.config.daemon) {
if (
publicKeyToAddress(appStore.account.address) !==
publicKeyToAddress(appStore.user?.account ?? appStore.config.daemon)
) {
snackbar.error({
title: 'Sign Transaction',
text: 'Signing account must be the same as wallet daemon account',
});

return;
}
}

const { extrinsic, payloadToSign, currentBlock } = await this.getExtrinsicData(
transaction,
useAppStore().account.address,
appStore.account.address,
this.api
);

const { signature } = await useAppStore().account.signer.signPayload(payloadToSign);
const { signature } = await appStore.account.signer.signPayload(payloadToSign);

extrinsic.addSignature(useAppStore().account.address, signature, payloadToSign);
extrinsic.addSignature(appStore.account.address, signature, payloadToSign);

const transactionHash = await this.api.rpc.author.submitExtrinsic(extrinsic.toHex());

return await this.updateTransaction({
id: transaction.id,
transactionHash: transactionHash.toHex(),
signingAccount: useAppStore().account.address,
signingAccount: appStore.account.address,
signedAtBlock: currentBlock.block.header.number.toNumber(),
});
},
Expand Down
1 change: 1 addition & 0 deletions resources/js/types/types.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface AppState {
tenant: boolean;
webSocket: string;
channel: string;
daemon: string;
};
navigations: any[];
collections: string[];
Expand Down
2 changes: 1 addition & 1 deletion resources/views/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<script>
global = globalThis
window.__dynamic_base__ = '/vendor/platform-ui/build';
window.bootstrap = { hostname: window.location.hostname }
window.bootstrap = { url: window.location.origin, daemon: "{{ Enjin\Platform\Support\Account::daemon()['public_key'] }}" }
</script>

@vite('resources/js/app.ts', 'vendor/platform-ui/build')
Expand Down
Loading