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

[PLA-1406] remove user account #48

Merged
merged 4 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
116 changes: 5 additions & 111 deletions resources/js/components/pages/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,14 @@
<LoadingCircle class="mt-40" :size="44" v-if="loading" />
<template v-else>
<div
v-if="!appStore.hasValidConfig && appStore.isMultiTenant"
v-if="!appStore.hasValidConfig && appStore.isMultiTenant && !tokens?.length"
class="flex flex-col mb-6 w-full transition-all rounded-md bg-[#0284c7] p-3 text-white"
>
<p class="font-bold">Initialization Guide</p>
<p>Please complete these steps in order to use the platform:</p>
<div v-if="!appStore.user?.account">1. Add a wallet account</div>
<div v-if="!tokens?.length">{{ appStore.user?.account ? '1.' : '2.' }} Create an API token</div>
<div>Create an API token</div>
</div>
<div class="flex flex-col space-y-8">
<div class="">
<h1 class="text-xl md:text-2xl">
Wallet Account
<span v-if="!appStore.loggedIn && !walletAccount" class="text-red-500">&nbsp;*</span>
</h1>
<p class="mt-1 text-sm text-gray-500 max-w-3xl">
The platform depends on there being a funded wallet daemon account setup and connected to
the platform and blockchain so it can receive transactions from the platform, sign them on
your behalf and then broadcast them to the network. You can get the latest version of the
wallet daemon from this repository:
<a href="https://github.com/enjin/wallet-daemon" target="_blank" class="text-primary">
https://github.com/enjin/wallet-daemon</a
>
and an overview can be found here:
<a
href="https://docs.enjin.io/enjin-platform/wallet-daemon"
target="_blank"
class="text-primary"
>
https://docs.enjin.io/enjin-platform/wallet-daemon</a
>
</p>
<div class="flex items-end space-x-4 mt-4">
<FormInput
v-model="walletAccount"
class="sm:w-[300px] flex-1 sm:flex-none"
:class="!enableAccountModify ? 'text-gray-400' : ''"
name="tokenName"
placeholder="Enter wallet account"
:disabled="!enableAccountModify"
/>
<Btn
v-if="appStore.isMultiTenant"
primary
class="py-2.5 disabled:!bg-primary"
@click="updateWalletAccount"
:disabled="updating"
>
<span v-if="!updating" class="truncate">
{{ enableAccountModify ? 'Update' : 'Update Account' }}
</span>
<LoadingCircle v-else class="w-4 h-4 text-white" />
</Btn>
</div>
</div>

<div v-if="appStore.isMultiTenant" class="flex flex-col space-y-4">
<div class="flex justify-between">
<h1 class="text-xl">
Expand Down Expand Up @@ -150,21 +103,16 @@ import snackbar from '~/util/snackbar';
import FormInput from '../FormInput.vue';
import { shortString, snackbarErrors } from '~/util';
import CopyTextIcon from '../CopyTextIcon.vue';
import { AuthApi } from '~/api/auth';
import { addressToPublicKey, isValidAddress, publicKeyToAddress } from '~/util/address';
import LoadingCircle from '../LoadingCircle.vue';

const router = useRouter();
const appStore = useAppStore();

const advancedMode = ref(appStore.advanced);
const tokenName = ref();
const walletAccount = ref(publicKeyToAddress(appStore.user?.account ?? appStore.config.daemon));
const enableTokenCreate = ref(false);
const enableAccountModify = ref(true);
const loading = ref(appStore.user || !appStore.hasMultiTenantPackage ? false : true);
const creating = ref(false);
const updating = ref(false);

const tokens = computed(() => appStore.user?.apiTokens);

Expand All @@ -189,40 +137,6 @@ const createApiToken = async () => {
}
};

const updateWalletAccount = async () => {
if (!enableAccountModify.value) {
enableAccountModify.value = true;
} else {
if (!walletAccount.value) {
return snackbar.error({ title: 'Account required', text: 'Please enter a wallet account.' });
} else if (addressToPublicKey(walletAccount.value) === appStore.user?.account) {
enableAccountModify.value = false;
return;
} else if (!isValidAddress(walletAccount.value)) {
return snackbar.error({ title: 'Invalid account', text: 'Please enter a valid wallet account.' });
}
try {
updating.value = true;
const res = await AuthApi.updateUser({ account: walletAccount.value });
enableAccountModify.value = false;
if (res.data.UpdateUser) {
appStore.user.account = walletAccount.value;
snackbar.info({
title: 'Account wallet updated',
text: `Your wallet account is set to ${walletAccount.value}`,
});
} else {
throw 'error';
}
} catch (e: any) {
if (snackbarErrors(e)) return;
snackbar.error({ title: 'Account wallet update failed', text: e.message });
} finally {
updating.value = false;
}
}
};

const revokeToken = async (name: string) => {
if (!name) return;
try {
Expand All @@ -245,15 +159,6 @@ const resetSettings = () => {
router.push({ name: 'platform.setup' });
};

(() => {
if (appStore.user?.account) {
walletAccount.value = publicKeyToAddress(appStore.user.account);
enableAccountModify.value = false;
} else if (!appStore.isMultiTenant) {
enableAccountModify.value = false;
}
})();

watch(
() => advancedMode.value,
() => {
Expand All @@ -265,25 +170,14 @@ watch(
}
);

watch(
() => appStore.user?.account,
(newAccount) => {
if (newAccount) {
enableAccountModify.value = false;
walletAccount.value = publicKeyToAddress(appStore.user?.account);
}

if (!appStore.user?.apiTokens?.length) {
enableTokenCreate.value = true;
}
}
);

watch(
() => appStore.user,
(userVal) => {
if (userVal) {
loading.value = false;
if (!appStore.user?.apiTokens?.length) {
enableTokenCreate.value = true;
}
}
}
);
Expand Down
1 change: 0 additions & 1 deletion resources/js/shims-vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ interface Window {
bootstrap: {
network: string;
url: string;
daemon: string;
name: string;
};
}
5 changes: 0 additions & 5 deletions resources/js/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const useAppStore = defineStore('app', {
tenant: false,
webSocket: '',
channel: '',
daemon: '',
},
navigations: [
{ name: 'Collections', to: { name: 'platform.collections' }, pos: 1 },
Expand Down Expand Up @@ -130,10 +129,6 @@ export const useAppStore = defineStore('app', {
this.config.channel = appConfig.channel;
}

if (window.bootstrap?.daemon) {
this.config.daemon = window.bootstrap.daemon;
}

if (window.bootstrap?.name) {
document.title = window.bootstrap.name;
}
Expand Down
16 changes: 0 additions & 16 deletions resources/js/store/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ 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';
import { useConnectionStore } from './connection';

const RPC_URLS = {
Expand Down Expand Up @@ -85,21 +84,6 @@ 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(useConnectionStore().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,
useConnectionStore().account.address,
Expand Down
1 change: 0 additions & 1 deletion resources/js/types/types.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ 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 @@ -15,7 +15,7 @@
<script>
global = globalThis
window.__dynamic_base__ = '/vendor/platform-ui/build';
window.bootstrap = { name: "{{ env('APP_NAME') }}", network: "{{ env('NETWORK') }}" , url: window.location.origin, daemon: "{{ Enjin\Platform\Support\Account::daemon()['public_key'] }}" }
window.bootstrap = { name: "{{ env('APP_NAME') }}", network: "{{ env('NETWORK') }}" , url: window.location.origin }
</script>

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