Files
radicle-explorer/src/base/faucet/lib.ts
T
Sebastian Martinez e3de337769 Move reactive config part into session state
This PR moves the signer "clones" the signer property from the `Config`
object into the `session` state, to allow Svelte reactivity, e.g. in the
Testnet Faucet, where we rely on `config.signer` but since it only
changes when the `Config` object in `App.svelte` changes we can't react
on it.

For now I only cloned the signer property, if we see in the future that
there are other properties that need to change with session we can add
them.

Signed-off-by: Sebastian Martinez <sebastinez@me.com>
Signed-off-by: Alexis Sellier <self@cloudhead.io>
2022-02-02 15:25:58 +01:00

61 lines
1.6 KiB
TypeScript

import * as ethers from 'ethers';
import type { Config } from '@app/config';
import { assert } from '@app/error';
import type { TransactionResponse } from '@ethersproject/providers';
import { toWei } from '@app/utils';
import type { WalletConnectSigner } from "@app/WalletConnectSigner";
import type { TypedDataSigner } from '@ethersproject/abstract-signer';
type Signer = ethers.Signer & TypedDataSigner | WalletConnectSigner | null;
export async function withdraw(amount: string, signer: Signer, config: Config): Promise<TransactionResponse> {
assert(signer);
const faucet = new ethers.Contract(
config.radToken.faucet,
config.abi.faucet,
signer
);
return faucet.withdraw(config.radToken.address, toWei(amount));
}
export async function getMaxWithdrawAmount(signer: Signer, config: Config): Promise<ethers.BigNumber> {
assert(signer);
const faucet = new ethers.Contract(
config.radToken.faucet,
config.abi.faucet,
signer
);
return faucet.maxWithdrawAmount();
}
export async function calculateTimeLock(amount: string, signer: Signer, config: Config): Promise<ethers.BigNumber> {
assert(signer);
const faucet = new ethers.Contract(
config.radToken.faucet,
config.abi.faucet,
signer
);
return faucet.calculateTimeLock(toWei(amount));
}
export async function lastWithdrawalByUser(signer: Signer, config: Config): Promise<ethers.BigNumber> {
assert(signer);
const address = signer.getAddress();
const faucet = new ethers.Contract(
config.radToken.faucet,
config.abi.faucet,
signer
);
return faucet.lastWithdrawalByUser(address);
}