Skip to content

Commit

Permalink
fix: mf-5006 from and to address might be wrong (#10464)
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleBill committed Aug 18, 2023
1 parent e2dcde4 commit 1efee4e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/web3-providers/src/DeBank/apis/HistoryAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class DeBankHistoryAPI implements HistoryAPI.Provider<ChainId, SchemaType
start_time: indicator?.id,
}),
)
const transactions = formatTransactions(result)
const transactions = formatTransactions(result, address)
const timeStamp = last(result.history_list)?.time_at
return createPageable(
transactions,
Expand All @@ -54,7 +54,7 @@ export class DeBankHistoryAPI implements HistoryAPI.Provider<ChainId, SchemaType
chain_ids: this.getChainIds(),
}),
)
const transactions = formatTransactions(result)
const transactions = formatTransactions(result, address)
const timeStamp = last(result.history_list)?.time_at
return createPageable(
transactions,
Expand Down
16 changes: 9 additions & 7 deletions packages/web3-providers/src/DeBank/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,10 @@ function toTxAsset(
}
}

export function formatTransactions({
cate_dict,
history_list,
token_dict,
}: HistoryResponse['data']): Array<Transaction<ChainId, SchemaType>> {
export function formatTransactions(
{ cate_dict, history_list, token_dict }: HistoryResponse['data'],
ownerAddress: string,
): Array<Transaction<ChainId, SchemaType>> {
const resolver = new ChainResolverAPI()
const transactions = history_list.map((transaction): Transaction<ChainId, SchemaType> | undefined => {
let txType = transaction.tx?.name
Expand All @@ -120,6 +119,9 @@ export function formatTransactions({
if (isSameAddress(transaction.sends[0]?.to_addr, ZERO_ADDRESS)) {
txType = 'burn'
}
const isIn = transaction.cate_id === 'receive'
const from = transaction.tx?.from_addr ?? (isIn ? transaction.other_addr : '')
const to = isIn ? ownerAddress : transaction.other_addr
return {
id: transaction.id,
chainId,
Expand All @@ -129,8 +131,8 @@ export function formatTransactions({
? cate_dict[transaction.cate_id].name
: transaction.tx?.name || 'Contract Interaction',
timestamp: transaction.time_at * 1000,
from: transaction.tx?.from_addr ?? '',
to: transaction.other_addr,
from,
to,
status: transaction.tx?.status,
assets: compact([
...transaction.sends.map((asset) => toTxAsset(asset, chainId, token_dict)),
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-shared/base/src/specs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ type TransactionAsset<ChainId, SchemaType> = Token<ChainId, SchemaType> & {
export interface Transaction<ChainId, SchemaType> {
id: string
chainId: ChainId
type?: LiteralUnion<'burn' | 'contract interaction'>
type?: LiteralUnion<'burn' | 'contract interaction' | 'transfer'>
cateType?: LiteralUnion<'approve' | 'receive' | 'send'>
cateName?: string
/** address */
Expand Down

0 comments on commit 1efee4e

Please sign in to comment.