Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: passphrase error #319

Merged
merged 2 commits into from
Apr 3, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@ export function ReceivePin({
</Stack>

<Dialog.Close asChild>
<Button size="large" onPress={() => onConfirm(val)}>
<Button
size="large"
onPress={() => {
onConfirm(val);
setVal('');
}}
>
{intl.formatMessage({ id: 'action__confirm' })}
</Button>
</Dialog.Close>
Expand All @@ -136,7 +142,10 @@ export function ReceivePin({
<Unspaced>
<Dialog.Close asChild>
<Button
onPress={onCancel}
onPress={() => {
setVal('');
onCancel();
}}
variant="tertiary"
circular
width={32}
Expand Down
12 changes: 7 additions & 5 deletions packages/core/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export const callAPI = async (message: CoreMessage) => {
}

// Check to see if it is safe to use Passphrase
checkPassphraseSafety(method, device.features);
checkPassphraseEnableState(method, device.features);

if (device.hasUsePassphrase() && method.useDevicePassphraseState) {
// check version
Expand All @@ -254,12 +254,14 @@ export const callAPI = async (message: CoreMessage) => {
}

// Check Device passphrase State
const passphraseState = await device.checkPassphraseState();
const passphraseStateSafety = await device.checkPassphraseStateSafety(
method.payload?.passphraseState
);

// Double check, handles the special case of Touch/Pro
checkPassphraseSafety(method, device.features);
checkPassphraseEnableState(method, device.features);

if (passphraseState) {
if (!passphraseStateSafety) {
DevicePool.clearDeviceCache(method.payload.connectId);
return Promise.reject(
ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError)
Expand Down Expand Up @@ -556,7 +558,7 @@ export const cancel = (connectId?: string) => {
closePopup();
};

const checkPassphraseSafety = (method: BaseMethod, features?: Features) => {
const checkPassphraseEnableState = (method: BaseMethod, features?: Features) => {
if (!method.useDevicePassphraseState) return;

if (
Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/device/Device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,15 +586,17 @@ export class Device extends EventEmitter {
return false;
}

async checkPassphraseState() {
async checkPassphraseStateSafety(passphraseState?: string) {
if (!this.features) return false;
const newState = await getPassphraseStateWithRefreshDeviceInfo(this);

// When exists passphraseState, check passphraseState
if (this.passphraseState && this.passphraseState !== newState) {
if (passphraseState && passphraseState !== newState) {
this.clearInternalState();
return newState;
return false;
}

return true;
}
}

Expand Down
Loading