You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
199 lines
7.8 KiB
HTML
199 lines
7.8 KiB
HTML
{% set is_user = current_user == user %}
|
|
<!DOCTYPE html>
|
|
<html>
|
|
{% include 'includes/head.html' %}
|
|
<body>
|
|
<section class="section">
|
|
<div class="container">
|
|
|
|
{% include 'includes/navbar.html' %}
|
|
|
|
{% if user %}
|
|
<div class="screen">
|
|
<div class="columns">
|
|
<div class="column is-one-third">
|
|
<img src="{{ user.get_profile_image() }}" id="profileImage" />
|
|
</div>
|
|
<div class="column is-full">
|
|
<p><strong>From Avax Chain</strong></p>
|
|
<p>Handle: <span id="userHandle" class="mr-4">?</span></p>
|
|
<p>Wownero Address: <span id="wowneroAddress" class="mr-4">?</span></p>
|
|
<p>Profile IPFS Hash: <span id="metadataIPFSHash">?</span></p>
|
|
<p>Tipped AVAX: <span id="tippedAVAX">?</span></p>
|
|
<p>Tipped WOWX: <span id="tippedWOWX">?</span></p>
|
|
<p>Tipped WOW: <span id="tippedWOW">?</span></p>
|
|
|
|
</br></br>
|
|
<p><strong>From Local Database</strong></p>
|
|
<p>
|
|
Handle:
|
|
{% if is_user %}
|
|
<input id="handleInput" type="text" placeholder="{{ user.handle }}" value="{{ user.handle }}"></input>
|
|
<a onclick="publishHandleAVAX()" class="publishAVAX">Publish AVAX</a>
|
|
{% else %}
|
|
<strong>{{ user.handle }}</strong>
|
|
{% endif %}
|
|
</p>
|
|
<p>
|
|
Wownero Address:
|
|
{% if is_user %}
|
|
<input id="wowneroAddressInput" type="text" placeholder="{{ user.wownero_address }}" value="{{ user.wownero_address }}"></input>
|
|
<a onclick="publishWowneroAddress()" class="publishAVAX">Publish AVAX</a>
|
|
{% else %}
|
|
<strong>{{ user.wownero_address }}</strong>
|
|
{% endif %}
|
|
</p>
|
|
<p>
|
|
Metadata IPFS Hash:
|
|
{% if is_user %}
|
|
<input id="metadataIPFSHashInput" type="text" placeholder="{{ user.ipfs_hash }}" value="{{ user.ipfs_hash }}"></input>
|
|
<a onclick="publishMetadataIPFSHash()" class="publishAVAX">Publish AVAX</a>
|
|
{% else %}
|
|
<strong>{{ user.ipfs_hash }}</strong>
|
|
{% endif %}
|
|
</p>
|
|
{% if is_user %}
|
|
<p><a onclick="saveDB()" class="ml-2 button is-primary">Save DB</a></p>
|
|
{% endif %}
|
|
<p>Register Date: <strong>{{ user.register_date }}</strong></p>
|
|
<p>Login Date: <strong>{{ user.last_login_date }}</strong></p>
|
|
<p>Moderator: <strong>{{ user.is_moderator() }}</strong></p>
|
|
<p>Verified: <strong>{{ user.verified }}</strong></p>
|
|
<p>Memes Posted: <strong>{{ user.memes | length }}</strong></p>
|
|
{% if user.bio %}
|
|
<p>Bio: {{ user.bio }}</p>
|
|
{% endif %}
|
|
{% if user.website %}
|
|
<p>Website: <a href="{{ user.website_url }}" target="_blank">{{ user.website_url }}</a></p>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
|
|
</div>
|
|
</section>
|
|
{% include 'includes/footer.html' %}
|
|
<script src="/static/js/vendor/web3-1.3.6.min.js"></script>
|
|
<script type="text/javascript">
|
|
let contractABI = {{ config.CONTRACT_ABI | tojson }};
|
|
let contractAddress = "{{ config.CONTRACT_ADDRESS }}";
|
|
const w3 = new Web3(Web3.givenProvider || "http://127.0.0.1:7545");
|
|
const contract = new w3.eth.Contract(contractABI, contractAddress);
|
|
|
|
async function getMetamaskAccount() {
|
|
const accounts = await window.ethereum.request({
|
|
method: 'eth_requestAccounts',
|
|
});
|
|
const account = accounts[0];
|
|
return account
|
|
}
|
|
|
|
async function saveDB() {
|
|
await fetch('{{ url_for("api.update_user" ) }}', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json;charset=utf-8'
|
|
},
|
|
body: JSON.stringify({
|
|
'user_id': {{ user.id }},
|
|
'handle': document.getElementById('handleInput').value,
|
|
'wownero_address': document.getElementById('wowneroAddressInput').value,
|
|
'ipfs_hash': document.getElementById('metadataIPFSHashInput').value,
|
|
})
|
|
})
|
|
.then((resp) => resp.json())
|
|
.then(function(data) {
|
|
console.log(data)
|
|
if (data['success']) {
|
|
notif('Updated user information in this server\'s database', 'success');
|
|
notif('Publish to AVAX to make the data more available', 'info');
|
|
} else {
|
|
notif('There was an issue posting data to the API. Try again later.', 'error');
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
async function fetchUserProfile() {
|
|
_walletAddress = w3.utils.toChecksumAddress('{{ user.public_address }}');
|
|
const userProfile = await contract.methods.userProfile(_walletAddress).call();
|
|
document.getElementById('userHandle').innerHTML = userProfile.userHandle;
|
|
document.getElementById('wowneroAddress').innerHTML = userProfile.wowneroAddress;
|
|
document.getElementById('metadataIPFSHash').innerHTML = userProfile.metadataIPFSHash;
|
|
document.getElementById('tippedAVAX').innerHTML = userProfile.tippedAVAX;
|
|
document.getElementById('tippedWOWX').innerHTML = 0;
|
|
return
|
|
}
|
|
|
|
async function publishHandleAVAX() {
|
|
const handle = document.getElementById('handleInput').value;
|
|
if (handle == "") {
|
|
notif('Cannot publish an empty value.', 'warning');
|
|
}
|
|
const walletAddress = await getMetamaskAccount();
|
|
const gasPrice = await w3.eth.getGasPrice();
|
|
const gasLimit = await contract.methods.setUserHandle(handle).estimateGas(function(err, gas){
|
|
return gas;
|
|
});
|
|
console.log(`Attempting to update user handle ${handle} with gas limit of ${gasLimit} gas and gas price of ${gasPrice}`);
|
|
let res = await contract.methods.setUserHandle(handle).send({
|
|
from: walletAddress,
|
|
value: 0,
|
|
gasPrice: gasPrice,
|
|
gas: gasLimit
|
|
});
|
|
console.log(res);
|
|
}
|
|
|
|
async function publishWowneroAddress() {
|
|
const address = document.getElementById('wowneroAddressInput').value;
|
|
if (address == "") {
|
|
notif('Cannot publish an empty value.', 'warning');
|
|
}
|
|
const walletAddress = await getMetamaskAccount();
|
|
const gasPrice = await w3.eth.getGasPrice();
|
|
const gasLimit = await contract.methods.setUserWowneroAddress(address).estimateGas(function(err, gas){
|
|
return gas;
|
|
});
|
|
console.log(`Attempting to update Wownero address ${address} with gas limit of ${gasLimit} gas and gas price of ${gasPrice}`);
|
|
let res = await contract.methods.setUserWowneroAddress(address).send({
|
|
from: walletAddress,
|
|
value: 0,
|
|
gasPrice: gasPrice,
|
|
gas: gasLimit
|
|
});
|
|
console.log(res);
|
|
}
|
|
|
|
async function publishMetadataIPFSHash() {
|
|
const _hash = document.getElementById('metadataIPFSHashInput').value;
|
|
if (_hash == "") {
|
|
notif('Cannot publish an empty value.', 'warning');
|
|
}
|
|
const walletAddress = await getMetamaskAccount();
|
|
const gasPrice = await w3.eth.getGasPrice();
|
|
const gasLimit = await contract.methods.setUserMetadata(_hash).estimateGas(function(err, gas){
|
|
return gas;
|
|
});
|
|
console.log(`Attempting to update user metadata hash ${_hash} with gas limit of ${gasLimit} gas and gas price of ${gasPrice}`);
|
|
let res = await contract.methods.setUserMetadata(_hash).send({
|
|
from: walletAddress,
|
|
value: 0,
|
|
gasPrice: gasPrice,
|
|
gas: gasLimit
|
|
});
|
|
console.log(res);
|
|
}
|
|
|
|
window.addEventListener('DOMContentLoaded', () => {
|
|
fetchUserProfile();
|
|
});
|
|
</script>
|
|
|
|
<style>
|
|
input { width: 30%; }
|
|
</style>
|
|
</body>
|
|
</html>
|