Skip to content

Commit

Permalink
Adding custom SBTs programatically as 3rd party
Browse files Browse the repository at this point in the history
  • Loading branch information
hide-on-bush-x committed Apr 27, 2023
1 parent e8ca5f6 commit 55ac715
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/provider/masa-context-provider.tsx
Expand Up @@ -141,7 +141,7 @@ export const MasaContextProvider = ({
} = useModal(isLoggedIn, hasWalletAddress, areScopesFullfiled);

// custom SBTs
const { customContracts } = useCustomGallerySBT(
const { customContracts, handleAddSBT } = useCustomGallerySBT(
masaInstance,
customGallerySBT
);
Expand Down Expand Up @@ -301,6 +301,7 @@ export const MasaContextProvider = ({
fullScreenGallery,
// custom SBTs
customSBTs,
handleAddSBT,
};

return (
Expand Down
1 change: 1 addition & 0 deletions src/provider/masa-shape.ts
Expand Up @@ -115,4 +115,5 @@ export interface MasaShape {
fullScreenGallery?: boolean;
// customSBTs
customSBTs?: any[];
handleAddSBT?: (isCollection: boolean, name: string, address: string) => void;
}
19 changes: 16 additions & 3 deletions src/provider/modules/custom-sbts/custom-sbts.ts
@@ -1,11 +1,24 @@
import { useEffect, useState } from 'react';
import { useLocalStorage } from 'provider/use-local-storage';
import { useCallback, useEffect, useState } from 'react';

export const useCustomGallerySBT = (
masa,
customGallerySBT
): { customContracts: any[] } => {
): {
customContracts: any[];
handleAddSBT: (isCollection: boolean, name: string, address: string) => void;
} => {
const { localStorageSet } = useLocalStorage();

const [contracts, setContracts] = useState<any[]>([]);

const handleAddSBT = useCallback((isCollection, name, address) => {
localStorageSet(`masa-gallery-${isCollection ? 'sbt' : 'badge'}-${name}`, {
address,
name,
});
}, []);

useEffect(() => {
if (masa) {
(async () => {
Expand All @@ -21,7 +34,7 @@ export const useCustomGallerySBT = (
}
}, [customGallerySBT, masa]);

return { customContracts: contracts };
return { customContracts: contracts, handleAddSBT };
};

export const useCustomSBT = (masa, customContracts) => {
Expand Down
2 changes: 0 additions & 2 deletions src/provider/modules/soulnames/soulnames.ts
Expand Up @@ -67,8 +67,6 @@ export const useSoulnames = (
[masa]
);

console.log({ soulnames, isLoading, status, error });

return {
soulnames,
isSoulnamesLoading: isLoading || isFetching,
Expand Down

0 comments on commit 55ac715

Please sign in to comment.