02b2 / Lottery-calls

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

// For security, I'm hardcoding the method names instead of passing the action directly switch (entity) { case 'daemon': switch (action) { case 'ping': res = await rpcCall({ ...daemonOptions, method: 'DERO.Ping' }) break case 'get-info': res = await rpcCall({ ...daemonOptions, method: 'DERO.GetInfo' }) break case 'get-random-address': res = await rpcCall({ ...daemonOptions, method: 'DERO.GetRandomAddress' }) break case 'get-height': res = await rpcCall({ ...daemonOptions, method: 'DERO.GetHeight' }) break case 'get-gas-estimate': res = await rpcCall({ ...daemonOptions, method: 'DERO.GetGasEstimate', params: args }) break case 'get-sc': res = await rpcCall({ ...daemonOptions, method: 'DERO.GetSC', params: args }) break case 'get-transaction': res = await rpcCall({ ...daemonOptions, method: 'DERO.GetTransaction', params: args }) break case 'get-block': res = await rpcCall({ ...daemonOptions, method: 'DERO.GetBlock', params: args }) break case 'name-to-address': res = await rpcCall({ ...daemonOptions, method: 'DERO.NameToAddress', params: args }) break case 'get-last-block-header': res = await rpcCall({ ...daemonOptions, method: 'DERO.GetLastBlockHeader' }) break case 'get-encrypted-balance': res = await rpcCall({ ...daemonOptions, method: 'DERO.GetEncryptedBalance', params: args }) break case 'get-tx-pool': res = await rpcCall({ ...daemonOptions, method: 'DERO.GetTxPool' }) break default: err = ERROR_INVALID_DAEMON_ACTION break } break case 'wallet': switch (action) { case 'make-integrated-address': res = await rpcCall({ ...walletOptions, method: MakeIntegratedAddress, params: args }) break case 'split-integrated-address': res = await rpcCall({ ...walletOptions, method: SplitIntegratedAddress, params: args }) break case 'get-balance': res = await rpcCall({ ...walletOptions, method: GetBalance, params: args }) break case 'get-height': res = await rpcCall({ ...walletOptions, method: GetHeight }) break case 'get-address': res = await rpcCall({ ...walletOptions, method: 'GetAddress' }) break case 'start-transfer': const transferStateId = nanoid() const promise = new Promise((resolve, reject) => { transferStateMap.set(transferStateId, { resolve, reject, params: args, sender }) })

const getWalletAddress = React.useCallback(async () => { const deroBridgeApi = deroBridgeApiRef.current const [err, res] = await to(deroBridgeApi.wallet('get-address')) if (err) alert(err.message) else alert(JSON.stringify(res)) }, [])

Get address

login.js

import React, { useState, useCallback, useRef, useEffect } from 'react'; import to from 'await-to-js'; import DeroBridgeApi from 'dero-rpc-bridge-api';

const Login = () => { const deroBridgeApiRef = useRef(); const [address, setAddress] = useState(''); const [errorMessage, setErrorMessage] = useState('');

useEffect(() => { const initDeroBridge = async () => { deroBridgeApiRef.current = new DeroBridgeApi(); const deroBridgeApi = deroBridgeApiRef.current; const [err] = await to(deroBridgeApi.init()); if (err) { setErrorMessage('Failed to connect to extension.'); } };

window.addEventListener('load', initDeroBridge);
return () => window.removeEventListener('load', initDeroBridge);

}, []);

const getWalletAddress = useCallback(async (userAddress) => { const deroBridgeApi = deroBridgeApiRef.current; const [err, res] = await to(deroBridgeApi.wallet('get-address')); if (err) { setErrorMessage(err.message); return ''; } return res; }, []);

const handleLogin = async () => { const userAddress = address.trim(); if (!userAddress) { setErrorMessage('Please enter your wallet address.'); return; } const walletAddress = await getWalletAddress(userAddress); if (!walletAddress) { setErrorMessage('Failed to retrieve wallet address.'); return; } if (userAddress === walletAddress) { // User authentication successful, allow access to account. // Do something here, like redirect to account page. } else { setErrorMessage('Invalid wallet address.'); } };

const handleChange = (event) => { setAddress(event.target.value); };

return (

Wallet Address: Login {errorMessage &&

{errorMessage}

}
); };

export default Login;

app.js

About


Languages

Language:JavaScript 77.0%Language:HTML 14.9%Language:CSS 8.1%