-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from sotatek-dev/fix/history-user
feat: add tip and gas fee for event logs
- Loading branch information
Showing
9 changed files
with
94 additions
and
71 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/database/migrations/1727426782955-create-fee-column-event-logs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm'; | ||
|
||
export class CreateFeeColumnEventLogs1727426782955 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
return queryRunner.addColumns('event_logs', [ | ||
new TableColumn({ | ||
name: 'tip', | ||
type: 'varchar', | ||
isNullable: true, | ||
}), | ||
new TableColumn({ | ||
name: 'gas_fee', | ||
type: 'varchar', | ||
isNullable: true, | ||
}), | ||
]); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
return queryRunner.dropColumns('event_logs', ['tip', 'gas_fee']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import BigNumber from 'bignumber.js/bignumber.mjs'; | ||
// import BigNumber from 'bignumber.js/bignumber.mjs'; | ||
import { BigNumber } from 'bignumber.js'; | ||
import { isNumber, isNumberString } from 'class-validator'; | ||
|
||
export const addDecimal = (value: string | number, decimal: number) => { | ||
if (!isNumber(value) && !isNumberString(value)) return '0'; | ||
return BigNumber(value).multipliedBy(BigNumber(10).pow(decimal)).toFixed().toString(); | ||
}; | ||
|
||
export const calculateFee = (amount: string, gasFee: string | number, tipPercent: number) => { | ||
const tip = BigNumber(amount) | ||
export const calculateTip = (amount: string, gasFee: string | number, tipPercent: number): BigNumber => { | ||
return BigNumber(amount) | ||
.minus(BigNumber(gasFee)) | ||
.multipliedBy(tipPercent * 10) | ||
.dividedBy(1000); | ||
}; | ||
export const calculateFee = (amount: string, gasFee: string | number, tipPercent: number) => { | ||
const tip = calculateTip(amount, gasFee, tipPercent); | ||
return BigNumber(gasFee).plus(tip).toFixed(0, BigNumber.ROUND_UP); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters