|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
{% set is_user = current_user == user %}
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html>
|
|
|
|
|
{% include 'includes/head.html' %}
|
|
|
|
@ -8,14 +9,41 @@
|
|
|
|
|
{% include 'includes/navbar.html' %}
|
|
|
|
|
|
|
|
|
|
{% if user %}
|
|
|
|
|
<div id="screen">
|
|
|
|
|
<div class="screen">
|
|
|
|
|
<p><strong>From Avax Chain</strong></p>
|
|
|
|
|
<p>Handle: ?</p>
|
|
|
|
|
<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: <input type="text" placeholder="{{ user.handle }}" value="{{ user.handle }}"></input></p>
|
|
|
|
|
<p>
|
|
|
|
|
Handle: <input id="handleInput" type="text" placeholder="{{ user.handle }}" value="{{ user.handle }}"></input>
|
|
|
|
|
{% if is_user %}
|
|
|
|
|
<a onclick="publishHandleAVAX()" class="publishAVAX">Publish AVAX</a>
|
|
|
|
|
{% endif %}
|
|
|
|
|
</p>
|
|
|
|
|
<p>
|
|
|
|
|
Wownero Address: <input id="wowneroAddressInput" type="text" placeholder="{{ user.wownero_address }}" value="{{ user.wownero_address }}"></input>
|
|
|
|
|
{% if is_user %}
|
|
|
|
|
<a onclick="publishWowneroAddress()" class="publishAVAX">Publish AVAX</a>
|
|
|
|
|
{% endif %}
|
|
|
|
|
</p>
|
|
|
|
|
<p>
|
|
|
|
|
Metadata IPFS Hash: <input id="metadataIPFSHashInput" type="text" placeholder="{{ user.ipfs_hash }}" value="{{ user.ipfs_hash }}"></input>
|
|
|
|
|
{% if is_user %}
|
|
|
|
|
<a onclick="publishMetadataIPFSHash()" class="publishAVAX">Publish AVAX</a>
|
|
|
|
|
{% endif %}
|
|
|
|
|
</p>
|
|
|
|
|
<p><a onclick="saveDB()" class="ml-2 button is-primary">Save DB</a></p>
|
|
|
|
|
<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>
|
|
|
|
@ -29,10 +57,131 @@
|
|
|
|
|
{% 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>
|
|
|
|
|