Code Monkey home page Code Monkey logo

Comments (2)

mcintyre94 avatar mcintyre94 commented on June 2, 2024 2

This is a little bit fiddly with the architecture of the app, but you can do it with relatively little change by updating PaymentProvider

Taking a step back, the reason this doesn't work currently is because recipient, label and message all come from ConfigProvider, which gets its initial values by parsing the URL. This is because in this simple example app we don't have UI for setting those values. Whereas amount is set in the UI, and it comes from PaymentProvider, a different context provider. Currently this does not read the URL for values, it's just client side state that's passed between pages by sharing the context provider.

So if we want to make this work we need to read the amount from the URL in PaymentProvider. Here's one way to do it:

In PaymentProvider.tsx Replace the line const [amount, setAmount] = useState<BigNumber>();

With this:

    const router = useRouter(); // import { useRouter } from 'next/router';
    const { amount: queryAmount } = router.query;

    const initialAmount = useMemo(() => {
        if (!queryAmount) return undefined;
        if (Array.isArray(queryAmount)) return new BigNumber(queryAmount[0]);
        return new BigNumber(queryAmount)
    }, [queryAmount])

    const [amount, setAmount] = useState<BigNumber | undefined>(initialAmount);

Now the amount set on page load is read from the query param if there's one present, otherwise it defaults to undefined as it currently does. Your example URL should then work :)

Example commit making this change: master...mcintyre94:solana-pay:cm-url-amount

from solana-pay.

ChippuArt avatar ChippuArt commented on June 2, 2024

Thank you very much. Did you commited this line to the main brunch? Cool. I am looking forward to use this tool. Perfect for so many use cases.

from solana-pay.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.