Advertisement
Guest User

how to convert react to js?

a guest
Apr 23rd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. class App extends React.Component {
  2.  
  3.  
  4. constructor(props) {
  5. super(props);
  6.  
  7. this.state = {
  8. buyValue: 10,
  9. playerAddress: 'yes',
  10. tempAddress: 'plz',
  11. originalPlayer: 'wow',
  12.  
  13. tronWeb: {
  14. installed: false,
  15. loggedIn: false
  16. },
  17. }
  18. this.init = this.init.bind(this)
  19. this.updateBuyValue = this.updateBuyValue.bind(this)
  20.  
  21. this.buyTron = this.buyTron.bind(this);
  22. this.getTronBalance = this.getTronBalance.bind(this);
  23. this.getTron2Balance = this.getTron2Balance.bind(this);
  24. this.getMicroTronBalance = this.getMicroTronBalance.bind(this);
  25. this.getContractBalance = this.getContractBalance.bind(this);
  26. this.microTronToTron = this.microTronToTron.bind(this);
  27. this.updatePlayerAddressInput = this.updatePlayerAddressInput.bind(this);
  28. this.returnHome = this.returnHome.bind(this);
  29. this.onOtherPlayer = this.onOtherPlayer.bind(this);
  30. }
  31.  
  32. async componentDidMount() {
  33.  
  34. this.setState({loading:true})
  35. await new Promise(resolve => {
  36. const tronWebState = {
  37. installed: !!window.tronWeb,
  38. loggedIn: window.tronWeb && window.tronWeb.ready
  39. };
  40.  
  41. if(tronWebState.installed) {
  42. this.setState({
  43. tronWeb:
  44. tronWebState
  45. });
  46.  
  47. return resolve();
  48. }
  49.  
  50. let tries = 0;
  51.  
  52. const timer = setInterval(() => {
  53. if(tries >= 10) {
  54. const TRONGRID_API = 'https://api.trongrid.io';
  55.  
  56. window.tronWeb = new TronWeb(
  57. TRONGRID_API,
  58. TRONGRID_API,
  59. TRONGRID_API
  60. );
  61.  
  62. this.setState({
  63. tronWeb: {
  64. installed: false,
  65. loggedIn: false
  66. }
  67. });
  68.  
  69. clearInterval(timer);
  70. return resolve();
  71. }
  72.  
  73. tronWebState.installed = !!global.tronWeb;
  74. tronWebState.loggedIn = window.tronWeb && window.tronWeb.ready;
  75.  
  76. if(!tronWebState.installed)
  77. return tries++;
  78.  
  79. this.setState({
  80. tronWeb: tronWebState
  81. });
  82.  
  83. resolve();
  84. }, 100);
  85. });
  86.  
  87. if(!this.state.tronWeb.loggedIn) {
  88. // Set default address (foundation address) used for contract calls
  89. // Directly overwrites the address object as TronLink disabled the
  90. // function call
  91. window.tronWeb.defaultAddress = {
  92. hex: global.tronWeb.address.toHex(FOUNDATION_ADDRESS),
  93. base58: FOUNDATION_ADDRESS
  94. };
  95.  
  96. window.tronWeb.on('addressChanged', () => {
  97. if(this.state.tronWeb.loggedIn)
  98. return;
  99.  
  100. this.setState({
  101. tronWeb: {
  102. installed: true,
  103. loggedIn: true
  104. }
  105. });
  106. });
  107. }
  108.  
  109. await Utils.setTronWeb(window.tronWeb, contractAddress);
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement