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.

197 lines
7.9 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-full content">
<h3>From Avalanche Blockchain</h3>
3 years ago
<p>Handle: <strong><span id="userHandle" class="mr-4">?</span></strong></p>
<p>Wownero Address: <strong><span id="wowneroAddress" class="mr-4 wrap">?</span></strong></p>
<p>Profile IPFS Hash: <strong><span id="metadataIPFSHash">?</span></strong></p>
<p>Tipped AVAX: <strong><span id="tippedAVAX">?</span></strong></p>
<p>Tipped WOWX: <strong><span id="tippedWOWX">?</span></strong></p>
<p>Tipped WOW: <strong><span id="tippedWOW">?</span></strong></p>
<h3>From Local Database</h3>
<p>
3 years ago
Handle:
{% if is_user %}
3 years ago
<input id="handleInput" type="text" placeholder="{{ user.handle }}" value="{{ user.handle }}"></input>
<a onclick="publishHandleAVAX()" class="publishAVAX">Publish AVAX</a>
3 years ago
{% else %}
<strong>{{ user.handle }}</strong>
{% endif %}
</p>
<p>
3 years ago
Wownero Address:
{% if is_user %}
3 years ago
<input id="wowneroAddressInput" type="text" placeholder="{{ user.wownero_address or '' }}" value="{{ user.wownero_address or '' }}"></input>
<a onclick="publishWowneroAddress()" class="publishAVAX">Publish AVAX</a>
3 years ago
{% else %}
3 years ago
<strong><span class="wrap">{{ user.wownero_address }}</span></strong>
{% endif %}
</p>
<p>
3 years ago
Metadata IPFS Hash:
{% if is_user %}
3 years ago
<input id="metadataIPFSHashInput" type="text" placeholder="{{ user.ipfs_hash or '' }}" value="{{ user.ipfs_hash or '' }}"></input>
<a onclick="publishMetadataIPFSHash()" class="publishAVAX">Publish AVAX</a>
3 years ago
{% else %}
<strong>{{ user.ipfs_hash }}</strong>
{% endif %}
</p>
<p>Register Date: <strong>{{ user.register_date }}</strong></p>
3 years ago
<p>Last 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 %}
3 years ago
{% if is_user %}
<p><a onclick="saveDB()" class="ml-2 button is-primary">Save DB</a></p>
3 years ago
{% endif %}
</div>
</div>
</div>
{% endif %}
</div>
</section>
{% include 'includes/footer.html' %}
<script type="text/javascript">
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 the Avalanche blockchain to make the data globally available.', 'info');
} else {
3 years ago
notif(data['message'], 'error');
}
})
}
async function fetchUserProfile() {
_walletAddress = w3.utils.toChecksumAddress('{{ user.public_address }}');
const userProfile = await contract.methods.userProfile(_walletAddress).call();
3 years ago
if (userProfile.userHandle){document.getElementById('userHandle').innerHTML = userProfile.userHandle};
if (userProfile.wowneroAddress){document.getElementById('wowneroAddress').innerHTML = userProfile.wowneroAddress};
if (userProfile.metadataIPFSHash){document.getElementById('metadataIPFSHash').innerHTML = userProfile.metadataIPFSHash};
if (userProfile.tippedAVAX){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;
});
3 years ago
try {
notif(`Publishing user handle "${handle}" to the Avalanche blockchain for address ${walletAddress.slice(0, 6)}...${walletAddress.slice(-6)}.`, 'info');
3 years ago
let res = await contract.methods.setUserHandle(handle).send({
from: walletAddress,
value: 0,
gasPrice: gasPrice,
gas: gasLimit
});
console.log(res);
window.location.href = "";
} catch(e) {
notif(e.message, 'warning');
}
}
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;
});
3 years ago
try {
notif(`Publishing Wownero address "${address.slice(0, 6)}...${address.slice(-6)}" to the Avalanche blockchain for address ${walletAddress.slice(0, 6)}...${walletAddress.slice(-6)}.`, 'info');
3 years ago
let res = await contract.methods.setUserWowneroAddress(address).send({
from: walletAddress,
value: 0,
gasPrice: gasPrice,
gas: gasLimit
});
console.log(res);
window.location.href = "";
} catch(e) {
notif(e.message, 'warning');
}
}
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;
});
3 years ago
try {
notif(`Publishing user profile metadata IPFS hash ${_hash} to the Avalanche blockchain for address ${walletAddress.slice(0, 6)}...${walletAddress.slice(-6)}.`, 'info');
3 years ago
let res = await contract.methods.setUserMetadata(_hash).send({
from: walletAddress,
value: 0,
gasPrice: gasPrice,
gas: gasLimit
});
console.log(res);
window.location.href = "";
} catch(e) {
notif(e.message, 'warning');
}
}
window.addEventListener('DOMContentLoaded', () => {
fetchUserProfile();
});
</script>
<style>
input { width: 30%; }
</style>
</body>
</html>