Skip to content

Commit

Permalink
Merge pull request #233 from tronprotocol/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
unicornonea authored Jan 27, 2022
2 parents 5fe79d5 + fc0a16f commit 80975e7
Show file tree
Hide file tree
Showing 17 changed files with 224 additions and 112 deletions.
18 changes: 6 additions & 12 deletions demo/tron-dapp-react-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,11 @@
"version": "1.0.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.1",
"web-vitals": "^0.2.4",
"@ant-design/icons": "^4.7.0",
"antd": "^4.8.3",
"axios": "^0.21.0",
"bignumber.js": "^9.0.1",
"cross-env": "^7.0.2",
"customize-cra": "^1.0.0",
"echarts": "^4.9.0",
"echarts-for-react": "^2.0.16",
"husky": "^4.3.0",
"ismobilejs": "^1.1.1",
"lint-staged": "^10.5.0",
Expand All @@ -25,13 +16,16 @@
"mobx-react": "^6.2.2",
"prettier": "^2.1.2",
"qrcode.react": "^1.0.0",
"react": "^16.8.0 || 16.9.0-alpha.0",
"react-app-rewired": "^2.1.6",
"react-countup": "^4.3.3",
"react-dom": "^16.0.1",
"react-intl-universal": "^2.2.5",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.1",
"sass": "^1.26.8",
"styled-components": "^5.2.1",
"tronweb": "^3.2.3"
"tronweb": "^4.1.0",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "PORT=18113 cross-env REACT_APP_ENV=test react-app-rewired start",
Expand Down
43 changes: 43 additions & 0 deletions demo/tron-dapp-react-demo/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="tronweb demo"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>TronWeb Demo</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root" class="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
7 changes: 4 additions & 3 deletions demo/tron-dapp-react-demo/src/assets/css/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ button,
}

@font-face {
font-family: 'Roboto';
src: url('../font/Roboto/Roboto-Black.ttf');
src: url('../font/Roboto/Roboto-Black.ttf') format('truetype');
// font-family: 'Roboto';
// src: url('../font/Roboto/Roboto-Black.ttf');
// src: url('../font/Roboto/Roboto-Black.ttf') format('truetype');
}

