Описание изменений
This commit is contained in:
@@ -4,47 +4,62 @@
|
||||
{{ error }}
|
||||
</div>
|
||||
|
||||
<button @click="connect" class="connect-button" :disabled="loading">
|
||||
<button @click="connectWallet" class="connect-button" :disabled="loading">
|
||||
<div v-if="loading" class="spinner"></div>
|
||||
{{ loading ? 'Подключение...' : 'Подключить кошелек' }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
<script>
|
||||
import { ref } from 'vue';
|
||||
import { connectWallet } from '../utils/wallet';
|
||||
import { useAuthStore } from '../stores/auth';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
const authStore = useAuthStore();
|
||||
const router = useRouter();
|
||||
const loading = ref(false);
|
||||
const error = ref('');
|
||||
export default {
|
||||
setup() {
|
||||
const authStore = useAuthStore();
|
||||
const router = useRouter();
|
||||
const loading = ref(false);
|
||||
const error = ref('');
|
||||
|
||||
async function connect() {
|
||||
console.log('Нажата кнопка "Подключить кошелек"');
|
||||
|
||||
if (loading.value) return;
|
||||
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
|
||||
try {
|
||||
const authResult = await connectWallet();
|
||||
console.log('Результат подключения:', authResult);
|
||||
|
||||
if (authResult && authResult.authenticated) {
|
||||
authStore.updateAuthState(authResult);
|
||||
router.push({ name: 'home' });
|
||||
} else {
|
||||
error.value = 'Не удалось подключить кошелек';
|
||||
return {
|
||||
authStore,
|
||||
router,
|
||||
loading,
|
||||
error
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async connectWallet() {
|
||||
console.log('Нажата кнопка "Подключить кошелек"');
|
||||
|
||||
if (this.loading) return;
|
||||
|
||||
this.loading = true;
|
||||
this.error = '';
|
||||
|
||||
try {
|
||||
const authResult = await connectWallet();
|
||||
console.log('Результат подключения:', authResult);
|
||||
|
||||
if (authResult && authResult.authenticated) {
|
||||
this.authStore.isAuthenticated = authResult.authenticated;
|
||||
this.authStore.user = { address: authResult.address };
|
||||
this.authStore.isAdmin = authResult.isAdmin;
|
||||
this.authStore.authType = authResult.authType;
|
||||
this.router.push({ name: 'home' });
|
||||
} else {
|
||||
this.error = 'Не удалось подключить кошелек';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка при подключении кошелька:', error);
|
||||
this.error = error.message || 'Ошибка при подключении кошелька';
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка при подключении кошелька:', error);
|
||||
error.value = error.message || 'Ошибка при подключении кошелька';
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user