Skip to content

Commit

Permalink
Merge pull request #621 from EdgeApp/sam/fil-send-to-self
Browse files Browse the repository at this point in the history
- fixed: Incorrectly identifying send-to-self transactions as receives from the network
  • Loading branch information
samholmes authored Sep 8, 2023
2 parents 2367cfb + 8f18829 commit e9bf829
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/filecoin/FilecoinEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,21 +447,28 @@ export class FilecoinEngine extends CurrencyEngine<
messageDetails: FilfoxMessageDetailed
): EdgeTransaction => {
const addressString = this.address.toString()
let netNativeAmount = messageDetails.value
const ourReceiveAddresses = []

// Get the fees paid
// Handle network fees:
const networkFee = messageDetails.transfers
.filter(
transfer =>
transfer.type === 'miner-fee' || transfer.type === 'burner-fee'
)
.reduce((sum, transfer) => add(sum, transfer.value), '0')

if (messageDetails.to !== addressString) {
// check if tx is a spend
netNativeAmount = `-${add(netNativeAmount, networkFee)}`
// Handle native amount:
let nativeAmount: string
if (messageDetails.from === addressString) {
// For spends, always include network fee
nativeAmount = `-${networkFee}`
if (messageDetails.to !== addressString) {
// For spends not to self, subtract tx value
nativeAmount = sub(nativeAmount, messageDetails.value)
}
} else {
// For receives nativeAMount is always positively the value
nativeAmount = messageDetails.value
ourReceiveAddresses.push(addressString)
}

Expand All @@ -470,8 +477,8 @@ export class FilecoinEngine extends CurrencyEngine<
date: messageDetails.timestamp,
currencyCode: this.currencyInfo.currencyCode,
blockHeight: messageDetails.height,
nativeAmount: netNativeAmount,
isSend: netNativeAmount.startsWith('-'),
nativeAmount,
isSend: nativeAmount.startsWith('-'),
networkFee,
ourReceiveAddresses, // blank if you sent money otherwise array of addresses that are yours in this transaction
signedTx: '',
Expand All @@ -484,14 +491,20 @@ export class FilecoinEngine extends CurrencyEngine<

filscanMessageToEdgeTransaction(message: FilscanMessage): EdgeTransaction {
const addressString = this.address.toString()
let netNativeAmount = message.value
const ourReceiveAddresses = []

const networkFee = '0' // TODO: calculate transaction fee from onchain gas fields
if (message.to !== addressString) {
// check if tx is a spend
netNativeAmount = `-${add(netNativeAmount, networkFee)}`
let nativeAmount: string
if (message.from === addressString) {
// For spends, always include network fee
nativeAmount = `-${networkFee}`
if (message.to !== addressString) {
// For spends not to self, subtract tx value
nativeAmount = sub(nativeAmount, message.value)
}
} else {
// For receives nativeAMount is always positively the value
nativeAmount = message.value
ourReceiveAddresses.push(addressString)
}

Expand All @@ -500,8 +513,8 @@ export class FilecoinEngine extends CurrencyEngine<
date: message.block_time,
currencyCode: this.currencyInfo.currencyCode,
blockHeight: message.height,
nativeAmount: netNativeAmount,
isSend: netNativeAmount.startsWith('-'),
nativeAmount,
isSend: nativeAmount.startsWith('-'),
networkFee,
ourReceiveAddresses, // blank if you sent money otherwise array of addresses that are yours in this transaction
signedTx: '',
Expand Down

0 comments on commit e9bf829

Please sign in to comment.