body {
Expand Down Expand Up @@ -185,6 +185,7 @@ body {
margin: auto;
width: 85px;
}

.main-content {
margin-left: 220px;
padding: 30px;
Expand Down
54 changes: 54 additions & 0 deletions demo/tron-dapp-react-demo/src/components/Header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
import isMobile from 'ismobilejs';
import intl from 'react-intl-universal';
import { inject, observer } from 'mobx-react';
import { Link } from 'react-router-dom';
import { Layout, Select, Menu, Modal, Drawer, Tooltip, Popover, Button } from 'antd';

import { cutMiddle, copyToClipboard } from '../utils/helper';
import '../assets/css/header.scss';
import walletSuccess from '../assets/images/walletSuccess.svg';
import walletFail from '../assets/images/walletFail.svg';
import logoSingle from '../assets/images/mainLogo.png';
import tronlink from '../assets/images/tronlinkLogo.svg';
import tronlinkBlue from '../assets/images/tronlinkBlue.svg';
import tronlinkRightArrow from '../assets/images/tronlinkRightArrow.svg';
import { PieChartOutlined, DesktopOutlined, ContainerOutlined } from '@ant-design/icons';

const { Option } = Select;
const { SubMenu } = Menu;

@inject('network')
@observer
class LeftMenu extends React.Component {
constructor(props) {
super(props);
this.state = {};
}

componentDidMount() {
this.props.instantActions && this.props.instantActions(); // should excute when componentDidMount, we need not check if a user logined or not
if (!this.props.network.isConnected) {
this.props.network.initTronLinkWallet(
() => {
this.props.mountedActions && this.props.mountedActions();
},
() => {
// if a user do not login TronLink wallet, we should do something
this.props.unmountedActions && this.props.unmountedActions();
}
);
} else {
this.props.mountedActions && this.props.mountedActions();
}
// when a user change a node or change a account or change a chain type,
// we shoule listen TronLink to reload the webpage to get new account info
this.props.network.listenTronLink();
}

render() {
return <></>;
}
}

export default LeftMenu;
30 changes: 30 additions & 0 deletions demo/tron-dapp-react-demo/src/components/Home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import { inject, observer } from 'mobx-react';
import HeaderPage from './Header';
import UserList from './UserList';

@inject('dapp')
@observer
class Home extends React.Component {
constructor(props) {
super(props);
this.state = {};
}

componentDidMount = async () => {};

mountedActions = async () => {
await this.props.dapp.getUserList();
};

render() {
return (
<div>
<HeaderPage mountedActions={this.mountedActions} />
<UserList />
</div>
);
}
}

export default Home;
2 changes: 1 addition & 1 deletion demo/tron-dapp-react-demo/src/components/UserList.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class UserList extends React.Component {
title: intl.get('table.balance'),
dataIndex: 'balance',
key: '3',
render: (text, item) => <span> {formatNumber({ text })}</span>
render: (text, item) => <span> {isNaN(text) ? '--' : formatNumber({ text })}</span>
},
{
title: intl.get('table.transfer'),
Expand Down
4 changes: 4 additions & 0 deletions demo/tron-dapp-react-demo/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const Config = {
privateKey: '01',
fullHost: 'https://api.trongrid.io'
},
trongrid: {
host: 'https://api.trongrid.io',
key: 'xxxxxx'
},
service: {},
contract: {
usdt: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'
Expand Down
35 changes: 1 addition & 34 deletions demo/tron-dapp-react-demo/src/locales/en-US.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,10 @@
{
"navi": {
"wallet_linkbtn": "Connect Wallet",
"index_btn": "Home",
"index_btn1": "Home1",
"index_btn2": "Home2",
"white_paper": "Whitepaper",
"report": "Audit Report",
"twitter": "Twitter",
"telegram": "Telegram",
"help": "Help"
},
"login_modal": {
"tronlink": "TronLink Wallet",
"no_tronlink_tip": {
"tip1": "Haven't installed TronLink yet?",
"tip2": "Click here>>"
},
"initializing": "Initializing...",
"login_tips": "Go to <a href='https://chrome.google.com/webstore/detail/tronlink%EF%BC%88%E6%B3%A2%E5%AE%9D%E9%92%B1%E5%8C%85%EF%BC%89/ibnejdfjmmkpcnlpebklmnkoeoihofec'>TronLink Wallet</a> for connection."
},
"account_modal": {
"account": "Account",
"connect_with_tronlink": "Connected with TronLink",
"copy": "Copy",
"copied": "Copied"
},
"wallet": {
"accept_tips": "Choosing to connect indicates that you have accepted",
"service": "Terms of Use",
"privacy": "Privacy Policy",
"no_wallet": "No TronLink Wallet?",
"click_to_get": "Click to download TronLink",
"authorize_justlend": "You need to confirm in your wallet for connection to JustLend",
"use_justlend": "Please connect to TronLink wallet to use JustLend"
},
"deposit": {
"deposit": "Supply",
"withdraw": "Withdraw",
Expand Down Expand Up @@ -69,9 +40,5 @@
"to": "Recieve Address",
"confirm": "Transfer"
},
"no_data": "No Data",
"footer": {
"audit": "Audit Report",
"develop": "API Doc"
}
"no_data": "No Data"
}
35 changes: 1 addition & 34 deletions demo/tron-dapp-react-demo/src/locales/zh-CN.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,10 @@
{
"navi": {
"wallet_linkbtn": "连接钱包",
"index_btn": "首页",
"index_btn1": "首页1",
"index_btn2": "首页2",
"white_paper": "白皮书",
"report": "审计报告",
"twitter": "推特",
"telegram": "电报",
"help": "帮助"
},
"login_modal": {
"tronlink": "TronLink 钱包",
"no_tronlink_tip": {
"tip1": "还没安装 TronLink?",
"tip2": "请点击此处>>"
},
"initializing": "正在初始化...",
"login_tips": "请使用 <a href='https://chrome.google.com/webstore/detail/tronlink%EF%BC%88%E6%B3%A2%E5%AE%9D%E9%92%B1%E5%8C%85%EF%BC%89/ibnejdfjmmkpcnlpebklmnkoeoihofec'>TronLink 钱包 </a>进行连接"
},
"account_modal": {
"account": "账户",
"connect_with_tronlink": "已连接 TronLink",
"copy": "复制",
"copied": "已复制"
},
"wallet": {
"accept_tips": "连接则代表您已接受",
"service": "服务条款",
"privacy": "隐私协议",
"no_wallet": "还没有TronLink钱包?",
"click_to_get": "点击获取",
"authorize_justlend": "您需要在钱包中确认以连接JustLend",
"use_justlend": "请连接钱包以开始使用JustLend"
},
"deposit": {
"deposit": "存款",
"withdraw": "提现",
Expand Down Expand Up @@ -69,9 +40,5 @@
"to": "接受地址",
"confirm": "确认"
},
"no_data": "无数据",
"footer": {
"audit": "审计报告",
"develop": "API文档"
}
"no_data": "无数据"
}
14 changes: 14 additions & 0 deletions demo/tron-dapp-react-demo/src/routes/Home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { inject, observer } from 'mobx-react';

import HomePage from '../components/Home';

@inject('network')
@observer
class Home extends React.Component {
render() {
return <HomePage />;
}
}

export default Home;
8 changes: 1 addition & 7 deletions demo/tron-dapp-react-demo/src/stores/dapp.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import React from 'react';
import { observable } from 'mobx';
import { notification } from 'antd';
import intl from 'react-intl-universal';
import Config from '../config';
import { tronscanTX } from '../utils/helper';
import Tip from '../components/Tip';
import { getUserList } from '../utils/backend';
export default class NetworkStore {
@observable userList = [];
Expand All @@ -20,7 +14,7 @@ export default class NetworkStore {
};

getUserList = async () => {
const account = this.rootStore.network.defaultAccount;
const account = window.defaultAccount;
if (!account) return;
const res = await getUserList(account);
if (!res.success) return;
Expand Down
4 changes: 0 additions & 4 deletions demo/tron-dapp-react-demo/src/stores/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { observable } from 'mobx';

import NetworkStore from './network';
import System from './system';
import Dapp from './dapp';

import Config from '../config';

class RootStore {
constructor() {
this.network = new NetworkStore(this);
Expand Down
Loading

0 comments on commit 80975e7

Please sign in to comment.