Skip to content

Commit

Permalink
add wallet accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
zlayine committed Jul 12, 2024
1 parent c0ee820 commit 616cc7a
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 13 deletions.
11 changes: 11 additions & 0 deletions resources/js/api/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,15 @@ export class AuthApi {

return AuthApi.sendPlatfromRequest(data);
}

static async setUserAccounts(accounts: string) {
const data = {
query: mutations.UpdateUser,
variables: {
walletAccounts: accounts,
},
};

return AuthApi.sendPlatfromRequest(data);
}
}
7 changes: 6 additions & 1 deletion resources/js/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import SideNavbar from '~/components/SideNavbar.vue';
import SupportButton from '~/components/SupportButton.vue';
import SnackbarGroup from '~/components/SnackbarGroup.vue';
import UserNavbar from '~/components/UserNavbar.vue';
import { computed, watch } from 'vue';
import { computed, onMounted, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useConnectionStore } from '~/store/connection';
const appStore = useAppStore();
const router = useRouter();
Expand Down Expand Up @@ -54,6 +55,10 @@ const initialTheme = () => {
}
})();
onMounted(() => {
useConnectionStore().loadWallet();
});
watch(
() => appStore.theme,
() => {
Expand Down
4 changes: 2 additions & 2 deletions resources/js/components/CollapseCard.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<div class="bg-light-surface-primary dark:bg-dark-surface-primary shadow rounded-lg">
<div
class="flex divide-x divide-light-stroke dark:divide-dark-stroke transition-all"
:class="{ 'border-b border-light-stroke dark:border-dark-stroke': open }"
class="flex divide-x divide-light-stroke dark:divide-dark-stroke transition-all border-light-stroke dark:border-dark-stroke"
:class="{ 'border-b': open }"
>
<div
class="flex justify-between px-4 py-5 flex-1 cursor-pointer text-light-content-strong dark:text-dark-content-strong"
Expand Down
10 changes: 6 additions & 4 deletions resources/js/components/WalletConnectButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/vue';
import ScaleTransition from './ScaleTransition.vue';
import snackbar from '~/util/snackbar';
import { useConnectionStore } from '~/store/connection';
import { publicKeyToAddress } from '~/util/address';
import { AuthApi } from '~/api/auth';
const connectionStore = useConnectionStore();
const loading = ref(false);
const showAccountsModal = ref(false);
const walletName = computed(() => {
if (connectionStore.provider === 'wc') {
return 'Enjin Wallet';
Expand All @@ -96,9 +98,9 @@ const connectWallet = async (provider: string) => {
await connectionStore.connectWallet(provider, () => {
loading.value = false;
});
if (connectionStore.accounts) {
showAccountsModal.value = true;
}
await connectionStore.getAccounts();
const accounts = connectionStore.accounts.map((account) => publicKeyToAddress(account.address))
AuthApi.setUserAccounts(accounts);
} catch {
snackbar.error({ title: 'Failed to connect the wallet' });
} finally {
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/pages/SettingsWalletAccount.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div v-if="walletAccount" class="p-6">
<div class="p-6">
<h1 class="text-xl text-light-content-strong dark:text-dark-content-strong">Wallet Account</h1>
<p class="mt-1 text-sm text-light-content dark:text-dark-content max-w-3xl">
The platform depends on there being a funded wallet daemon account setup and connected to the platform and
Expand Down
4 changes: 2 additions & 2 deletions resources/js/graphql/mutation/auth/UpdateUser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default `mutation UpdateUser($email: String, $password: String) {
UpdateUser(email: $email, password: $password)
export default `mutation UpdateUser($email: String, $password: String, $walletAccounts: [String!]) {
UpdateUser(email: $email, password: $password, walletAccounts: $walletAccounts)
}`;
12 changes: 12 additions & 0 deletions resources/js/store/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { wcNamespaces, wcProjectId } from '~/util/constants';
import { useAppStore } from '.';
import snackbar from '~/util/snackbar';
import { Web3Modal, Web3ModalConfig } from '@web3modal/standalone';
import { AuthApi } from '~/api/auth';
import { publicKeyToAddress } from '~/util/address';

export const PrivacyPolicyLink = 'https://nft.io/legal/privacy-policy';
export const TermsOfServiceLink = 'https://nft.io/legal/terms-of-service';
Expand Down Expand Up @@ -44,6 +46,16 @@ export const useConnectionStore = defineStore('connection', {
getWeb3Modal() {
return new Web3Modal(walletConnectWeb3modalConfig);
},
async loadWallet() {
if (this.provider) {
await this.connectWallet(this.provider, () => {});
if (!this.wallet) {
return;
}
await this.getAccounts();
AuthApi.setUserAccounts(this.accounts.map((account) => publicKeyToAddress(account.address)));
}
},
async connectWallet(provider: string, endLoading: Function) {
if (provider === 'wc') {
await this.connectWC(endLoading);
Expand Down
6 changes: 3 additions & 3 deletions resources/js/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ export const checkFormatPrice = (price, listing, currency) => {
if (
listing &&
(listing.makeAssetId.collectionId !== '0' ||
listing.makeAssetId.tokenId !== '0' ||
listing.takeAssetId.tokenId !== '0' ||
listing.takeAssetId.collectionId !== '0')
listing.makeAssetId.tokenId !== '0' ||
listing.takeAssetId.tokenId !== '0' ||
listing.takeAssetId.collectionId !== '0')
) {
return `${formatPriceFromENJ(price)?.toLocaleString('en-US', {
maximumFractionDigits: 18,
Expand Down

0 comments on commit 616cc7a

Please sign in to comment.