Skip to content

Commit

Permalink
[SDK] fix: Allow resending OTP on failures (#6412)
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquim-verges authored Mar 5, 2025
1 parent 158a08a commit 9f1a77f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 82 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-jobs-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Allow resending OTP on failures
59 changes: 0 additions & 59 deletions packages/thirdweb/src/extensions/erc1155/drop1155.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ import { resolvePromisedValue } from "../../utils/promise/resolve-promised-value
import { toEther } from "../../utils/units.js";
import { generateMerkleTreeInfoERC1155 } from "../airdrop/write/merkleInfoERC1155.js";
import { name } from "../common/read/name.js";
import { deployERC20Contract } from "../prebuilts/deploy-erc20.js";
import { deployERC1155Contract } from "../prebuilts/deploy-erc1155.js";
import { balanceOf } from "./__generated__/IERC1155/read/balanceOf.js";
import { totalSupply } from "./__generated__/IERC1155/read/totalSupply.js";
import { nextTokenIdToMint } from "./__generated__/IERC1155Enumerable/read/nextTokenIdToMint.js";
import { canClaim } from "./drops/read/canClaim.js";
import { getActiveClaimCondition } from "./drops/read/getActiveClaimCondition.js";
Expand Down Expand Up @@ -472,63 +470,6 @@ describe.runIf(process.env.TW_SECRET_KEY)(
expect(isGetNFTsSupported(selectors)).toBe(true);
});

/**
* This is to document the behavior where one can claim without paying if the claiming address
* is the same as the PrimaryRecipientAddress, because of this Solidity code:
* ```solidity
* // CurrencyTransferLib.sol
* function safeTransferERC20(address _currency, address _from, address _to, uint256 _amount) internal {
* if (_from == _to) {
* return;
* }
* ...
* }
* ```
*/
it("address that is the same with PrimaryFeeRecipient can claim without paying ERC20", async () => {
const tokenAddress = await deployERC20Contract({
client: TEST_CLIENT,
chain: ANVIL_CHAIN,
account: TEST_ACCOUNT_C,
type: "TokenERC20",
params: {
name: "token20",
contractURI: TEST_CONTRACT_URI,
},
});
const tokenId = 5n;
const setClaimTx = setClaimConditions({
contract,
tokenId,
phases: [
{
maxClaimableSupply: 100n,
maxClaimablePerWallet: 100n,
currencyAddress: tokenAddress,
price: 1000,
startTime: new Date(),
},
],
});
await sendAndConfirmTransaction({
transaction: setClaimTx,
account: TEST_ACCOUNT_C,
});

const transaction = claimTo({
contract,
tokenId,
quantity: 50n,
to: TEST_ACCOUNT_C.address,
});
await sendAndConfirmTransaction({
transaction,
account: TEST_ACCOUNT_C,
});
const supplyCount = await totalSupply({ contract, id: tokenId });
expect(supplyCount).toBe(50n);
});

it("getActiveClaimCondition should work", async () => {
// Create a public allowlist claim phase
const snapshot = [
Expand Down
4 changes: 2 additions & 2 deletions packages/thirdweb/src/react/web/wallets/shared/OTPLoginUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export function OTPLoginUI(props: {

{!isWideModal && <Line />}

<Container p={isWideModal ? undefined : "lg"}>
<Container p={isWideModal ? undefined : "lg"} gap="xs">
{accountStatus === "error" && (
<Text size="sm" center color="danger">
{locale.emailLoginScreen.failedToSendCode}
Expand All @@ -297,7 +297,7 @@ export function OTPLoginUI(props: {
</Container>
)}

{accountStatus === "sent" && (
{accountStatus !== "sending" && (
<LinkButton onClick={sendEmailOrSms} type="button">
{locale.emailLoginScreen.resendCode}
</LinkButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,12 @@ describe.runIf(process.env.TW_SECRET_KEY)("prepareengineTransaction", () => {
const { message, messageType, signature } = result;

expect(isHex(signature)).toBe(true);
expect(message).toMatchInlineSnapshot(`
{
"data": "0xa9059cbb00000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c80000000000000000000000000000000000000000000000056bc75e2d63100000",
"from": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"gas": 64340n,
"nonce": 0n,
"to": "${erc20Contract.address}",
"value": 0n,
}
`);
expect(message.data).toBe(
"0xa9059cbb00000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c80000000000000000000000000000000000000000000000056bc75e2d63100000",
);
expect(message.from).toBe(TEST_ACCOUNT_A.address);
expect(message.to).toBe(erc20Contract.address);
expect(message.value).toBe(0n);
expect(messageType).toMatchInlineSnapshot(`"forward"`);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,12 @@ describe.runIf(process.env.TW_SECRET_KEY)(
const { message, messageType, signature } = result;

expect(isHex(signature)).toBe(true);
expect(message).toMatchInlineSnapshot(`
{
"data": "0xa9059cbb00000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c80000000000000000000000000000000000000000000000056bc75e2d63100000",
"from": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"gas": 64340n,
"nonce": 0n,
"to": "${erc20Contract.address}",
"value": 0n,
}
`);
expect(message.from).toBe(TEST_ACCOUNT_A.address);
expect(message.to).toBe(erc20Contract.address);
expect(message.value).toBe(0n);
expect(message.data).toBe(
"0xa9059cbb00000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c80000000000000000000000000000000000000000000000056bc75e2d63100000",
);
expect(messageType).toMatchInlineSnapshot(`"forward"`);
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
});

await expect(tx).rejects.toMatchInlineSnapshot(`
[TransactionError: Error - Not authorized
[TransactionError: Execution Reverted: {"code":3,"message":"execution reverted: Not authorized"}
contract: ${contract.address}
chainId: 11155111]
Expand Down

0 comments on commit 9f1a77f

Please sign in to comment.