diff --git a/.eslintrc b/.eslintrc
index 5d65c0e..cad14c2 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -1,10 +1,26 @@
{
- "extends": ["taro"],
+ "extends": [
+ "taro"
+ ],
"rules": {
- "no-unused-vars": ["error", { "varsIgnorePattern": "Taro" }],
- "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx", ".tsx"] }]
+ "no-unused-vars": [
+ "error",
+ {
+ "varsIgnorePattern": "Taro"
+ }
+ ],
+ "react/jsx-filename-extension": [
+ 1,
+ {
+ "extensions": [
+ ".js",
+ ".jsx",
+ ".tsx"
+ ]
+ }
+ ]
},
- "parser": "@typescript-eslint/parser",
+ "parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
@@ -12,4 +28,4 @@
"useJSXTextNode": true,
"project": "./tsconfig.json"
}
- }
+}
diff --git a/src/app.scss b/src/app.scss
index 019c0ae..29f635e 100644
--- a/src/app.scss
+++ b/src/app.scss
@@ -8,4 +8,14 @@
.flex-item{
flex-grow: 1;
text-align: center;
-}
\ No newline at end of file
+}
+
+.page {
+ position: relative;
+ background-color: #FDFDFD;
+
+ view,
+ div {
+ box-sizing: border-box;
+ }
+}
diff --git a/src/app.tsx b/src/app.tsx
index 67e41e2..65ce6d4 100644
--- a/src/app.tsx
+++ b/src/app.tsx
@@ -9,9 +9,9 @@ import './app.scss'
// 如果需要在 h5 环境中开启 React Devtools
// 取消以下注释:
-if (process.env.NODE_ENV !== 'production' && process.env.TARO_ENV === 'h5') {
- require('nerv-devtools')
-}
+// if (process.env.NODE_ENV !== 'production' && process.env.TARO_ENV === 'h5') {
+// require('nerv-devtools')
+// }
const app = dva.createApp({
initialState: {},
diff --git a/src/models/index.ts b/src/models/index.ts
index 34b91fe..e74e9f3 100644
--- a/src/models/index.ts
+++ b/src/models/index.ts
@@ -1,2 +1,3 @@
import Index from '../pages/index/model'
-export default [Index];
+import My from '../pages/my/model'
+export default [Index, My];
diff --git a/src/models/types.ts b/src/models/types.ts
index 319498c..df397bd 100644
--- a/src/models/types.ts
+++ b/src/models/types.ts
@@ -1,3 +1,18 @@
+/**
+ * @type P: Type of payload
+ * @type C: Type of callback
+ */
+export type Dispatch =
void>(action: {
+ type: string;
+ payload?: P;
+ callback?: C;
+ [key: string]: any;
+}) => any;
+
+export interface DefaultProps {
+ dispatch: Dispatch
+}
+
export interface DefaultModel {
namespace: string,
state: T,
diff --git a/src/models/utils.ts b/src/models/utils.ts
new file mode 100644
index 0000000..2e0b241
--- /dev/null
+++ b/src/models/utils.ts
@@ -0,0 +1,6 @@
+let mapDefaultProps = ({ def }) => ({ ...def })
+
+export {
+ mapDefaultProps
+}
+
diff --git a/src/pages/index/index.scss b/src/pages/index/index.scss
index a43c752..6792ec6 100644
--- a/src/pages/index/index.scss
+++ b/src/pages/index/index.scss
@@ -1,13 +1,3 @@
-.page {
- position: relative;
- background-color: #FDFDFD;
-
- view,
- div {
- box-sizing: border-box;
- }
-}
-
.page-index {
padding: 0 0 30px;
diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx
index c6b47c6..f1d300a 100644
--- a/src/pages/index/index.tsx
+++ b/src/pages/index/index.tsx
@@ -1,18 +1,23 @@
-import { AtCard, AtNoticebar } from 'taro-ui'
import { connect } from '@tarojs/redux';
-import { View, Image } from '@tarojs/components'
-import Taro, { Component, Config } from '@tarojs/taro'
+import { AtCard, AtNoticebar } from 'taro-ui';
+import { View, Image } from '@tarojs/components';
+import Taro, { Component, Config } from '@tarojs/taro';
-import './index.scss'
-import logoImg from '../../assets/images/logo.png'
-import { IndexProps } from './type';
+import logoImg from '../../assets/images/logo.png';
+import { mapDefaultProps } from '../../models/utils';
-@connect(({ index }): IndexProps => ({ ...index }))
-export default class Index extends Component {
+import './index.scss';
+import { IndexProps, IndexState } from './type';
+
+@connect(mapDefaultProps)
+export default class Index extends Component {
config: Config = {
navigationBarTitleText: '首页',
enablePullDownRefresh: true
}
+ state = {
+ notify: '通知: 钱包目前处于测试阶段 如果发现BUG 请及时反馈!'
+ }
componentDidMount() {
Taro.startPullDownRefresh();
@@ -25,26 +30,27 @@ export default class Index extends Component {
}
render() {
- const {
- data
- } = this.props
+ const data = this.props
+ const info = (
+
+ 软件版本: {data.version}
+ 当前高度: {data.block}
+ 流通数量: {data.supply}
+ 百 分 比: {data.percent}
+ 当前收益: {data.lastNumber}
+ 来 自: {data.lastMiner} {data.lastName}
+
+ )
return (
- 通知: 钱包目前处于测试阶段 如果发现BUG 请及时反馈!
+ {this.state.notify}
泰瑞管家
-
- 软件版本: {data.version}
- 当前高度: {data.block}
- 流通数量: {data.supply}
- 百 分 比: {data.percent}
- 当前收益: {data.lastMiner}
- 来 自: {data.lastNumber} {data.lastName}
-
+ {info}
)
}
diff --git a/src/pages/index/model.ts b/src/pages/index/model.ts
index 2a66436..8a61af1 100644
--- a/src/pages/index/model.ts
+++ b/src/pages/index/model.ts
@@ -1,33 +1,30 @@
-import { getInfo } from './service'
-import { DefaultModel } from 'src/models/types';
-import { IndexProps } from './type';
+import { DefaultModel } from '../../models/types';
+
+import { getInfo } from './service';
+import { IndexModel } from './type';
export default {
namespace: 'index',
state: {
- data: {
- version: 0,
- block: 0,
- supply: 0,
- percent: '0.00',
- lastMiner: 0,
- lastName: 'system',
- lastNumber: 0,
- }
+ version: 0,
+ block: 0,
+ supply: 0,
+ percent: '0.00',
+ lastMiner: 0,
+ lastName: 'system',
+ lastNumber: 0,
},
effects: {
*getCurrentInfo({ }, { call, put }) {
let info = yield call(getInfo);
yield put({
- type: "setState", payload: {
- data: info
- }
+ type: "setState", payload: info
});
}
},
reducers: {
- setState(state: IndexProps, { payload }) {
+ setState(state: IndexModel, { payload }) {
return { ...state, ...payload }
}
}
-} as DefaultModel
+} as DefaultModel
diff --git a/src/pages/index/service.ts b/src/pages/index/service.ts
index 64fdeab..4d2abfe 100644
--- a/src/pages/index/service.ts
+++ b/src/pages/index/service.ts
@@ -1,7 +1,8 @@
-import { getCurrentInfo, getBlockInfo, getAccount, getHistoryTransactions } from '../../rpc/tera'
-import coinKit from '../../utils/coin-kit'
import Taro from '@tarojs/taro';
+import coinKit from '../../utils/coin-kit'
+import { getCurrentInfo, getBlockInfo, getAccount, getHistoryTransactions } from '../../rpc/tera'
+
const MAX_CENT = 1e9
async function getInfo() {
diff --git a/src/pages/index/type.ts b/src/pages/index/type.ts
index c6fb7a0..d6ae40b 100644
--- a/src/pages/index/type.ts
+++ b/src/pages/index/type.ts
@@ -1,8 +1,8 @@
-export interface IndexProps {
- dispatch?: any,
- data: IndexData
-}
-export interface IndexData {
+import { DefaultProps } from "../../models/types";
+
+export type IndexProps = IndexModel & DefaultProps
+
+export interface IndexModel {
version: number;
block: number;
supply: number;
@@ -11,3 +11,6 @@ export interface IndexData {
lastName: string;
lastNumber: number;
}
+export interface IndexState {
+ notify: string
+}
diff --git a/src/pages/my/index.scss b/src/pages/my/index.scss
index d16a038..f3021b6 100644
--- a/src/pages/my/index.scss
+++ b/src/pages/my/index.scss
@@ -31,4 +31,12 @@
line-height: 34px;
}
}
-}
\ No newline at end of file
+}
+
+.my {
+ padding: 30px;
+}
+
+.account {
+ margin-top: 30px;
+}
diff --git a/src/pages/my/index.tsx b/src/pages/my/index.tsx
index 096ea18..91ffaef 100644
--- a/src/pages/my/index.tsx
+++ b/src/pages/my/index.tsx
@@ -1,36 +1,106 @@
-import Taro, { Component, Config } from '@tarojs/taro'
-import { View, Text, Image } from '@tarojs/components'
-import defaultImage from '../../assets/images/logo.png'
-import './index.scss'
+import { connect } from '@tarojs/redux';
+import { AtList, AtListItem } from 'taro-ui';
+import Taro, { Component, Config } from '@tarojs/taro';
+import { View, Text, Image } from '@tarojs/components';
-class Index extends Component {
- config: Config = {
- navigationBarTitleText: '个人中心',
- disableScroll: true
- }
- state = {
- nickName: 'MiaoWoo',
- avatarUrl: defaultImage
- }
- render() {
- const {
- nickName,
- avatarUrl
- } = this.state;
- return (
-
-
-
-
-
-
- {nickName}
- 查看或编辑个人主页
-
-
-
- )
+import coinKit from '../../utils/coin-kit';
+import { mapDefaultProps } from '../../models/utils';
+import defaultImage from '../../assets/images/logo.png';
+
+import './index.scss';
+import { MyIndexProps, MyState } from './type';
+
+@connect(mapDefaultProps)
+class Index extends Component {
+ config: Config = {
+ navigationBarTitleText: '个人中心',
+ enablePullDownRefresh: true
+ }
+ state = {
+ nickName: 'MiaoWoo',
+ avatarUrl: defaultImage,
+ }
+
+ onPullDownRefresh() {
+ const { dispatch } = this.props;
+ if (dispatch) {
+ dispatch({
+ type: 'my/getAccounts',
+ playload: '02078AC7F16BAF88F9A6F8FA05D5C9F697596402D9EB774A36C74E52A3470EA85B'
+ })
}
+ }
+
+ componentDidMount() {
+ Taro.startPullDownRefresh();
+ }
+
+ render() {
+ const {
+ nickName,
+ avatarUrl
+ } = this.state;
+ const accounts = this.props.accounts.map(a => {
+ return
+ })
+ return (
+
+
+
+
+
+
+ {nickName}
+ 查看或编辑个人主页
+
+
+
+
+
+
+
+
+
+
+ {accounts}
+
+
+
+
+ )
+ }
}
-export default Index
\ No newline at end of file
+export default Index
diff --git a/src/pages/my/model.ts b/src/pages/my/model.ts
new file mode 100644
index 0000000..3495653
--- /dev/null
+++ b/src/pages/my/model.ts
@@ -0,0 +1,24 @@
+import { DefaultModel } from '../../models/types';
+
+import { getAccounts } from './service';
+import { MyProps } from './type';
+
+export default {
+ namespace: 'my',
+ state: {
+ accounts: []
+ },
+ effects: {
+ *['getAccounts']({ playload }, { call, put }) {
+ let accounts = yield call(getAccounts, playload);
+ yield put({
+ type: "setState", playload: accounts
+ });
+ }
+ },
+ reducers: {
+ setState(state: MyProps, { playload }) {
+ return { ...state, ...playload }
+ }
+ }
+} as DefaultModel
diff --git a/src/pages/my/service.ts b/src/pages/my/service.ts
new file mode 100644
index 0000000..003aaa7
--- /dev/null
+++ b/src/pages/my/service.ts
@@ -0,0 +1,15 @@
+import Taro from '@tarojs/taro';
+
+import { getAccountListByKey } from '../../rpc/tera';
+
+async function getAccounts(key: string) {
+ Taro.showLoading({
+ title: '加载中...'
+ })
+ let result = await getAccountListByKey(key);
+ Taro.hideLoading()
+ Taro.stopPullDownRefresh()
+ return { accounts: result };
+}
+
+export { getAccounts }
diff --git a/src/pages/my/type.ts b/src/pages/my/type.ts
new file mode 100644
index 0000000..b984068
--- /dev/null
+++ b/src/pages/my/type.ts
@@ -0,0 +1,12 @@
+import { Account } from '../../rpc/types';
+import { DefaultProps } from '../../models/types';
+
+export type MyIndexProps = MyProps & DefaultProps
+
+export interface MyProps {
+ accounts: Account[];
+}
+export interface MyState {
+ nickName: string;
+ avatarUrl: any;
+}
diff --git a/src/rpc/index.ts b/src/rpc/index.ts
index 43ffe6d..5ab091b 100644
--- a/src/rpc/index.ts
+++ b/src/rpc/index.ts
@@ -1,4 +1,4 @@
-import Taro from "@tarojs/taro";
+import Taro from '@tarojs/taro';
let host = 'https://teraapi.sixi.com'
@@ -15,7 +15,7 @@ function printRequest(method: string, path: string, data: any, response: any, co
function showError(content) {
Taro.showModal({
- title: "网络请求错误",
+ title: '网络请求错误',
content,
showCancel: false
})
diff --git a/src/rpc/tera.ts b/src/rpc/tera.ts
index 1192866..fb31adc 100644
--- a/src/rpc/tera.ts
+++ b/src/rpc/tera.ts
@@ -1,4 +1,4 @@
-import rpc from './index'
+import rpc from './index';
import { BlockInfo, CurrentInfo, Account } from './types';
async function getCurrentInfo(): Promise {
@@ -29,9 +29,18 @@ async function getHistoryTransactions(id: number, count: number = 3, getDes: num
return result.History;
}
+async function getAccountListByKey(key: string): Promise {
+ let result = await rpc.get('/api/v1/GetAccountListByKey', {
+ Key: key,
+ AllData: 1
+ })
+ return result.arr;
+}
+
export {
getAccount,
getCurrentInfo,
getBlockInfo,
- getHistoryTransactions
+ getHistoryTransactions,
+ getAccountListByKey
}
diff --git a/src/utils/time-kit.ts b/src/utils/time-kit.ts
index 1cb838f..72df314 100644
--- a/src/utils/time-kit.ts
+++ b/src/utils/time-kit.ts
@@ -1,29 +1,25 @@
-import i18n from '@/i18n/index.js'
-
function formatShortTime(time, count = 4) {
- const t = Math.floor(time / 86400);
- const h = Math.floor((time / 3600) % 24);
- const m = Math.floor((time / 60) % 60);
- const s = Math.floor(time % 60);
- var timeStr = '';
- if (t > 0) {
- timeStr = timeStr + t + '天';
- count--;
- }
- if (h > 0 && count > 0) {
- timeStr = timeStr + h + '时';
- count--;
- }
- if (m > 0 && count > 0) {
- timeStr = timeStr + m + '分';
- count--;
- }
- if (count > 0) {
- timeStr = timeStr + s + '秒';
- }
- return timeStr;
+ const t = Math.floor(time / 86400);
+ const h = Math.floor((time / 3600) % 24);
+ const m = Math.floor((time / 60) % 60);
+ const s = Math.floor(time % 60);
+ var timeStr = '';
+ if (t > 0) {
+ timeStr = timeStr + t + '天';
+ count--;
+ }
+ if (h > 0 && count > 0) {
+ timeStr = timeStr + h + '时';
+ count--;
+ }
+ if (m > 0 && count > 0) {
+ timeStr = timeStr + m + '分';
+ count--;
+ }
+ if (count > 0) {
+ timeStr = timeStr + s + '秒';
+ }
+ return timeStr;
}
-module.exports = {
- formatShortTime
-}
+export { formatShortTime }