-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from SweetmanTech/sweets/matter
Sweets/matter
- Loading branch information
Showing
16 changed files
with
868 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const useCallSale = (collectionContract: any) => { | ||
const callSale = async ( | ||
tokenId: number, | ||
salesConfig: string, | ||
data: string | ||
) => { | ||
const tx = await collectionContract.callSale(tokenId, salesConfig, data); | ||
const receipt = await tx.wait(); | ||
return receipt; | ||
}; | ||
|
||
return { callSale }; | ||
}; | ||
|
||
export default useCallSale; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Contract } from "ethers"; | ||
import { useCallback, useEffect, useMemo, useState } from "react"; | ||
import abi from "@/lib/abi/ERC20FixedPriceSaleStrategy.json"; | ||
import getDefaultProvider from "@/lib/getDefaultProvider"; | ||
|
||
type UseErc20FixedPriceSaleStrategyParams = { | ||
saleConfig: string; | ||
drops: any[]; | ||
chainId: number; | ||
}; | ||
|
||
const useErc20FixedPriceSaleStrategy = ({ | ||
saleConfig, | ||
drops, | ||
chainId, | ||
}: UseErc20FixedPriceSaleStrategyParams) => { | ||
const [priceValues, setPriceValues] = useState([] as string[]); | ||
const saleConfigContract = useMemo( | ||
() => | ||
saleConfig && new Contract(saleConfig, abi, getDefaultProvider(chainId)), | ||
[saleConfig, chainId] | ||
); | ||
|
||
const sale = useCallback( | ||
async (tokenContract: string, tokenId: string) => { | ||
try { | ||
if (!saleConfigContract) return; | ||
const response = await saleConfigContract.sale(tokenContract, tokenId); | ||
return response; | ||
} catch (error) { | ||
return error; | ||
} | ||
}, | ||
[saleConfigContract] | ||
); | ||
|
||
useEffect(() => { | ||
const getValues = async () => { | ||
if (drops.length === 0) return; | ||
const pricesPromises = drops.map((drop: any) => | ||
sale(drop.contractAddress, drop.tokenId) | ||
); | ||
const prices = await Promise.all(pricesPromises); | ||
const values = prices.map((price) => price.pricePerToken.toString()); | ||
setPriceValues(values); | ||
}; | ||
|
||
getValues(); | ||
}, [drops, sale]); | ||
|
||
return { sale, priceValues }; | ||
}; | ||
|
||
export default useErc20FixedPriceSaleStrategy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const usePermission = (collectionContract: any) => { | ||
const isAdminOrRole = async (user: string, tokenId: number, role: number) => { | ||
if (!collectionContract) return false; | ||
const response = await collectionContract.isAdminOrRole( | ||
user, | ||
tokenId, | ||
role | ||
); | ||
return response; | ||
}; | ||
|
||
const addPermission = async (tokenId: number, user: string, role: number) => { | ||
if (!collectionContract) return false; | ||
const tx = await collectionContract.addPermission(tokenId, user, role); | ||
const receipt = await tx.wait(); | ||
return receipt; | ||
}; | ||
|
||
return { addPermission, isAdminOrRole }; | ||
}; | ||
|
||
export default usePermission; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.