Описание изменений
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div v-if="authStore.isAuthenticated">
|
||||
<div v-if="isAuthenticated">
|
||||
<div class="conversation-list">
|
||||
<div class="list-header">
|
||||
<h3>Диалоги</h3>
|
||||
@@ -40,20 +40,20 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, computed, defineEmits, watch } from 'vue';
|
||||
import { useAuthStore } from '../../stores/auth';
|
||||
import { ref, onMounted, computed, defineEmits, watch, inject } from 'vue';
|
||||
import axios from 'axios';
|
||||
|
||||
const emit = defineEmits(['select-conversation']);
|
||||
const authStore = useAuthStore();
|
||||
const auth = inject('auth');
|
||||
const isAuthenticated = computed(() => auth.isAuthenticated.value);
|
||||
|
||||
const conversations = ref([]);
|
||||
const loading = ref(true);
|
||||
const selectedConversationId = ref(null);
|
||||
|
||||
// Следим за изменением статуса аутентификации
|
||||
watch(() => authStore.isAuthenticated, (isAuthenticated) => {
|
||||
if (!isAuthenticated) {
|
||||
watch(() => isAuthenticated.value, (authenticated) => {
|
||||
if (!authenticated) {
|
||||
conversations.value = []; // Очищаем список бесед при отключении
|
||||
selectedConversationId.value = null;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div v-if="authStore.isAuthenticated">
|
||||
<div v-if="isAuthenticated">
|
||||
<div class="message-thread" ref="threadContainer">
|
||||
<div v-if="loading" class="loading">Загрузка сообщений...</div>
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
<script setup>
|
||||
import { ref, onMounted, watch, nextTick, defineExpose } from 'vue';
|
||||
import axios from 'axios';
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
|
||||
const props = defineProps({
|
||||
conversationId: {
|
||||
@@ -40,7 +39,7 @@ const props = defineProps({
|
||||
const messages = ref([]);
|
||||
const loading = ref(true);
|
||||
const threadContainer = ref(null);
|
||||
const authStore = useAuthStore()
|
||||
const isAuthenticated = ref(false);
|
||||
|
||||
// Загрузка сообщений диалога
|
||||
const fetchMessages = async () => {
|
||||
@@ -112,8 +111,8 @@ watch(
|
||||
);
|
||||
|
||||
// Следим за изменением статуса аутентификации
|
||||
watch(() => authStore.isAuthenticated, (isAuthenticated) => {
|
||||
if (!isAuthenticated) {
|
||||
watch(() => isAuthenticated.value, (authenticated) => {
|
||||
if (!authenticated) {
|
||||
messages.value = []; // Очищаем сообщения при отключении
|
||||
}
|
||||
});
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue';
|
||||
import axios from 'axios';
|
||||
|
||||
const props = defineProps({
|
||||
onEmailAuth: {
|
||||
@@ -49,6 +50,7 @@ const code = ref('');
|
||||
const error = ref('');
|
||||
const isLoading = ref(false);
|
||||
const showVerification = ref(false);
|
||||
const isConnecting = ref(false);
|
||||
|
||||
const isValidEmail = computed(() => {
|
||||
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.value);
|
||||
|
||||
@@ -18,6 +18,7 @@ import axios from 'axios';
|
||||
const loading = ref(false);
|
||||
const error = ref('');
|
||||
const success = ref('');
|
||||
const isConnecting = ref(false);
|
||||
|
||||
async function connectTelegram() {
|
||||
try {
|
||||
|
||||
@@ -5,14 +5,17 @@
|
||||
:disabled="isLoading"
|
||||
class="wallet-btn"
|
||||
>
|
||||
{{ isAuthenticated ? 'Подключено' : 'Подключить кошелек' }}
|
||||
{{ isConnected ? 'Подключено' : 'Подключить кошелек' }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { ref, inject, computed } from 'vue';
|
||||
import { connectWithWallet } from '../../services/wallet';
|
||||
import { ethers } from 'ethers';
|
||||
import { SiweMessage } from 'siwe';
|
||||
import axios from 'axios';
|
||||
|
||||
// Определяем props
|
||||
const props = defineProps({
|
||||
@@ -24,6 +27,12 @@ const props = defineProps({
|
||||
|
||||
// Определяем состояние
|
||||
const isLoading = ref(false);
|
||||
const auth = inject('auth');
|
||||
const isConnecting = ref(false);
|
||||
const address = ref('');
|
||||
|
||||
// Вычисляемое свойство для статуса подключения
|
||||
const isConnected = computed(() => auth.isAuthenticated.value);
|
||||
|
||||
const emit = defineEmits(['connect']);
|
||||
|
||||
@@ -33,22 +42,10 @@ const connectWallet = async () => {
|
||||
|
||||
try {
|
||||
isLoading.value = true;
|
||||
// Получаем адрес кошелька
|
||||
const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
|
||||
const address = accounts[0];
|
||||
|
||||
// Получаем nonce
|
||||
const nonceResponse = await api.get(`/api/auth/nonce?address=${address}`);
|
||||
const nonce = nonceResponse.data.nonce;
|
||||
|
||||
// Подписываем сообщение
|
||||
const message = `${window.location.host} wants you to sign in with your Ethereum account:\n${address.slice(0, 42)}...`;
|
||||
const signature = await window.ethereum.request({
|
||||
method: 'personal_sign',
|
||||
params: [message, address]
|
||||
});
|
||||
|
||||
emit('connect', { address, signature, message });
|
||||
const result = await connectWithWallet();
|
||||
await auth.checkAuth();
|
||||
console.log('Wallet connected, auth state:', auth.isAuthenticated.value);
|
||||
emit('connect', result);
|
||||
} catch (error) {
|
||||
console.error('Error connecting wallet:', error);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user