|
|
@ -1,3 +1,4 @@
|
|
|
|
|
|
|
|
{% set is_user = current_user == user %}
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<html>
|
|
|
|
{% include 'includes/head.html' %}
|
|
|
|
{% include 'includes/head.html' %}
|
|
|
@ -8,31 +9,179 @@
|
|
|
|
{% include 'includes/navbar.html' %}
|
|
|
|
{% include 'includes/navbar.html' %}
|
|
|
|
|
|
|
|
|
|
|
|
{% if user %}
|
|
|
|
{% if user %}
|
|
|
|
<div id="screen">
|
|
|
|
<div class="screen">
|
|
|
|
<div class="screen">
|
|
|
|
<div class="columns">
|
|
|
|
<p><strong>From Avax Chain</strong></p>
|
|
|
|
<div class="column is-one-third">
|
|
|
|
<p>Handle: ?</p>
|
|
|
|
<img src="{{ user.get_profile_image() }}" id="profileImage" />
|
|
|
|
<img src="{{ user.get_profile_image() }}" id="profileImage" />
|
|
|
|
</div>
|
|
|
|
</br></br>
|
|
|
|
<div class="column is-full">
|
|
|
|
<p><strong>From Local Database</strong></p>
|
|
|
|
<p><strong>From Avax Chain</strong></p>
|
|
|
|
<p>Handle: <input type="text" placeholder="{{ user.handle }}" value="{{ user.handle }}"></input></p>
|
|
|
|
<p>Handle: <span id="userHandle" class="mr-4">?</span></p>
|
|
|
|
<p>Register Date: <strong>{{ user.register_date }}</strong></p>
|
|
|
|
<p>Wownero Address: <span id="wowneroAddress" class="mr-4">?</span></p>
|
|
|
|
<p>Login Date: <strong>{{ user.last_login_date }}</strong></p>
|
|
|
|
<p>Profile IPFS Hash: <span id="metadataIPFSHash">?</span></p>
|
|
|
|
<p>Moderator: <strong>{{ user.is_moderator() }}</strong></p>
|
|
|
|
<p>Tipped AVAX: <span id="tippedAVAX">?</span></p>
|
|
|
|
<p>Verified: <strong>{{ user.verified }}</strong></p>
|
|
|
|
<p>Tipped WOWX: <span id="tippedWOWX">?</span></p>
|
|
|
|
<p>Memes Posted: <strong>{{ user.memes | length }}</strong></p>
|
|
|
|
<p>Tipped WOW: <span id="tippedWOW">?</span></p>
|
|
|
|
{% if user.bio %}
|
|
|
|
|
|
|
|
<p>Bio: {{ user.bio }}</p>
|
|
|
|
</br></br>
|
|
|
|
{% endif %}
|
|
|
|
<p><strong>From Local Database</strong></p>
|
|
|
|
{% if user.website %}
|
|
|
|
<p>
|
|
|
|
<p>Website: <a href="{{ user.website_url }}" target="_blank">{{ user.website_url }}</a></p>
|
|
|
|
Handle: <input id="handleInput" type="text" placeholder="{{ user.handle }}" value="{{ user.handle }}"></input>
|
|
|
|
{% endif %}
|
|
|
|
{% if is_user %}
|
|
|
|
</div>
|
|
|
|
<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>
|
|
|
|
|
|
|
|
<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>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
{% endif %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</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>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
</html>
|
|
|
|