├── public
├── robots.txt
├── favicon.ico
├── logoReact192.png
├── logoReact512.png
├── logoTronlink192.png
├── logoTronlink512.png
├── manifest.json
└── index.html
├── src
├── Screenshot.png
├── App.test.js
├── index.js
├── index.css
├── App.css
├── App.js
├── logo.svg
└── background.svg
├── .gitignore
├── README.md
└── package.json
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ibnzUK/Tron-Wallet-React-Integration/HEAD/public/favicon.ico
--------------------------------------------------------------------------------
/src/Screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ibnzUK/Tron-Wallet-React-Integration/HEAD/src/Screenshot.png
--------------------------------------------------------------------------------
/public/logoReact192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ibnzUK/Tron-Wallet-React-Integration/HEAD/public/logoReact192.png
--------------------------------------------------------------------------------
/public/logoReact512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ibnzUK/Tron-Wallet-React-Integration/HEAD/public/logoReact512.png
--------------------------------------------------------------------------------
/public/logoTronlink192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ibnzUK/Tron-Wallet-React-Integration/HEAD/public/logoTronlink192.png
--------------------------------------------------------------------------------
/public/logoTronlink512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ibnzUK/Tron-Wallet-React-Integration/HEAD/public/logoTronlink512.png
--------------------------------------------------------------------------------
/src/App.test.js:
--------------------------------------------------------------------------------
1 | import { render, screen } from '@testing-library/react';
2 | import App from './App';
3 |
4 | test('renders learn react link', () => {
5 | render();
6 | const linkElement = screen.getByText(/learn react/i);
7 | expect(linkElement).toBeInTheDocument();
8 | });
9 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import './index.css';
4 | import App from './App';
5 |
6 | ReactDOM.render(
7 |
8 |
9 | ,
10 | document.getElementById('root')
11 | );
12 |
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | font-family:monospace ;
4 | -webkit-font-smoothing: antialiased;
5 | -moz-osx-font-smoothing: grayscale;
6 | }
7 |
8 |
9 | html {
10 | background: url(./background.svg) no-repeat center center fixed;
11 | -webkit-background-size: cover;
12 | -moz-background-size: cover;
13 | -o-background-size: cover;
14 | background-size: cover;
15 | }
16 |
17 | html,
18 | body {
19 | min-height: 100%;
20 | }
21 |
--------------------------------------------------------------------------------
/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "Tronlink React Integration",
3 | "name": "Create React, Tronlink Wallet App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logoTronlink192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logoTronlink512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TRON WALLET & REACT INTEGRATION
2 |
3 | 
4 |
5 |
6 | DEMO - https://wallet-link.ibnz.dev/
7 |
8 |
9 | This is a React application to fetch and display details from TRON Blockchain wallets (Tronlink, Klever). This should help community developers, who are building decentralised applications, to establish a link and communication with Tron Blockchain.
10 |
11 | ## Community coders, please commit
12 |
13 | Feel free to add extra functions or improvements, this helps me to familiarise myself with source control and open source project managing. By contributing, you also help to build yet another open-source tool on TRON Network.
14 |
15 | -----
16 | ## Tested Wallets
17 |
18 | - KLEVER - https://klever.io/en/
19 | - TronLink - https://www.tronlink.org/
20 |
21 |
22 |
23 | ## Running instructions
24 |
25 | - Copy project to your directory ( git clone https://github.com/ibnzUK/Ton-Wallet-React-Integration )
26 | - navigate to _Ton-Wallet-React-Integration_ project directory
27 | - make sure you have node.js installed on your machine
28 | - install project packages (npm install)
29 | - start a project (npm run start)
30 |
31 |
--------------------------------------------------------------------------------
/src/App.css:
--------------------------------------------------------------------------------
1 | .App {
2 | text-align: center;
3 | display: flex;
4 | align-items: center;
5 | justify-content: center;
6 | }
7 |
8 | .Card {
9 | margin: 0.5em;
10 | margin-top: 10vh;
11 | background-color: rgba(0, 0, 0, 0.575);
12 | width: 35em;
13 | height: 45em;
14 | border-radius: 3em;
15 | -webkit-backdrop-filter: blur(10px);
16 | backdrop-filter: blur(10px);
17 | filter: drop-shadow(0 0 0.75rem rgba(0, 0, 0, 0.082));
18 | /* border: solid 0.8em rgba(255, 255, 255, 0.048); */
19 | border: solid 0.9em rgba(143, 170, 243, 0.068);
20 | }
21 | .Logo {
22 |
23 | height: 6em;
24 | width: auto;
25 | padding: 2em 5em 0em 5em ;
26 |
27 | /* padding-right: 5em; */
28 | }
29 |
30 |
31 | .Stats h3 {
32 | margin: 1.7em;
33 | color: rgb(132, 160, 159);
34 | color: rgb(165, 137, 154);
35 | font-weight: 400;
36 | font-size: 1.6em;
37 | }
38 |
39 | h1 {
40 | margin: 1.4em;
41 | color: rgb(117, 136, 196);
42 |
43 | font-weight: 400;
44 | font-size: 1.5em;
45 | }
46 |
47 | h4 {
48 | color: rgb(161, 160, 160);
49 | font-weight: 400;
50 | font-size: 1.2em;
51 | }
52 |
53 | p {
54 | font-size: 0.7em;
55 | }
56 |
57 | footer {
58 | position: absolute;
59 | bottom: 1em;
60 | width: 100%;
61 | color: rgba(255, 255, 255, 0.76);
62 | border-radius: 0em 0em 1em 1em;
63 | padding-top: 2em;
64 | }
65 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "tron-wallet-react-integration",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^5.14.1",
7 | "@testing-library/react": "^11.2.7",
8 | "@testing-library/user-event": "^12.8.3",
9 | "react": "^17.0.2",
10 | "react-dom": "^17.0.2",
11 | "react-scripts": "4.0.3",
12 | "web-vitals": "^1.1.2"
13 | },
14 | "scripts": {
15 | "start": "react-scripts start",
16 | "build": "react-scripts build",
17 | "test": "react-scripts test",
18 | "eject": "react-scripts eject"
19 | },
20 | "eslintConfig": {
21 | "extends": [
22 | "react-app",
23 | "react-app/jest"
24 | ]
25 | },
26 | "browserslist": {
27 | "production": [
28 | ">0.2%",
29 | "not dead",
30 | "not op_mini all"
31 | ],
32 | "development": [
33 | "last 1 chrome version",
34 | "last 1 firefox version",
35 | "last 1 safari version"
36 | ]
37 | },
38 | "description": "TRON WALLET & REACT INTEGRATION",
39 | "main": "index.js",
40 | "devDependencies": {},
41 | "keywords": [
42 | "react",
43 | "tronlink",
44 | "klever",
45 | "integration",
46 | "example",
47 | "tron",
48 | "trx",
49 | "blockchain",
50 | "tronweb",
51 | "wallet",
52 | "cryptocurrency",
53 | "crypto",
54 | "solidity"
55 |
56 | ],
57 | "author": "Justinas Kairys",
58 | "license": "ISC"
59 | }
60 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | TRON WALLET & REACT INTEGRATION
28 |
29 |
30 |
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import { React, useState, useEffect } from 'react';
2 | import './App.css';
3 | import logo from './logo.svg';
4 |
5 | function App() {
6 | const [myMessage, setMyMessage] = useState( LOADING..
);
7 | const [myDetails, setMyDetails] = useState({
8 | name: 'none',
9 | address: 'none',
10 | balance: 0,
11 | frozenBalance: 0,
12 | network: 'none',
13 | link: 'false',
14 | });
15 |
16 | const getBalance = async () => {
17 | //if wallet installed and logged , getting TRX token balance
18 | if (window.tronWeb && window.tronWeb.ready) {
19 | let walletBalances = await window.tronWeb.trx.getAccount(
20 | window.tronWeb.defaultAddress.base58
21 | );
22 | return walletBalances;
23 | } else {
24 | return 0;
25 | }
26 | };
27 |
28 | const getWalletDetails = async () => {
29 | if (window.tronWeb) {
30 | //checking if wallet injected
31 | if (window.tronWeb.ready) {
32 | let tempBalance = await getBalance();
33 | let tempFrozenBalance = 0;
34 |
35 | if (!tempBalance.balance) {
36 | tempBalance.balance = 0;
37 | }
38 |
39 | //checking if any frozen balance exists
40 | if (
41 | !tempBalance.frozen &&
42 | !tempBalance.account_resource.frozen_balance_for_energy
43 | ) {
44 | tempFrozenBalance = 0;
45 | } else {
46 | if (
47 | tempBalance.frozen &&
48 | tempBalance.account_resource.frozen_balance_for_energy
49 | ) {
50 | tempFrozenBalance =
51 | tempBalance.frozen[0].frozen_balance +
52 | tempBalance.account_resource.frozen_balance_for_energy
53 | .frozen_balance;
54 | }
55 | if (
56 | tempBalance.frozen &&
57 | !tempBalance.account_resource.frozen_balance_for_energy
58 | ) {
59 | tempFrozenBalance = tempBalance.frozen[0].frozen_balance;
60 | }
61 | if (
62 | !tempBalance.frozen &&
63 | tempBalance.account_resource.frozen_balance_for_energy
64 | ) {
65 | tempFrozenBalance =
66 | tempBalance.account_resource.frozen_balance_for_energy
67 | .frozen_balance;
68 | }
69 | }
70 |
71 | //we have wallet and we are logged in
72 | setMyMessage(WALLET CONNECTED
);
73 | setMyDetails({
74 | name: window.tronWeb.defaultAddress.name,
75 | address: window.tronWeb.defaultAddress.base58,
76 | balance: tempBalance.balance / 1000000,
77 | frozenBalance: tempFrozenBalance / 1000000,
78 | network: window.tronWeb.fullNode.host,
79 | link: 'true',
80 | });
81 | } else {
82 | //we have wallet but not logged in
83 | setMyMessage(WALLET DETECTED PLEASE LOGIN
);
84 | setMyDetails({
85 | name: 'none',
86 | address: 'none',
87 | balance: 0,
88 | frozenBalance: 0,
89 | network: 'none',
90 | link: 'false',
91 | });
92 | }
93 | } else {
94 | //wallet is not detected at all
95 | setMyMessage(WALLET NOT DETECTED
);
96 | }
97 | };
98 |
99 | useEffect(() => {
100 | const interval = setInterval(async () => {
101 | getWalletDetails();
102 | //wallet checking interval 2sec
103 | }, 2000);
104 | return () => {
105 | clearInterval(interval);
106 | };
107 | });
108 |
109 | return (
110 |
111 |
112 |
TRON WALLET & REACT INTEGRATION
113 |
114 |

118 |
119 |
120 |
121 | {myMessage}
122 |
Account Name: {myDetails.name}
123 | My Address: {myDetails.address}
124 |
125 | Balance: {myDetails.balance} TRX (Frozen:{' '}
126 | {myDetails.frozenBalance} TRX)
127 |
128 | Network Selected: {myDetails.network}
129 | Link Established: {myDetails.link}
130 |
131 |
134 |
135 |
136 | );
137 | }
138 |
139 | export default App;
140 |
--------------------------------------------------------------------------------
/src/logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
73 |
--------------------------------------------------------------------------------
/src/background.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
262 |
--------------------------------------------------------------------------------