Skip to content

Commit

Permalink
Fix: passphrase error (#319)
Browse files Browse the repository at this point in the history
* fix: passphrase error

* fix: input pin
  • Loading branch information
ByteZhang1024 authored Apr 3, 2024
1 parent 0349761 commit 54a2e93
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
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

0 comments on commit 54a2e93

Please sign in to comment.