diff --git a/src/BalanceShower.css b/src/BalanceShower.css new file mode 100644 index 0000000..4b5a918 --- /dev/null +++ b/src/BalanceShower.css @@ -0,0 +1,19 @@ +.balance-popover { + position: absolute; + top: 2em; + margin: auto; + left: 50%; + transform: translateX(-50%); + z-index: 1; +} + +.balance-value { + opacity: 0; + animation: balance-disappear 2s ease-in; +} + +@keyframes balance-disappear { + from {opacity: 1;} + 75% {opacity: 1;} + to {opacity: 0;} +} \ No newline at end of file diff --git a/src/BalanceShower.js b/src/BalanceShower.js new file mode 100644 index 0000000..86ebf52 --- /dev/null +++ b/src/BalanceShower.js @@ -0,0 +1,81 @@ +import React, {Component, PureComponent} from 'react'; +import {PKUHELPER_ROOT} from './infrastructure/const'; +import {API_VERSION_PARAM, get_json} from './flows_api'; +import {TokenCtx} from './UserAction'; + +import './BalanceShower.css'; + +export class BalanceShower extends PureComponent { + constructor(props) { + super(props); + this.state={ + loading_status: 'idle', + error: null, + balance: null, + }; + } + + do_load(token) { + if(this.state.loading_status==='loading') + return; + if(!token || !window.config.easter_egg) { + this.setState({ + loading_status: 'idle', + }); + return; + } + + this.setState({ + loading_status: 'loading', + },()=>{ + fetch( + PKUHELPER_ROOT+'api_xmcp/isop/card_balance' + +'?user_token='+encodeURIComponent(token) + +API_VERSION_PARAM() + ) + .then(get_json) + .then((json)=>{ + console.log(json); + if(!json.success) + throw new Error(JSON.stringify(json)); + + this.setState({ + loading_status: 'done', + error: null, + balance: json.balance, + }); + }) + .catch((e)=>{ + console.error(e); + this.setState({ + loading_status: 'error', + error: ''+e, + }); + }); + }) + } + + render_popover() { + if(this.state.loading_status==='idle') // no token or disabled + return null; + else if(this.state.loading_status==='loading') + return (
This program is free software: you can redistribute it and/or modify @@ -186,11 +187,13 @@ export function Title(props) {
- P大树洞 -
-+ P大树洞 +
+