Skip to content

Commit

Permalink
[PLA-1406] remove user account (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
zlayine authored Nov 7, 2023
1 parent bde1bd4 commit 27c20ff
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 167 deletions.
12 changes: 0 additions & 12 deletions resources/js/api/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,4 @@ export class AuthApi {

return AuthApi.sendPlatfromRequest(data);
}

static async updateUser({ email, account }: { email?: string; account?: string }) {
const data = {
query: mutations.UpdateUser,
variables: {
email,
account,
},
};

return AuthApi.sendPlatfromRequest(data);
}
}
2 changes: 0 additions & 2 deletions resources/js/api/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import ResetPassword from '~/graphql/mutation/auth/ResetPassword';
import RequestPasswordReset from '~/graphql/mutation/auth/RequestPasswordReset';
import CreateApiToken from '~/graphql/mutation/auth/CreateApiToken';
import RevokeApiTokens from '~/graphql/mutation/auth/RevokeApiTokens';
import UpdateUser from '~/graphql/mutation/auth/UpdateUser';

import AddAccount from '~/graphql/mutation/fueltank/AddAccount';
import RemoveAccount from '~/graphql/mutation/fueltank/RemoveAccount';
Expand Down Expand Up @@ -102,7 +101,6 @@ export default {
RequestPasswordReset,
CreateApiToken,
RevokeApiTokens,
UpdateUser,

AddAccount,
RemoveAccount,
Expand Down
9 changes: 0 additions & 9 deletions resources/js/components/ProfileMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@
{{ appStore.user.email }}
</p>
</div>
<div class="px-4 py-2" v-if="appStore.user">
<p class="text-sm text-gray-500">Account</p>
<Address
class="truncate text-sm font-medium text-gray-900"
short
:address="appStore.user?.account"
/>
</div>
<div class="px-4 py-2" v-if="appStore.config.url">
<p class="text-sm text-gray-500">URL</p>
<p class="truncate text-sm font-medium text-gray-900">
Expand Down Expand Up @@ -84,7 +76,6 @@ import { useAppStore } from '~/store';
import { Cog6ToothIcon } from '@heroicons/vue/24/outline';
import { useRouter } from 'vue-router';
import Tooltip from './Tooltip.vue';
import Address from './Address.vue';
const appStore = useAppStore();
const router = useRouter();
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/batch/forms/BatchMintForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ const mintTypes = [
},
];
const formRef = ref();
const account = ref(publicKeyToAddress(props.modelValue.account ?? appStore.user?.account) ?? '');
const account = ref(publicKeyToAddress(props.modelValue.account ?? '') ?? '');
const createTokenId: Ref<TokenIdType> = ref(
parseFormatedTokenId(props.modelValue.createParams?.tokenId ?? null) ?? {
tokenId: '',
Expand Down
13 changes: 13 additions & 0 deletions resources/js/components/pages/Collections.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ import NoItems from '~/components/NoItems.vue';
import { snackbarErrors } from '~/util';
import Btn from '~/components/Btn.vue';
import { TransactionState } from '~/types/types.enums';
import { useRoute, useRouter } from 'vue-router';

const isLoading = ref(true);
const isPaginationLoading = ref(false);
Expand All @@ -135,6 +136,9 @@ const modalSlide = ref(false);
const slideComponent = ref();
const searchInput = ref('');

const route = useRoute();
const router = useRouter();

const enablePagination = computed(() => searchInput.value === '');

const actions = [
Expand Down Expand Up @@ -297,6 +301,15 @@ onMounted(() => {
events.on('transaction', openTransactionSlide);
});

watch(
() => useAppStore().user,
() => {
if (useAppStore().isMultiTenant && !useAppStore().hasValidConfig && route.meta.requiresToken) {
router.push({ name: 'platform.user.settings' });
}
}
);

watch(() => collections.value, setCollectionIds);
</script>

Expand Down
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
2 changes: 1 addition & 1 deletion resources/js/components/pages/create/CreateListing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ const router = useRouter();
const appStore = useAppStore();
const isLoading = ref(false);
const account = ref(appStore.user?.account);
const account = ref();
const amount = ref('');
const price = ref('');
const salt = ref('');
Expand Down
4 changes: 2 additions & 2 deletions resources/js/components/pages/create/CreateToken.vue
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ import snackbar from '~/util/snackbar';
import { useRouter } from 'vue-router';
import FormInput from '~/components/FormInput.vue';
import FormCheckbox from '~/components/FormCheckbox.vue';
import { addressToPublicKey, publicKeyToAddress } from '~/util/address';
import { addressToPublicKey } from '~/util/address';
import { currencySymbolByNetwork, formatData, formatPriceToENJ, formatToken, snackbarErrors } from '~/util';
import { TokenCapType, TokenIdSelectType } from '~/types/types.enums';
import FormList from '~/components/FormList.vue';
Expand All @@ -253,7 +253,7 @@ const currencySymbol = computed(() => currencySymbolByNetwork(appStore.config.ne
const isLoading = ref(false);
const collectionId = ref('');
const recipient = ref(publicKeyToAddress(appStore.user?.account));
const recipient = ref();
const tokenId = ref({
tokenId: '',
tokenType: TokenIdSelectType.Integer,
Expand Down
3 changes: 0 additions & 3 deletions resources/js/graphql/mutation/auth/UpdateUser.ts

This file was deleted.

1 change: 0 additions & 1 deletion resources/js/graphql/query/auth/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ export default `query User {
apiTokens {
name
}
account
}
}`;
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;
};
}
7 changes: 1 addition & 6 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 Expand Up @@ -252,7 +247,7 @@ export const useAppStore = defineStore('app', {
getters: {
hasValidConfig(state: AppState) {
if (this.isMultiTenant) {
return state.loggedIn && state.user?.apiTokens?.length > 0 && state.user?.account;
return state.loggedIn && state.user?.apiTokens?.length > 0;
}

return state.loggedIn && state.config.url;
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

0 comments on commit 27c20ff

Please sign in to comment.