Skip to content

Commit

Permalink
Merge branch 'master' into pull-master
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekteega authored Apr 8, 2023
2 parents f0cd041 + 70aa2d4 commit 8973f7c
Show file tree
Hide file tree
Showing 3 changed files with 3,568 additions and 30 deletions.
111 changes: 81 additions & 30 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ <h3 id="page_title"></h3>
<!-- Set urls for token and flo Apis -->
<script>
let floGlobals = {}
tokenApiUrl = 'https://ranchimallflo.duckdns.org'
floApiUrl = 'https://flosight.duckdns.org'
tokenApiUrl = 'https://ranchimallflov2.ranchimall.net'
floApiUrl = 'https://flosight.ranchimall.net'
</script>
<script>
/*jshint esversion: 8 */
Expand Down Expand Up @@ -329,6 +329,7 @@ <h3 id="page_title"></h3>
async function renderHome(state) {
getRef("page_header").classList.add("hidden");
let [data, latestTxs, latestBlocks] = await Promise.all([getBannerData(), getLatestTxs(), getAllBlocks(6)])
console.log(latestTxs)
renderElem(getRef("page_container"), html`${render.homepage(data)}`);
renderTransactions('top_transaction_container', latestTxs)
const renderedBlocks = latestBlocks.map(block => render.blockCard(block))
Expand Down Expand Up @@ -668,15 +669,17 @@ <h4>${formatAmount(balance, token.toLowerCase() === 'rupee' ? 'inr' : 'usd')}</h
`;
},
transactionPage(obj) {
let { type, name, blockHeight, amount, sender, receiver, floData, hash, confirmations } = obj;
let { type, name, blockHeight, amount, sender, receiver, floData, hash, confirmations,nftHash} = obj;
// todo : This is a temporary fix. Fix this on the Database and API level
if (type == 'smartContractPays' || type == ' smartContractPays') {
name = ''
}
// split camel case to words
type = type.replace(/([A-Z])/g, ' $1').replace(/^./, function (str) {
return str.toUpperCase();
});

if(type.trim() === 'nftIncorporation')
type = 'NFT Incorporation'
else if(type.trim() === 'nft transfer')
type = 'NFT Transfer'

return html`
<div id="transaction_page" class="page">
<div class='head'>
Expand Down Expand Up @@ -706,10 +709,16 @@ <h4>${formatAmount(amount, 'usd')}</h4>
</div>
</div>
<div class="card">
<h5 class="label">FLO Data</h5>
<p>${floData}</p>
<h5 class="label">Block Confirmations</h5>
<h4>${confirmations}</h4>
<h5 class="label">FLO Data</h5>
<p>${floData}</p>
<h5 class="label">Block Confirmations</h5>
<h4>${confirmations}</h4>
${
nftHash?html`
<h5 class="label">NFT hash</h5>
<sm-copy value=${nftHash} clip-text></sm-copy>
`:''
}
</div>
</div>
`;
Expand Down Expand Up @@ -859,13 +868,19 @@ <h5 class="label">Transaction ID</h5>
</div>`;
},
tokenTransferCard(obj) {
const { hash, blockHeight, token, sender, receiver, amount } = obj;
const { hash, blockHeight, token, sender, receiver, amount,type } = obj;
let title = 'Token transfer';
console.log(type)
if(type === 'nfttransfer')
title = 'NFT transfer';
return html`
<div id=${hash} class="transaction token-transfer">
<svg class="icon" viewBox="0 0 64 64"> <title>transfer</title> <polyline points="17.04 35.97 14.57 33.5 40.15 7.9 32.75 0.5 55.52 0.5 55.52 23.28 48.12 15.87 23.86 40.14 15.88 48.13 8.48 40.72 8.48 63.5 31.25 63.5 23.85 56.1 49.43 30.5 46.96 28.03"/> </svg>
<div class="contract-type">
<h5 class="label">Token transfer</h5>
<a href=${`#/token/${token}`} class="uppercase">${token}</a>
<h5 class="label">${title}</h5>
<a href=${`#/token/${token}`} class="">${token}</a>
</div>
<div class="contract-info">
<div class="flex flex-direction-column">
Expand All @@ -884,12 +899,15 @@ <h5 class="label">Transaction ID</h5>
`;
},
tokenCreationCard(obj) {
const { hash, blockHeight, token, incAddress, supply } = obj;
const { hash, blockHeight, token, incAddress, supply,type,nftHash } = obj;
let title = 'Token creation';
if(type === 'nftincorp')
title = 'NFT creation';
return html`
<div id=${hash} class="transaction token-creation">
<svg class="icon" viewBox="0 0 64 64"> <title>token</title> <circle cx="32" cy="32" r="31"/> <circle cx="32" cy="32" r="25.19"/> <line x1="37" y1="21.74" x2="43.14" y2="21.74"/> <path d="M20.86,21.74H32V43.23"/> </svg>
<div class="contract-type">
<h5 class="label">token creation</h5>
<h5 class="label">${title}</h5>
<a href=${`#/token/${token}`} class="token uppercase">${token}</a>
</div>
<div class="contract-info">
Expand All @@ -905,6 +923,12 @@ <h4 class="uppercase">${token}</h4>
<h5 class="label">supply</h5>
<h4>${supply}</h4>
</div>
${
type === 'nftincorp'? html`<div class="flex flex-direction-column">
<h5 class="label">NFT hash</h5>
<sm-copy value="${nftHash}"></sm-copy>
</div>`:''
}
<div class="flex align-center space-between flex-wrap gap-1">
<div class="flex flex-direction-column">
<h5 class="label">Transaction ID</h5>
Expand Down Expand Up @@ -1022,12 +1046,14 @@ <h5 class="label">Transaction ID</h5>
const renderedTransactions = txFrag.map(tx => {
switch (tx.type) {
case 'tokentransfer':
case 'nfttransfer':
return render.tokenTransferCard(tx)
break;
case 'contracttransfer':
return render.contractTransferCard(tx);
break;
case 'tokenincorp':
case 'nftincorp':
return render.tokenCreationCard(tx);
break;
case 'contractincorp':
Expand All @@ -1038,6 +1064,7 @@ <h5 class="label">Transaction ID</h5>
break;
}
})
console.log(renderedTransactions)
renderElem(document.getElementById(container), html`${renderedTransactions.length ? renderedTransactions : html`<div class="no-results">No transactions found</div>`}`)
}

