ваше сообщение коммита
This commit is contained in:
@@ -3,25 +3,25 @@ import api from '../api/axios';
|
||||
// Адреса смарт-контрактов токенов HB3A
|
||||
export const TOKEN_CONTRACTS = {
|
||||
eth: {
|
||||
address: "0xd95a45fc46a7300e6022885afec3d618d7d3f27c",
|
||||
symbol: "HB3A",
|
||||
network: "Ethereum"
|
||||
address: '0xd95a45fc46a7300e6022885afec3d618d7d3f27c',
|
||||
symbol: 'HB3A',
|
||||
network: 'Ethereum',
|
||||
},
|
||||
bsc: {
|
||||
address: "0x1d47f12ffA279BFE59Ab16d56fBb10d89AECdD5D",
|
||||
symbol: "HB3A",
|
||||
network: "BSC"
|
||||
address: '0x1d47f12ffA279BFE59Ab16d56fBb10d89AECdD5D',
|
||||
symbol: 'HB3A',
|
||||
network: 'BSC',
|
||||
},
|
||||
arbitrum: {
|
||||
address: "0xdce769b847a0a697239777d0b1c7dd33b6012ba0",
|
||||
symbol: "HB3A",
|
||||
network: "Arbitrum"
|
||||
address: '0xdce769b847a0a697239777d0b1c7dd33b6012ba0',
|
||||
symbol: 'HB3A',
|
||||
network: 'Arbitrum',
|
||||
},
|
||||
polygon: {
|
||||
address: "0x351f59de4fedbdf7601f5592b93db3b9330c1c1d",
|
||||
symbol: "HB3A",
|
||||
network: "Polygon"
|
||||
}
|
||||
address: '0x351f59de4fedbdf7601f5592b93db3b9330c1c1d',
|
||||
symbol: 'HB3A',
|
||||
network: 'Polygon',
|
||||
},
|
||||
};
|
||||
|
||||
// Получение балансов токенов
|
||||
@@ -35,7 +35,7 @@ export const fetchTokenBalances = async () => {
|
||||
eth: '0',
|
||||
bsc: '0',
|
||||
arbitrum: '0',
|
||||
polygon: '0'
|
||||
polygon: '0',
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -4,39 +4,39 @@ import { SiweMessage } from 'siwe';
|
||||
|
||||
export async function connectWithWallet() {
|
||||
console.log('Starting wallet connection...');
|
||||
|
||||
|
||||
try {
|
||||
// Проверяем наличие MetaMask
|
||||
if (!window.ethereum) {
|
||||
throw new Error('MetaMask not detected. Please install MetaMask.');
|
||||
}
|
||||
|
||||
|
||||
console.log('MetaMask detected, requesting accounts...');
|
||||
|
||||
|
||||
// Запрашиваем доступ к аккаунтам
|
||||
const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
|
||||
|
||||
|
||||
console.log('Got accounts:', accounts);
|
||||
|
||||
|
||||
if (!accounts || accounts.length === 0) {
|
||||
throw new Error('No accounts found. Please unlock MetaMask.');
|
||||
}
|
||||
|
||||
|
||||
// Берем первый аккаунт
|
||||
const address = ethers.getAddress(accounts[0]);
|
||||
console.log('Normalized address:', address);
|
||||
|
||||
|
||||
// Запрашиваем nonce с сервера
|
||||
console.log('Requesting nonce...');
|
||||
const nonceResponse = await axios.get(`/api/auth/nonce?address=${address}`);
|
||||
const nonce = nonceResponse.data.nonce;
|
||||
console.log('Got nonce:', nonce);
|
||||
|
||||
|
||||
// Создаем сообщение для подписи
|
||||
const domain = window.location.host;
|
||||
const origin = window.location.origin;
|
||||
const statement = 'Sign in with Ethereum to the app.';
|
||||
|
||||
|
||||
const siweMessage = new SiweMessage({
|
||||
domain,
|
||||
address,
|
||||
@@ -45,31 +45,31 @@ export async function connectWithWallet() {
|
||||
version: '1',
|
||||
chainId: 1,
|
||||
nonce,
|
||||
resources: [`${origin}/api/auth/verify`]
|
||||
resources: [`${origin}/api/auth/verify`],
|
||||
});
|
||||
|
||||
|
||||
const message = siweMessage.prepareMessage();
|
||||
console.log('SIWE message:', message);
|
||||
|
||||
|
||||
// Запрашиваем подпись
|
||||
console.log('Requesting signature...');
|
||||
const signature = await window.ethereum.request({
|
||||
method: 'personal_sign',
|
||||
params: [message, address]
|
||||
params: [message, address],
|
||||
});
|
||||
|
||||
|
||||
console.log('Got signature:', signature);
|
||||
|
||||
|
||||
// Отправляем подпись на сервер для верификации
|
||||
console.log('Sending verification request...');
|
||||
const verificationResponse = await axios.post('/api/auth/verify', {
|
||||
message,
|
||||
signature,
|
||||
address
|
||||
address,
|
||||
});
|
||||
|
||||
|
||||
console.log('Verification response:', verificationResponse.data);
|
||||
|
||||
|
||||
// Обновляем состояние аутентификации
|
||||
if (verificationResponse.data.success) {
|
||||
// Обновляем состояние аутентификации в localStorage
|
||||
@@ -78,10 +78,10 @@ export async function connectWithWallet() {
|
||||
localStorage.setItem('address', verificationResponse.data.address);
|
||||
localStorage.setItem('isAdmin', verificationResponse.data.isAdmin);
|
||||
}
|
||||
|
||||
|
||||
return verificationResponse.data;
|
||||
} catch (error) {
|
||||
console.error('Error connecting wallet:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user