Skip to content

Commit

Permalink
pool-sapi
Browse files Browse the repository at this point in the history
  • Loading branch information
Enrique Soares committed Sep 2, 2020
1 parent 81cd2b4 commit 9c6ee56
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 75 deletions.
29 changes: 27 additions & 2 deletions src/lib/poolSapi.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
const random = require("random");
const random = require('random');

let sapis = ["https://sapi2.smartcash.org", "https://sapi.smartcash.cc"];
const request = require('request-promise');

let sapis = ['https://sapi2.smartcash.org', 'https://sapi.smartcash.cc'];
/*
request.get('https://sapi.smartcash.cc/v1/smartnodes/list').then((list) => {
list = JSON.parse(list);
const mappedKey = Object.keys(list).map((key) => {
return list[key];
});
const serves = mappedKey
.filter((f) => f.protocol === 90030 && f.status === 'ENABLED')
.map((server) => {
return {
status: server.status,
protocol: server.protocol,
payee: server.payee,
uptime: server.uptime,
ip_sapi: server.ip.split(':')[0] + ':8080',
ip: server.ip,
};
});
if (serves.length > 0) {
sapis = serves.map((server) => 'http://' + server.ip_sapi);
}
});*/
module.exports = () => sapis[random.int(0, sapis.length - 1)];
4 changes: 2 additions & 2 deletions src/lib/sapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ export async function getTransactionHistory(_address) {
method: 'POST',
uri: `${getSapiUrl()}/v1/address/transactions/${_address}`,
body: {
"pageNumber": 1,
"pageSize": 5
pageNumber: 1,
pageSize: 5,
},
json: true, // Automatically stringifies the body to JSON
};
Expand Down
134 changes: 63 additions & 71 deletions src/pages/send/components/transactions-history/TransactionHistory.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,70 @@
import React, { useEffect, useState } from "react";
import ReactDOM from "react-dom";
import style from "./TransactionHistory.module.css";
import { getTransactionHistory } from "../../../../lib/sapi";
import React, { useEffect, useState } from 'react';
import ReactDOM from 'react-dom';
import style from './TransactionHistory.module.css';
import { getTransactionHistory } from '../../../../lib/sapi';

const TransactionsHistory = ({ isShowing, hide, address }) => {
const [history, setHistory] = useState();
const [history, setHistory] = useState();

useEffect(() => {
async function _getTransactionHistory() {
await getTransactionHistory(address)
.then((data) => {
setHistory(data);
})
.catch((error) => console.error(error));
}
_getTransactionHistory();
}, [address]);
useEffect(() => {
async function _getTransactionHistory() {
await getTransactionHistory(address)
.then((data) => {
setHistory(data);
})
.catch((error) => console.error(error));
}
_getTransactionHistory();
}, [address]);

return isShowing
? ReactDOM.createPortal(
<React.Fragment>
<div className={style["modal-overlay"]} />
<div
className={style["modal-wrapper"]}
aria-modal
aria-hidden
tabIndex={-1}
role="dialog"
>
<div className={style["modal"]}>
<div className={style["modal-header"]}>
<strong>Transactions</strong>
<button
type="button"
className={style["modal-close-button"]}
data-dismiss="modal"
aria-label="Close"
onClick={hide}
>
<span aria-hidden="true">&times;</span>
</button>
</div>
<div className={style["modal-body"]}>
Showing last 5 transactions.
<a
href={`https://sapi-explorer.herokuapp.com/#/address/${address}`}
target="_blank"
rel="noopener noreferrer"
>
See all
</a>
{
history?.map((tx, index) => {
return (

<div className={style.cardWrapper} key={index}>
<strong>Type</strong>
<p>{tx.direction}</p>
<strong>Fees</strong>
<p>{tx.fees}</p>
<strong>Amount</strong>
<p>{tx.amount}</p>
<strong>Transaction Id</strong>
<p>{tx.txid}</p>
</div>
);
})}
</div>
</div>
</div>
</React.Fragment>,
document.body
)
: null;
return isShowing
? ReactDOM.createPortal(
<React.Fragment>
<div className={style['modal-overlay']} />
<div className={style['modal-wrapper']} aria-modal aria-hidden tabIndex={-1} role="dialog">
<div className={style['modal']}>
<div className={style['modal-header']}>
<strong>Transactions</strong>
<button
type="button"
className={style['modal-close-button']}
data-dismiss="modal"
aria-label="Close"
onClick={hide}
>
<span aria-hidden="true">&times;</span>
</button>
</div>
<div className={style['modal-body']}>
Showing last 5 transactions.
<a
href={`https://sapi-explorer.herokuapp.com/#/address/${address}`}
target="_blank"
rel="noopener noreferrer"
>
See all
</a>
{history?.map((tx, index) => {
return (
<div className={style.cardWrapper} key={index}>
<strong>Type</strong>
<p>{tx.direction}</p>
<strong>Fees</strong>
<p>{tx.fees}</p>
<strong>Amount</strong>
<p>{tx.amount}</p>
<strong>Transaction Id</strong>
<p>{tx.txid}</p>
</div>
);
})}
</div>
</div>
</div>
</React.Fragment>,
document.body
)
: null;
};

export default TransactionsHistory;

0 comments on commit 9c6ee56

Please sign in to comment.