Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
ycc-website
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Website
ycc-website
Commits
33c0a4e8
Commit
33c0a4e8
authored
Mar 03, 2022
by
chenqikuai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf:优化网络请求,请求成功后再进行请求
parent
0edca08d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
19 deletions
+52
-19
blockChainBrowser.ts
src/mixin/blockChainBrowser.ts
+36
-19
common.ts
src/utils/common.ts
+16
-0
No files found.
src/mixin/blockChainBrowser.ts
View file @
33c0a4e8
...
...
@@ -16,6 +16,13 @@ import {
import
{
icustomizedTx
}
from
"@/types/trade"
;
import
{
getNodeNum
}
from
"@/service/blockChainBrowser"
;
import
{
clearTimeoutFromTimerObj
,
registerTimeoutToTimerObj
,
}
from
"@/utils/common"
;
const
TimerObj
=
{}
as
{
[
key
:
string
]:
number
};
const
__timeout
=
10
*
1
e3
;
export
default
Vue
.
extend
({
data
()
{
...
...
@@ -42,26 +49,22 @@ export default Vue.extend({
this
.
fetchTpsData
();
this
.
init
();
this
.
fetchLatestTxListData
();
getNodeNum
().
then
((
res
)
=>
{
if
(
res
.
error
===
null
)
{
this
.
nodeNum
=
(
res
.
result
.
countries
||
[]).
reduce
((
prev
,
cur
)
=>
{
return
prev
+
cur
.
value
;
},
0
);
}
});
this
.
timer
=
window
.
setInterval
(()
=>
{
this
.
fetchAllPos33TicketCountData
();
this
.
fetchAccountCountData
();
this
.
fetchTpsData
();
this
.
init
();
this
.
fetchLatestTxListData
();
},
15
*
1000
);
this
.
fetchNodeNum
();
},
beforeDestroy
()
{
window
.
clearInterval
(
this
.
timer
);
clearTimeoutFromTimerObj
(
TimerObj
);
},
methods
:
{
fetchNodeNum
()
{
getNodeNum
().
then
((
res
)
=>
{
if
(
res
.
error
===
null
)
{
this
.
nodeNum
=
(
res
.
result
.
countries
||
[]).
reduce
((
prev
,
cur
)
=>
{
return
prev
+
cur
.
value
;
},
0
);
registerTimeoutToTimerObj
(
TimerObj
,
this
.
fetchNodeNum
,
__timeout
);
}
});
},
fetchTpsData
()
{
getTxCountBewteenTimes
(
moment
().
unix
(),
...
...
@@ -71,6 +74,7 @@ export default Vue.extend({
).
then
((
res
)
=>
{
if
(
res
.
error
===
null
)
{
this
.
tps
=
Number
((
res
.
result
/
(
24
*
60
*
60
)).
toFixed
(
2
));
registerTimeoutToTimerObj
(
TimerObj
,
this
.
fetchTpsData
,
__timeout
);
}
});
},
...
...
@@ -87,6 +91,11 @@ export default Vue.extend({
amount
:
i
.
amount
,
success
:
i
.
success
,
}));
registerTimeoutToTimerObj
(
TimerObj
,
this
.
fetchLatestTxListData
,
__timeout
);
}
});
},
...
...
@@ -94,6 +103,11 @@ export default Vue.extend({
getAccountCount
().
then
((
ret
)
=>
{
if
(
ret
.
error
===
null
)
{
this
.
addressNumber
=
ret
.
result
;
registerTimeoutToTimerObj
(
TimerObj
,
this
.
fetchAccountCountData
,
__timeout
);
}
});
},
...
...
@@ -101,6 +115,11 @@ export default Vue.extend({
getAllPos33TicketCount
().
then
((
ret
)
=>
{
if
(
ret
.
error
===
null
)
{
this
.
ticketCount
=
ret
.
result
;
registerTimeoutToTimerObj
(
TimerObj
,
this
.
fetchAllPos33TicketCountData
,
__timeout
);
}
});
},
...
...
@@ -111,9 +130,6 @@ export default Vue.extend({
const
lastBlock
=
res
.
result
[
1
];
const
perTime
=
(
lastBlock
.
time
-
fatherBlock
.
time
)
/
(
this
.
latestHeight
-
725000
);
// const perTxCount =
// (lastBlock.tx_count - fatherBlock.tx_count) /
// (lastBlock.time - fatherBlock.time);
this
.
speed
=
Number
(
perTime
.
toFixed
(
2
));
}
});
...
...
@@ -186,6 +202,7 @@ export default Vue.extend({
const
totalFeeRet
=
await
getRpc
(
yccApi
).
queryTotalFee
([
str
]);
if
(
!
totalFeeRet
.
error
)
{
this
.
totalTx
=
totalFeeRet
.
result
.
txCount
;
registerTimeoutToTimerObj
(
TimerObj
,
this
.
init
,
__timeout
);
}
}
},
...
...
src/utils/common.ts
View file @
33c0a4e8
...
...
@@ -60,3 +60,19 @@ const nFormatter = (num: number, digits = 2) => {
};
export
{
tradeAccuracy
,
nFormatter
};
export
const
registerTimeoutToTimerObj
=
(
TimerObj
:
{
[
key
:
string
]:
number
},
func
:
()
=>
any
,
delay
:
number
)
=>
{
TimerObj
[
func
.
name
]
=
window
.
setTimeout
(()
=>
{
func
();
},
delay
);
};
export
const
clearTimeoutFromTimerObj
=
(
TimerObj
:
{
[
key
:
string
]:
number
;
})
=>
{
Object
.
values
(
TimerObj
).
forEach
((
timer
)
=>
window
.
clearTimeout
(
timer
));
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment