Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't resolve getPlatformFeeAccounts() with custom hook #6

Open
Maaverick opened this issue Feb 12, 2022 · 0 comments
Open

Can't resolve getPlatformFeeAccounts() with custom hook #6

Maaverick opened this issue Feb 12, 2022 · 0 comments

Comments

@Maaverick
Copy link

I am trying to add platformFees, but the fee accounts are not refreshed when the hook resolve getPlatformFeeAccounts().

The custom hook:

export const usePlatformFees = () => {
  const [platformFeesAccount, setPlatformFeesAccount] =
    useState<PlatformFeeAndAccounts>(null);
  const { connection } = useConnection();

  useEffect(() => {
    const setFeeAccount = async () => {
      let platformFeeAndAccounts = {
        feeBps: 250,
        feeAccounts: await getPlatformFeeAccounts(
          connection,
          new PublicKey(process.env.NEXT_PUBLIC_TREASURY_ADDRESS) // The platform fee account owner
        ) // map of mint to token account pubkey
      };
      console.log(platformFeeAndAccounts.feeAccounts);

      setPlatformFeesAccount(platformFeeAndAccounts);
    };
    setFeeAccount();
  }, []);

  return platformFeesAccount;
};

The Provider part using the hook:

  const JupiterApp = ({ children }) => {
  const { connection } = useConnection();
  const wallet = useWallet();
  const platformFeeAndAccounts = usePlatformFees();

  return (
    <JupiterProvider
      cluster="mainnet-beta"
      connection={connection}
      userPublicKey={wallet.publicKey || undefined}
      platformFeeAndAccounts={platformFeeAndAccounts || undefined}
    >
      {children}
    </JupiterProvider>
  );
};

When I print platformFeeAndAccounts.feeAccounts & routeInfo.marketInfos[routeInfo.marketInfos.length - 1].platformFee.pct <= (when jupiter-hook update routes on inputMint update)

I get my feeAccounts:

Map(12) {'7MC1...BPqQe' => PublicKey, 
'mSoLzY...m7So' => PublicKey, 
'4k3Dy...QrkX6R' => PublicKey, 
'SRMu...oKWRt' => PublicKey, 
'Es9vM...nwNYB' => PublicKey, …}

and 0 for all platformFee.pct routes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant