Skip to content

Commit

Permalink
Merge pull request #4 from cheqd/fixCustomAmount
Browse files Browse the repository at this point in the history
fix: Fix custom amount type mismatch
  • Loading branch information
filipdjokic authored Apr 5, 2024
2 parents 4ba3d0b + 47c9908 commit e54576b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/faucet/src/api/requestparser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { RequestParser } from "./requestparser";
describe("RequestParser", () => {
it("can process valid credit request with denom", () => {
const body = { address: "abc", denom: "utkn" };
expect(RequestParser.parseCreditBody(body)).toEqual({ address: "abc", denom: "utkn" });
expect(RequestParser.parseCreditBody(body)).toEqual({ address: "abc", denom: "utkn", amount: 1 });
});

it("throws helpful error message when ticker is found", () => {
Expand Down
12 changes: 11 additions & 1 deletion packages/faucet/src/faucet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { PathBuilder } from "./pathbuilder";
import { createClients, createWallets } from "./profile";
import { TokenConfiguration, TokenManager } from "./tokenmanager";
import { MinimalAccount, SendJob } from "./types";
import { Uint53 } from "@cosmjs/math";

export class Faucet {
public static async make(
Expand Down Expand Up @@ -86,10 +87,19 @@ export class Faucet {
public async credit(recipient: string, denom: string, amount?: number): Promise<void> {
if (this.distributorAddresses.length === 0) throw new Error("No distributor account available");
const sender = this.distributorAddresses[this.getCreditCount() % this.distributorAddresses.length];

let amountToCredit: Uint53 | undefined;

if (amount !== undefined) {
amountToCredit = new Uint53(amount);
} else {
amountToCredit = undefined;
}

const job: SendJob = {
sender: sender,
recipient: recipient,
amount: this.tokenManager.creditAmount(denom, amount),
amount: this.tokenManager.creditAmount(denom, amountToCredit),
};
if (this.logging) logSendJob(job);
await this.send(job);
Expand Down

0 comments on commit e54576b

Please sign in to comment.