Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -12353,6 +12353,7 @@ const autoRunController = self.MultiPageBackgroundAutoRunController?.createAutoR
getAutoRunStatusPayload,
getErrorMessage,
getFirstUnfinishedNodeId,
getNodeIdsForState,
getPendingAutoRunTimerPlan,
getRunningNodeIds,
getState,
Expand Down
74 changes: 74 additions & 0 deletions background/auto-run-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
getAutoRunStatusPayload,
getErrorMessage,
getFirstUnfinishedNodeId,
getNodeIdsForState,
getPendingAutoRunTimerPlan,
getRunningNodeIds,
getState,
Expand Down Expand Up @@ -65,6 +66,78 @@
return false;
}

const EMPTY_REGISTRATION_EMAIL_STATE = Object.freeze({
current: '',
previous: '',
source: '',
updatedAt: 0,
});
const DONE_NODE_STATUSES = new Set(['completed', 'manual_completed', 'skipped']);

function isPhoneSignupFlow(state = {}) {
const signupMethod = String(state?.signupMethod || state?.resolvedSignupMethod || '').trim().toLowerCase();
return signupMethod === 'phone';
}

function getFullWorkflowNodeIds(state = {}) {
if (typeof getNodeIdsForState === 'function') {
const nodeIds = getNodeIdsForState(state);
if (Array.isArray(nodeIds) && nodeIds.length) {
return Array.from(new Set(
nodeIds
.map((nodeId) => String(nodeId || '').trim())
.filter(Boolean)
));
}
}
return getKnownNodeIdsFromState(state);
}

function isFullWorkflowDone(state = {}) {
const nodeIds = getFullWorkflowNodeIds(state);
if (!nodeIds.length) {
return false;
}
const nodeStatuses = state?.nodeStatuses || {};
return nodeIds.every((nodeId) => (
DONE_NODE_STATUSES.has(String(nodeStatuses[nodeId] || 'pending').trim())
));
}

async function clearPhoneSignupRuntimeAfterRoundSuccess() {
const currentState = await getState();
if (
!isPhoneSignupFlow(currentState)
|| !isFullWorkflowDone(currentState)
) {
return false;
}

await setState({
accountIdentifierType: null,
accountIdentifier: '',
currentPhoneActivation: null,
phoneNumber: '',
signupPhoneNumber: '',
signupPhoneActivation: null,
signupPhoneCompletedActivation: null,
signupPhoneVerificationRequestedAt: null,
signupPhoneVerificationPurpose: '',
currentPhoneVerificationCode: '',
currentPhoneVerificationCountdownEndsAt: 0,
currentPhoneVerificationCountdownWindowIndex: 0,
currentPhoneVerificationCountdownWindowTotal: 0,
email: null,
registrationEmailState: { ...EMPTY_REGISTRATION_EMAIL_STATE },
step8VerificationTargetEmail: '',
lastEmailTimestamp: null,
lastSignupCode: '',
lastLoginCode: '',
bindEmailSubmitted: false,
});
return true;
}

async function waitForRunningWorkflowNodesToFinish(payload = {}) {
if (typeof waitForRunningNodesToFinish === 'function') {
return waitForRunningNodesToFinish(payload);
Expand Down Expand Up @@ -698,6 +771,7 @@
attemptRuns: attemptRun,
continued: useExistingProgress,
});
await clearPhoneSignupRuntimeAfterRoundSuccess();

roundSummary.status = 'success';
roundSummary.finalFailureReason = '';
Expand Down
Loading