Skip to content

Commit

Permalink
fix: further fix on transaction type problem which need more api request
Browse files Browse the repository at this point in the history
  • Loading branch information
wu committed Jul 10, 2019
1 parent 46d9275 commit 75ba78d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/layouts/transaction/detail.styl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
text-overflow ellipsis
white-space nowrap
textarea
background-color rgb(235, 235, 228)
background-color #eeeeee
min-height 200px
max-height 500px
padding 15px!important
Expand Down
43 changes: 23 additions & 20 deletions src/layouts/transaction/detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ class TransactionDetail extends React.Component<any, any> {
data.unsignedTransaction &&
data.unsignedTransaction.transaction &&
data.unsignedTransaction.transaction.to)
var toIsContract =
(data && data.to) ||
(data &&
data.unsignedTransaction &&
data.unsignedTransaction.transaction &&
data.unsignedTransaction.transaction.toIsContract)
var subData =
data &&
data.unsignedTransaction &&
Expand Down Expand Up @@ -131,10 +137,7 @@ class TransactionDetail extends React.Component<any, any> {
? ''
: !to
? 'Contract Creation'
: subData &&
subData.replace(/^0x/, '') &&
dataReceipt &&
dataReceipt.contractAddress
: subData && toIsContract && subData.replace(/^0x/, '')
? 'Contract Call'
: 'Exchange'}
</div>
Expand Down Expand Up @@ -294,22 +297,22 @@ class TransactionDetail extends React.Component<any, any> {
var dataUtf8: HTMLTextAreaElement = document.getElementById(
'dataUtf8'
) as HTMLTextAreaElement
if (subData.replace(/^0x/, '')) {
if (dataReceipt && dataReceipt.contractAddress) {
getContractData(
dataReceipt.contractAddress,
subData,
(error: any, data: any) => {
if (error) {
if (dataUtf8) dataUtf8.value = error
} else {
if (dataUtf8) dataUtf8.value = data
}
if (toIsContract && subData.replace(/^0x/, '')) {
// if (dataReceipt && dataReceipt.contractAddress) {
getContractData(
to || (dataReceipt && dataReceipt.contractAddress),
subData,
(error: any, data: any) => {
console.log(error)
if (error) {
if (dataUtf8) dataUtf8.value = error
} else {
if (dataUtf8) dataUtf8.value = data
}
)
} else {
dataUtf8.value = hex2Utf8(subData)
}
}
)
} else {
dataUtf8.value = hex2Utf8(subData)
}
}
}}
Expand All @@ -324,7 +327,7 @@ class TransactionDetail extends React.Component<any, any> {
}}
/>
</Tab>
{subData && subData.replace(/^0x/, '') ? (
{data && to ? (
<Tab title="UTF8">
<textarea
id="dataUtf8"
Expand Down
37 changes: 32 additions & 5 deletions src/redux/actions/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,38 @@ export function getTransaction(key: string) {
.getTransaction(key)
.then((data: TransactionItem) => {
dispatch(hideLoading())
dispatch({
type: constants.GET_TRANSACTION_ITEM,
data: data
})
return data

if (
data &&
data.unsignedTransaction &&
data.unsignedTransaction.transaction &&
data.unsignedTransaction.transaction.to
) {
return dataAPI
.getCode(data.unsignedTransaction.transaction.to)
.then((code: any) => {
data.unsignedTransaction.transaction.toIsContract =
code && code !== '0x'
dispatch({
type: constants.GET_TRANSACTION_ITEM,
data: data
})
return data
})
.catch(() => {
dispatch({
type: constants.GET_TRANSACTION_ITEM,
data: data
})
return data
})
} else {
dispatch({
type: constants.GET_TRANSACTION_ITEM,
data: data
})
return data
}
})
.catch((error: any) => {
dispatch(hideLoading())
Expand Down
10 changes: 9 additions & 1 deletion src/redux/states/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
export interface TransactionItem {}
export interface TransactionItem {
blockHash: string
blockNumber: String
content: String
from: String
hash: String
index: String
unsignedTransaction: any
}
export interface TransactionReceiptItem {}
export interface TransactionList {
pageNum: Number | 1
Expand Down

0 comments on commit 75ba78d

Please sign in to comment.