Expand Down Expand Up @@ -1080,7 +1107,7 @@ <h5 class="label">Transaction ID</h5>
.then(function (latestTxs) {
let latestTxArray = [];
for (const transactionKey in latestTxs.latestTransactions) {
const { transactionDetails: { txid, blockHeight, vin, vout }, parsedFloData: { type, tokenAmount, tokenIdentification, transferType, contractName, triggerCondition, userChoice } } = latestTxs.latestTransactions[transactionKey];
const { transactionDetails: { txid, blockHeight, vin, vout }, parsedFloData: { type, tokenAmount, tokenIdentification, transferType, contractName, triggerCondition, userChoice,nftHash } } = latestTxs.latestTransactions[transactionKey];
// determine txhash and blockHeight
let obj = {
hash: txid,
Expand All @@ -1092,7 +1119,7 @@ <h5 class="label">Transaction ID</h5>
obj["token"] = tokenIdentification;

if (type == "transfer") {
if (transferType == "token") {
if (transferType == "token" || transferType == "nft") {
// token transfer
/* tokenTransferCard
hash, blockHeight, token, sender, receiver, amount */
Expand Down Expand Up @@ -1154,6 +1181,16 @@ <h5 class="label">Transaction ID</h5>
type: "tokenincorp",
});
latestTxArray.push(obj);
} else if (type === "nftIncorporation") {
// token incorporation
// smart contract incorporation
obj = Object.assign({}, obj, {
incAddress: vin[0]["addr"],
supply: tokenAmount,
type,
nftHash,
});
latestTxArray.push(obj);
}
} else {
// smart contract committee trigger
Expand All @@ -1176,6 +1213,8 @@ <h5 class="label">Transaction ID</h5>
}
}
return latestTxArray;
}).catch((err) => {
console.log(err)
});
}

