Switch from ExampleSale to SettlementSale contract#4
Conversation
f2547da to
f1ac5e8
Compare
| useEffect(() => { | ||
| if (txReceipt?.status === "success") { | ||
| refetchAmountInContract(); | ||
| } | ||
| }, [txReceipt?.status, refetchAmountInContract]); |
There was a problem hiding this comment.
Struggled to get this working - seems like sometimes it would return the fresh state from the contract, but other times would return a stale value. I'm guessing that even after waiting for a successful tx receipt, there's no guarantee a subsequent read won't get a stale value.
So I've just switched to polling every 3 seconds.
But let me know if you have any suggestions.
There was a problem hiding this comment.
yeah this is a common problem. just polling is fine I think
f1ac5e8 to
085e855
Compare
Essentially the same as sunrisedotdev/sonar-example-react#4
| VITE_SALE_CONTRACT_ADDRESS=0x51BcE35d57833253EAccd6901e95eb6772aFfc8D | ||
|
|
||
| # Address of the payment token | ||
| VITE_PAYMENT_TOKEN_ADDRESS=0x036CbD53842c5426634e7929541eC2318f3dCF7e # USDC |
There was a problem hiding this comment.
should probably also support multiple?
| function ReadyToPurchaseSection({ | ||
| walletAddress, | ||
| function CommitSection({ | ||
| entityID, |
There was a problem hiding this comment.
might be worth to differentiate sale specific vs client ID
|
|
||
| const [loading, setLoading] = useState(false); | ||
| const [error, setError] = useState<Error | undefined>(undefined); | ||
| const [commitAmount, setCommitAmount] = useState<string>("1"); |
| setError(undefined); | ||
| try { | ||
| const purchasePermitResp = await generatePurchasePermit(); | ||
| const amountInMicroUnits = BigInt(Math.floor(parseFloat(commitAmount) * 1e6)); |
There was a problem hiding this comment.
nit: maybe just amount, which aligns it with the committedAmount below. I think let's try to get rid of the micro terminology since it's a bit misleading imo
|
|
||
| The example uses a [SettlementSale](https://github.com/sunrisedotdev/sonar/blob/main/contracts/src/SettlementSale.sol) contract on Base Sepolia. | ||
|
|
||
| In order to test committing funds, you will need to have USDC to commit and ETH to pay for the gas. |
There was a problem hiding this comment.
the contract now also supports USDT, so might be worth noting? USDT is a bit easier in practice since one can directly mint from the contract
| export const saleContract = | ||
| (import.meta.env.VITE_SALE_CONTRACT_ADDRESS as Hex) ?? "0x0000000000000000000000000000000000000000"; | ||
| export const paymentTokenAddress = | ||
| (import.meta.env.VITE_PAYMENT_TOKEN_ADDRESS as `0x${string}`) ?? "0x0000000000000000000000000000000000000000"; |
| useEffect(() => { | ||
| if (txReceipt?.status === "success") { | ||
| refetchAmountInContract(); | ||
| } | ||
| }, [txReceipt?.status, refetchAmountInContract]); |
There was a problem hiding this comment.
yeah this is a common problem. just polling is fine I think

Switches from the very simple ExampleSale contract to the "proper" SettlementSale contract.
Screen Recording 2026-01-26 at 15.34.48.mov (uploaded via Graphite)