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

Frontend MakeOffer callback pattern #104

Merged
merged 15 commits into from
Dec 5, 2023
Merged

Conversation

Pandelissym
Copy link
Contributor

Description

In this PR:

Created a new pattern for creating offer callbacks that get passed the the wallet's makeOffer function. The pattern defined in contract-callbacks.ts allows developers to define their callback functions in the view components themselves. Also, having passed the callback from the view component to the hooks you are able to overwrite the callback and add common logic to them (see for example sevice/character.ts useBuyCharacter hook).

interface MakeOfferCallback {
  accepted?: (args?: any) => void, // offer was successful
  refunded?: (args?: any) => void, // strangely seems to behave the same way as accepted
  error?: (args?: any) => void, // offer failed
  seated?: (args?: any) => void, // returned exclusively by the KREAd sell method, likely has to do with the offer being long-lived
  settled?: (args?: any) => void, // gets called when a response is received, regardless of the status
  setIsLoading?: React.Dispatch<React.SetStateAction<boolean>> 
};

You can now implement this interface in a view component passing it callbacks for specific cases (error, accepted, etc). This object is passed from the view to the hook. There common functionality can be added to the callback by doing so:

{
          ...callback,
          accepted: () => {
            if (callback.accepted) callback.accepted();
            // common functionality 
          },
        },

This object is then passed to the service functions where it is passed through the formOfferResultCallback function that generates the complete callback that the agoric makeOffer function expects.

Checklist

Make sure all items are checked before submitting the pull request. Remove any items that are not applicable.

@Pandelissym Pandelissym changed the title Frotnend MakeOffer callback pattern Frontend MakeOffer callback pattern Nov 29, 2023
@Pandelissym
Copy link
Contributor Author

  • Also changed the yarn version to 1.22.19 because 4.0.0 does not seem to be working

@Pandelissym Pandelissym merged commit a94671d into develop Dec 5, 2023
3 checks passed
@Pandelissym Pandelissym deleted the temp/offer-result-2 branch December 5, 2023 11:57
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

Successfully merging this pull request may close these issues.

2 participants