From 707776f2b49fa5623437a1d5b93d4756b58c76a2 Mon Sep 17 00:00:00 2001 From: iamjc93 Date: Fri, 8 Mar 2024 12:28:44 +0800 Subject: [PATCH 1/6] update: rpc, added error catch --- .env | 1 + package.json | 3 ++- src/components/Pages/Block/index.jsx | 6 +++--- src/components/Pages/Home/index.jsx | 11 +++++++++++ src/hooks/useDynamicGlobalProperties.js | 5 ++++- src/hooks/useGetBlocks.js | 3 ++- src/utils/api.js | 3 ++- yarn.lock | 9 ++++++++- 8 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..90bf817 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +VITE_RPC= diff --git a/package.json b/package.json index 8286cf5..94d282c 100644 --- a/package.json +++ b/package.json @@ -8,13 +8,14 @@ }, "type": "module", "scripts": { - "dev": "vite --port 2020", + "dev": "vite --port 2021", "build": "vite build", "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0", "preview": "vite preview" }, "dependencies": { "axios": "^1.6.7", + "cross-env": "^7.0.3", "flowbite": "^2.3.0", "flowbite-react": "^0.7.2", "jdenticon": "^3.2.0", diff --git a/src/components/Pages/Block/index.jsx b/src/components/Pages/Block/index.jsx index 280e22c..7064b4b 100644 --- a/src/components/Pages/Block/index.jsx +++ b/src/components/Pages/Block/index.jsx @@ -14,7 +14,7 @@ const BlockPage = () => { loading, timestamp, count, - error, + blockError, } = useGetBlocks(headBlockNumber) const { headBlockNumber: lastestHeadBlockNumber, @@ -30,10 +30,10 @@ const BlockPage = () => { } - if (error) { + if (blockError) { return
-

{error}

+

{JSON.stringify(blockError)}

The latest head_block_number is {lastestHeadBlockNumber}

diff --git a/src/components/Pages/Home/index.jsx b/src/components/Pages/Home/index.jsx index 1444888..ab53ade 100644 --- a/src/components/Pages/Home/index.jsx +++ b/src/components/Pages/Home/index.jsx @@ -17,12 +17,14 @@ const HomePage = () => { currentHbdSupply, virtualSupply, loading: dynamicGlobalLoading, + dynamicGlobalError, } = useDynamicGlobalProperties() const { timestamp, transactions, loading: blockLoading, + blockError, } = useGetBlocks(headBlockNumber) if (dynamicGlobalLoading && blockLoading && !headBlockNumber) { @@ -33,6 +35,15 @@ const HomePage = () => {
} + if (dynamicGlobalError || blockError) { + return
+
+ {JSON.stringify(dynamicGlobalError)} + {JSON.stringify(blockError)} +
+
+ } + return (
diff --git a/src/hooks/useDynamicGlobalProperties.js b/src/hooks/useDynamicGlobalProperties.js index 3178a96..e7f1522 100644 --- a/src/hooks/useDynamicGlobalProperties.js +++ b/src/hooks/useDynamicGlobalProperties.js @@ -18,6 +18,7 @@ const handleGetDynamicGlobalProperties = async () => { const useDynamicGlobalProperties = () => { const [loading, setLoading] = useState(true) + const [error, setError] = useState(null) const [headBlockNumber, setHeadBlockNumber] = useState(null) const [headBlockId, setHeadBlockId] = useState(null) @@ -167,6 +168,7 @@ const useDynamicGlobalProperties = () => { setLoading(false) } catch (error) { console.error('Error fetching dynamic global properties:', error) + setError(error) setLoading(false) } } @@ -220,7 +222,8 @@ const useDynamicGlobalProperties = () => { maxRecurrentTransferEndDate, minRecurrentTransfersRecurrence, maxOpenRecurrentTransfers, - loading + loading, + dynamicGlobalError: error, } } diff --git a/src/hooks/useGetBlocks.js b/src/hooks/useGetBlocks.js index e4c1794..acb2106 100644 --- a/src/hooks/useGetBlocks.js +++ b/src/hooks/useGetBlocks.js @@ -74,6 +74,7 @@ const useGetBlocks = (headBlockNumber) => { setLoading(false) } catch (error) { console.error('Error fetching blocks:', error) + setError(error) setLoading(false) } } @@ -96,7 +97,7 @@ const useGetBlocks = (headBlockNumber) => { transactionIds, loading, count, - error, + blockError: error, } } diff --git a/src/utils/api.js b/src/utils/api.js index c00e872..3fc0846 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -1,7 +1,8 @@ // /utils/api.js // const BASE_URL = 'https://rpc.d.buzz/' // const BASE_URL = 'https://api.hive.blog' -const BASE_URL = 'https://rpc.d.buzz' +const BASE_URL = import.meta.env.VITE_RPC || 'https://api.hive.blog' + // Example function for making a GET request export const fetchData = async (endpoint) => { diff --git a/yarn.lock b/yarn.lock index c7d5554..7e28d03 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1822,7 +1822,14 @@ core-util-is@^1.0.3, core-util-is@~1.0.0: resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85" integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ== -cross-spawn@^7.0.0, cross-spawn@^7.0.2: +cross-env@^7.0.3: + version "7.0.3" + resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf" + integrity sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw== + dependencies: + cross-spawn "^7.0.1" + +cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2: version "7.0.3" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== From 3175af078861684aefd8df401fc1f2f0e0b857d0 Mon Sep 17 00:00:00 2001 From: iamjc93 Date: Fri, 8 Mar 2024 12:29:56 +0800 Subject: [PATCH 2/6] fix: dev --port --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 94d282c..8157dc0 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ }, "type": "module", "scripts": { - "dev": "vite --port 2021", + "dev": "vite --port 2020", "build": "vite build", "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0", "preview": "vite preview" From c109a82acfb1ca4a1701f600172beb1b437f4202 Mon Sep 17 00:00:00 2001 From: iamjc93 Date: Fri, 8 Mar 2024 12:35:35 +0800 Subject: [PATCH 3/6] fix: url 404 in netlify --- .env | 2 +- public/_redirects | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 public/_redirects diff --git a/.env b/.env index 90bf817..3d73cc5 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -VITE_RPC= +VITE_RPC=https://rpc.d.buzz/ diff --git a/public/_redirects b/public/_redirects new file mode 100644 index 0000000..ad37e2c --- /dev/null +++ b/public/_redirects @@ -0,0 +1 @@ +/* /index.html 200 From 3ecd220af5cac622f9a110ccd3fffd61c9a8c8f5 Mon Sep 17 00:00:00 2001 From: iamjc93 Date: Fri, 8 Mar 2024 12:38:05 +0800 Subject: [PATCH 4/6] fix: remove default rpc in .env --- .env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env b/.env index 3d73cc5..90bf817 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -VITE_RPC=https://rpc.d.buzz/ +VITE_RPC= From 79ad129ad8e7a32c1195152ce55cd3b6a2aaa6d6 Mon Sep 17 00:00:00 2001 From: iamjc93 Date: Fri, 8 Mar 2024 12:53:41 +0800 Subject: [PATCH 5/6] fix: curation reward undefined url and author, added svg icon --- public/vite.svg | 29 ++++++++++++++++++- .../Common/Operation/CurationReward/index.jsx | 8 +++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/public/vite.svg b/public/vite.svg index e7b8dfb..b91a5ff 100644 --- a/public/vite.svg +++ b/public/vite.svg @@ -1 +1,28 @@ - \ No newline at end of file + + + + + + + + + + + + + + + + diff --git a/src/components/Common/Operation/CurationReward/index.jsx b/src/components/Common/Operation/CurationReward/index.jsx index 224b415..b4ff267 100644 --- a/src/components/Common/Operation/CurationReward/index.jsx +++ b/src/components/Common/Operation/CurationReward/index.jsx @@ -5,8 +5,10 @@ import {Link} from "react-router-dom" const CurationReward = ({data, trx_id, timestamp, headBlockNumber}) => { const { + author, reward, curator, + permlink, comment_author, comment_permlink, // payout_must_be_claimed, @@ -14,6 +16,8 @@ const CurationReward = ({data, trx_id, timestamp, headBlockNumber}) => { totalVestingFundHive, } = data + console.log(data) + return
virtual @@ -22,8 +26,8 @@ const CurationReward = ({data, trx_id, timestamp, headBlockNumber}) => { {` curation reward: `} {vestToHive(reward, totalVestingShares, totalVestingFundHive).toFixed(3)} {` HP for `} - - {`@${comment_author}/${comment_permlink}`} + + {`@${comment_author || author}/${comment_permlink || permlink}`}
From f37a769c466773233a4b8df76e5710ef8c83b685 Mon Sep 17 00:00:00 2001 From: iamjc93 Date: Fri, 8 Mar 2024 13:06:04 +0800 Subject: [PATCH 6/6] fix: fill_order not displaying, curation reward, transfer --- .../Common/Operation/CommentReward/index.jsx | 2 +- .../Common/Operation/CurationReward/index.jsx | 2 - .../Common/Operation/FillOrder/index.jsx | 41 +++++++++++++++++++ .../Common/Operation/Transfer/index.jsx | 4 +- src/components/Common/Operation/index.jsx | 13 ++++++ 5 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 src/components/Common/Operation/FillOrder/index.jsx diff --git a/src/components/Common/Operation/CommentReward/index.jsx b/src/components/Common/Operation/CommentReward/index.jsx index e649391..a0ac148 100644 --- a/src/components/Common/Operation/CommentReward/index.jsx +++ b/src/components/Common/Operation/CommentReward/index.jsx @@ -19,7 +19,7 @@ const ClaimRewardBalance = ({data, trx_id, timestamp, headBlockNumber}) => {
{author} - comment_reward + {` comment_reward `} diff --git a/src/components/Common/Operation/CurationReward/index.jsx b/src/components/Common/Operation/CurationReward/index.jsx index b4ff267..bf8c007 100644 --- a/src/components/Common/Operation/CurationReward/index.jsx +++ b/src/components/Common/Operation/CurationReward/index.jsx @@ -16,8 +16,6 @@ const CurationReward = ({data, trx_id, timestamp, headBlockNumber}) => { totalVestingFundHive, } = data - console.log(data) - return
virtual diff --git a/src/components/Common/Operation/FillOrder/index.jsx b/src/components/Common/Operation/FillOrder/index.jsx new file mode 100644 index 0000000..1cddc7e --- /dev/null +++ b/src/components/Common/Operation/FillOrder/index.jsx @@ -0,0 +1,41 @@ +import PropTypes from "prop-types" +import {timeAgo} from "../../../../utils/helper.js" +import TrimTxId from "../../TrimTxId/index.jsx" +import {Link} from "react-router-dom" + +const FillOrder = ({data, trx_id, timestamp, headBlockNumber}) => { + + const { + open_pays, + open_owner, + current_pays, + // open_orderid, + current_owner, + // current_orderid, + } = data + + return
+ + +
+ {current_owner} + {` paid ${current_pays} for ${open_pays} from `} + {`${open_owner}`} +
+ +
+ + + +
+
+} + +FillOrder.propTypes = { + data: PropTypes.object.isRequired, + trx_id: PropTypes.string.isRequired, + timestamp: PropTypes.string.isRequired, + headBlockNumber: PropTypes.number.isRequired, +} + +export default FillOrder diff --git a/src/components/Common/Operation/Transfer/index.jsx b/src/components/Common/Operation/Transfer/index.jsx index 639fa0f..b1b1537 100644 --- a/src/components/Common/Operation/Transfer/index.jsx +++ b/src/components/Common/Operation/Transfer/index.jsx @@ -15,9 +15,9 @@ const Transfer = ({data, trx_id, timestamp, headBlockNumber}) => {
- {`@${from}`} + {from} {` transfer ${amount} to `} - {to} + {`@${to}`} {` `} {memo}
diff --git a/src/components/Common/Operation/index.jsx b/src/components/Common/Operation/index.jsx index badd551..6f09d05 100644 --- a/src/components/Common/Operation/index.jsx +++ b/src/components/Common/Operation/index.jsx @@ -18,6 +18,7 @@ import CreateClaimedAccount from "./CreateClaimedAccount/index.jsx" import LimitOrderCancel from "./LimitOrderCancel/index.jsx" import LimitOrderCreate from "./LimitOrderCreate/index.jsx" import WitnessSetProperties from "./WitnessSetProperties/index.jsx" +import FillOrder from "./FillOrder/index.jsx"; const Operation = ({ opType, @@ -30,6 +31,8 @@ const Operation = ({ totalVestingShares }) => { + console.log(opType, opData) + opData['totalVestingShares'] = totalVestingShares opData['totalVestingFundHive'] = totalVestingFundHive @@ -233,6 +236,16 @@ const Operation = ({ /> } + if (opType === 'fill_order') { + return + } + return

{opType}

}