Skip to content

Commit

Permalink
Merge pull request #84 from leo42/Bug-Fixes-04-06-24
Browse files Browse the repository at this point in the history
Fix wrong amounts in History because of withdraw (Blockfrost specific)
  • Loading branch information
leo42 authored Jun 4, 2024
2 parents a099f3b + e4c5565 commit cd88b7d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
12 changes: 12 additions & 0 deletions Be/passthrough/passtrough.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ res.header('Access-Control-Allow-Origin', SERVING);
}
}
);
//Endpoint /txs/:hash/withdrawals
app.get('/txs/:hash/withdrawals', async (req, res) => {
res.header('Access-Control-Allow-Origin', SERVING);
const { hash } = req.params;
try {
const response = await axios.get(`${blockfrostApis[req.headers.project_id]}/txs/${hash}/withdrawals`, { headers: { project_id: blockfrostApiKeys[req.headers.project_id] } });
res.json(response.data);
}catch (error) {
const statusCode = error.response.status || 500;
res.status(statusCode).json({ error: error.message });
}
});

//Endpoint :txs/${txHash}
app.get('/txs/:txHash', async (req, res) => {
Expand Down
42 changes: 34 additions & 8 deletions Fe/src/helpers/TransactionHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async function getTransactionHistory(address, settings, page=0 , limit = 10){
}else if ( settings.metadataProvider === "Blockfrost"){
const api = settings.api.url
const response = await fetch(
`${api}/addresses/${address}/transactions?order=acs`,
`${api}/addresses/${address}/transactions`,
{
method: "GET",
headers: {
Expand All @@ -47,7 +47,7 @@ async function getTransactionHistory(address, settings, page=0 , limit = 10){
if (json.error)
return []
json.sort((a,b) => b.block_height - a.block_height)
return await getTransactionDetails(json.slice(page*limit,(page+1)*limit), settings)
return await getTransactionDetails(json.slice(page*limit,(page+1)*limit), settings, address)
}else if(settings.metadataProvider === "Maestro")
{
const MaestroUrl = `https://${settings.network}.gomaestro-api.org`
Expand All @@ -72,9 +72,13 @@ async function getTransactionHistory(address, settings, page=0 , limit = 10){

}

async function getTransactionDetails(transactionIds, settings){
async function getTransactionDetails(transactionIds, settings, address){
let transactionInfo = {...JSON.parse(localStorage.getItem('transactionInfo'))};

const lucid = await Lucid.new(
null,
settings.network
);


let fullTransactionsInfo = transactionIds.map( async (transactionId) => {
if (transactionInfo[transactionId.tx_hash] && transactionInfo[transactionId.tx_hash].provider === settings.metadataProvider ){
Expand Down Expand Up @@ -138,10 +142,35 @@ async function getTransactionDetails(transactionIds, settings){
}
}
);
let withdraw
try{
const withdrawResponce = await fetch(
`${api}/txs/${transactionId.tx_hash}/withdrawals`,
{

method: "GET",
headers: {
project_id: settings.api.projectId
}
}
)
withdraw = await withdrawResponce.json()
}catch(e){
console.log(e)
withdraw = []
}
let fullTransactionInfo = {...transactionId};
fullTransactionInfo.utxos = await response.json();
transactionInfo[transactionId.tx_hash] = fullTransactionInfo
transactionInfo[transactionId.tx_hash].fetch_time = Date.now()
transactionInfo[transactionId.tx_hash].withdrawals = {}
transactionInfo[transactionId.tx_hash].withdrawals.amount = 0
withdraw.forEach( w => {
if(lucid.utils.getAddressDetails(address).stakeCredential.hash === lucid.utils.getAddressDetails(w.address).stakeCredential.hash) {
transactionInfo[transactionId.tx_hash].withdrawals.amount += Number(w.amount)}
})

// transactionInfo[transactionId.tx_hash].withdrawals = withdrawResponce.ok ? await withdrawResponce.json() : null
transactionInfo[transactionId.tx_hash].provider = "Blockfrost"
localStorage.setItem('transactionInfo', JSON.stringify(transactionInfo));
return transactionInfo[transactionId.tx_hash]
Expand All @@ -156,10 +185,7 @@ async function getTransactionDetails(transactionIds, settings){
} },
).then((res) => res.json());

const lucid = await Lucid.new(
null,
settings.network
);


let fullTransactionInfo = {...transactionId};
fullTransactionInfo.utxos = {}
Expand Down

0 comments on commit cd88b7d

Please sign in to comment.