Expand Down Expand Up @@ -1279,18 +1318,21 @@ <h5 class="label">Transaction ID</h5>
// Object
let latestTxArray = [];
for (const transactionKey in txList) {
const { transactionDetails: { txid, blockHeight, vin, vout }, parsedFloData: { contractAddress, contractType, expiryTime, contractAmount, type, tokenAmount, tokenIdentification, transferType, contractName, triggerCondition, userChoice } } = txList[transactionKey];
console.log(transactionKey)
if(transactionKey == '11571ce7e5eed0bce30e24de89bb1ba6cc432df7b5b40bbc9f0225b98968cb47'){
//debugger
}
const { transactionDetails: { txid, blockHeight, vin, vout }, parsedFloData: { contractAddress, contractType, expiryTime, contractAmount, type, tokenAmount, tokenIdentification, transferType, contractName, triggerCondition, userChoice,nftHash } } = txList[transactionKey];
let obj = {
hash: txid,
blockHeight,
};

if (type != "smartContractPays") {
// determine token
obj["token"] = tokenIdentification;
switch (type) {
case 'transfer':
if (transferType == "token") {
if (transferType == "token" || transferType == 'nft') {
let receiverAddress = "";
for (const output of vout) {
if (output["scriptPubKey"]["addresses"][0] !== vin[0]["addr"]) {
Expand All @@ -1303,7 +1345,7 @@ <h5 class="label">Transaction ID</h5>
sender: vin[0]["addr"],
receiver: receiverAddress,
amount: tokenAmount,
type: "tokentransfer",
type: transferType == "token" ? "tokentransfer" : "nfttransfer",
});
latestTxArray.push(obj);
break;
Expand Down Expand Up @@ -1338,7 +1380,6 @@ <h5 class="label">Transaction ID</h5>
});
latestTxArray.push(obj);
break;

case 'smartContractIncorporation':
// smart contract incorporation
// todo : add checks to determine obj for different types of smart contract incorporation
Expand All @@ -1353,7 +1394,17 @@ <h5 class="label">Transaction ID</h5>
});
latestTxArray.push(obj);
break;
}
case 'nftIncorporation':
// nft incorporation
obj = Object.assign({}, obj, {
incAddress: vin[0]["addr"],
supply: tokenAmount,
type: "nftincorp",
nftHash
});
latestTxArray.push(obj);
break;
}

} else {
// transaction is a FLO Smart Contract Committee trigger
Expand Down Expand Up @@ -1412,7 +1463,7 @@ <h5 class="label">Transaction ID</h5>
return [false, transaction.description]
} else {
let transactionHash = transaction.transactionHash,
{ flodata, tokenAmount, tokenIdentification, type } = transaction.parsedFloData,
{ flodata, tokenAmount, tokenIdentification, type,nftHash } = transaction.parsedFloData,
{ blockheight, vin, vout, confirmations } = transaction.transactionDetails;
let receiver = "",
sender = vin[0].addr;
Expand All @@ -1422,7 +1473,7 @@ <h5 class="label">Transaction ID</h5>
}
}
console.log(transaction)
// todo - temporary fixes below. Fix these on the Databse and API level
// todo - temporary fixes below. Fix these on the Database and API level
let transactionType = ''
if (type == 'transfer') {
transactionType = transaction.parsedFloData?.transferType
Expand All @@ -1437,11 +1488,12 @@ <h5 class="label">Transaction ID</h5>
name: tokenIdentification,
blockHeight: blockheight,
amount: tokenAmount,
sender: sender,
receiver: receiver,
sender,
receiver,
floData: flodata,
hash: transactionHash,
confirmations: confirmations
confirmations,
nftHash
}
]
}
Expand Down Expand Up @@ -1537,7 +1589,6 @@ <h5 class="label">Transaction ID</h5>
ranchimallFlo.smartContractNameAddressList = [];
//console.log(ranchimallFlo.smartContractList.length);
ranchimallFlo.smartContractList.forEach(contract => {
console.log(contract.contractName);
allSuggestions.push(`${contract.contractName}-${contract.contractAddress}`);
ranchimallFlo.smartContractNameList.push(contract.contractName);
ranchimallFlo.smartContractNameAddressList.push(`${contract.contractName}-${contract.contractAddress}`);
Expand Down
Loading

0 comments on commit 8973f7c

Please sign in to comment.