2.0 Async Javascript

Creating Revenue Path (code subject to change)

see here for example createArgs parameters

import { R3vlClient } from "@r3vl/sdk";
import { ethers } from "ethers";

interface ICreateArgs {
  addressList: string[][];
  distributionsList: number[][];
  tokenList: string[];
  limitSequence: ethers.BigNumberish[][];
  pathName: string;
  isImmutable: boolean;
}

export const CreatePathButton = ({ createArgs }: { ICreateArgs }) => {
    
    const handleSubmit = async () => {
        client = new R3vlClient.v2;
        try {
          await client.createRevenuePath(createArgs);
        } catch (e) {
          console.log(e);
        }
    };
    
    return (
        <button onClick={handleSubmit}>Create Path</button>
    );
};

Withdrawing From Revenue Path

import { R3vlClient } from "@r3vl/sdk";
import { useAccount } from "wagmi";
import { ethers } from "ethers";

export const WithdrawRevenueButton = () => {
    const { address } = useAccount();
    
    const handleWithdraw = () => {
        client = new R3vlClient.v2;
        try {
          await client.withdraw(address);
        } catch (e) {
          console.log(e);
        }
    };
    
    return (
        <button onClick={handleWithdraw}>Withdraw Revenue</button>
    );
};

Get Revenue Path Balances

a simple hook to display a user's available balances

import { useBalances } from "@r3vl/sdk/hooks";
import { useAccount } from "wagmi";
import { ethers } from "ethers";
import { useEffect, useState } from "React";

interface IBalances {
  earnings: number;
  withdrawn: number;
  withdrawable: number;
}

export const DisplayBalances = () => {
    const { address } = useAccount();
    const [balances, setBalances] = useState<IBalances>()
    useEffect(() => {
        client = new R3vlClient.v2;
        try {
          const withdrawn = await client.withdrawn(address);
          const withdrawable = await client.withdrawable(address);
          const earnings = withdrawn + withdrawable;
          setBalances({earnings, withdrawn, withdrawable});
        } catch (e) {
          console.log(e);
        }
    }, []);
    
    return (
        // earnings - withdrawn = withdrawable
        <div display="flex">
            {!!balances && (
                <div className="total-earnings">{balances.earnings}</div>
                <div className="total-withdrawn">{balances.withdrawn}</div>
                <div className="total-withdrawable">{balances.withdrawable}</div>
            )}
        </div>
    );
};

Last updated