-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathindex.js
More file actions
170 lines (143 loc) · 4.6 KB
/
index.js
File metadata and controls
170 lines (143 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import React, { Component } from 'react';
import classnames from 'classnames/bind';
import cardtitle from '../../images/cardtitle.png';
import style from './Card.css';
import { getCryptoHerosTokenAddress } from '../../lib/web3Service';
import axios from 'axios';
import LoadingCoin from '../LoadingCoin';
import Button from '@material-ui/core/Button';
import {
Dialog,
DialogActions,
DialogContent,
DialogContentText,
} from '@material-ui/core';
const cx = classnames.bind(style);
function ipfsUrl(hash) {
return 'https://ipfs.infura.io/ipfs/' + hash;
}
const ErrorAlertDialog = (props) => (
<Dialog
open={props.isOpenAlert}
onClose={props.handleAlertClose}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description"
>
<DialogContent>
<DialogContentText id="alert-dialog-description">
{props.errmsg}
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={props.handleAlertClose} color="primary" autoFocus>
Close
</Button>
</DialogActions>
</Dialog>
);
class Card extends Component {
state = {
doMintTx: '',
isLoading: false,
isOpenAlert: false,
errmsg: '',
}
handleClickAlertOpen = () => {
this.setState({ isOpenAlert: true });
}
handleAlertClose = () => {
this.setState({ isOpenAlert: false });
}
CreateHero = async() =>{
const{doMint} = this.props;
const result = await doMint();
this.setState({'doMintTx': result, isLoading: true},()=>{
this.handleSubmitMetaMask(this.state.doMintTx);
})
}
handleSubmitMetaMask =(doMintTx)=>{
const {account, network} = this.props.metaMask;
const {web3} = this.props;
const msk = {
from: account,
to: getCryptoHerosTokenAddress(network),
value: this.props.web3.toWei(0.01, 'ether'),
data: doMintTx
}
web3.eth.sendTransaction(msk, this.handleMetaMaskCallBack);
}
handleMetaMaskCallBack = (err, result)=>{
if(err) {
this.setState({errmsg: 'Sorry, transaction failed'}, ()=> this.setState({isOpenAlert: true}));
console.error('MetaMask Error:', err.message);
this.setState({isLoading: false});
return;
}
const tx = result;
let t = setInterval(async ()=>{
const result = await axios.get(`https://api-ropsten.etherscan.io/api?module=transaction&action=gettxreceiptstatus&txhash=${tx}&apikey=RAADZVN65BQA7G839DFN3VHWCZBQMRBR11`);
if(result.data.result.status === "1") {
this.ReloadDataFn();
window.clearInterval(t);
}
},3000);
}
ReloadDataFn =()=>{
const {network, account} = this.props.metaMask;
//抓卡牌編號
this.props.handleCryptoHerosTokenGetOwnedTokens(network, account, this.props.TimeOutGoTokens);
setTimeout(() => {
this.setState({isLoading: false},()=> this.props.gotoAndPlayGame());
}, 6000);
}
render() {
const {brandItem, isGetCardPage, closeMyCard} = this.props;
const alertMsg = this.state.isOpenAlert &&
<ErrorAlertDialog
{...this.state}
handleAlertClose={this.handleAlertClose}
/>;
return (
<div className={cx('Card', {open: isGetCardPage})}>
<div className="cloud_card1"></div>
<div className="cloud_card2"></div>
<div className="ui start1"></div>
<div className="ui start2"></div>
<div className="ui start3"></div>
<div className="ui Elf1"></div>
<div className="ui Elf2"></div>
<div className="ui Elf3"></div>
<div className="cardtitle">
<img src={cardtitle} />
<div className="btn_box">
<a className="goback" onClick={closeMyCard}></a>
<a className="getHero" onClick={this.CreateHero}></a>
</div>
</div>
<div className="c_mid">
{
brandItem.map((obj, idx)=>{
return (
<div className="cardBox" key={idx}>
<div className="cardbg">
<div className="s_bgcard" style={{backgroundImage: `url("${ipfsUrl(obj[2])}")` }}></div>
<div className="s_user" style={{backgroundImage: `url("${ipfsUrl(obj[1])}")` } }></div>
<div className="s_number" style={{backgroundImage: `url("${ipfsUrl(obj[3])}")` }}></div>
</div>
</div>
)
})
}
<div className='addCardBtn'>
<a onClick={this.CreateHero}></a>
</div>
</div>
{
this.state.isLoading && <LoadingCoin/>
}
{ alertMsg }
</div>
);
}
}
export default Card;