Skip to content

Commit

Permalink
ZEUS Pay: new device check
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Nov 9, 2024
1 parent 94b586b commit 9b4464b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
39 changes: 30 additions & 9 deletions stores/LightningAddressStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export default class LightningAddressStore {
@observable public redeemingAll: boolean = false;
@observable public error: boolean = false;
@observable public error_msg: string = '';
@observable public availableHashes: number = 0;
@observable public availableHashes: number = 0; // on server
@observable public localHashes: number = 0; // on device
@observable public paid: any = [];
@observable public preimageMap: any = {};
@observable public fees: any = {};
Expand All @@ -63,18 +64,29 @@ export default class LightningAddressStore {
this.settingsStore = settingsStore;
}

@action
public DEV_deleteLocalHashes = async () => {
this.loading = true;
await EncryptedStorage.setItem(
HASHES_STORAGE_STRING,
JSON.stringify('')
);
await this.status();
this.loading = false;
};

@action
public getPreimageMap = async () => {
this.loading = true;
const map = await EncryptedStorage.getItem(HASHES_STORAGE_STRING);

if (map) {
this.preimageMap = JSON.parse(map);
this.loading = false;
return this.preimageMap;
} else {
this.loading = false;
this.localHashes = Object.keys(this.preimageMap).length;
}

this.loading = false;
return this.preimageMap;
};

@action
Expand Down Expand Up @@ -116,7 +128,7 @@ export default class LightningAddressStore {
};

@action
public generatePreimages = async () => {
public generatePreimages = async (newDevice?: boolean) => {
this.error = false;
this.error_msg = '';
this.loading = true;
Expand Down Expand Up @@ -207,14 +219,16 @@ export default class LightningAddressStore {
message: verification,
signature,
hashes,
nostrSignatures
nostrSignatures,
newDevice
}
: {
pubkey: this.nodeInfoStore
.nodeInfo.identity_pubkey,
message: verification,
signature,
hashes
hashes,
newDevice
}
)
)
Expand Down Expand Up @@ -572,6 +586,7 @@ export default class LightningAddressStore {
}
this.loading = false;
this.availableHashes = results || 0;
await this.getPreimageMap();
this.paid =
this.enhanceWithFee(paid);
this.fees = fees;
Expand All @@ -585,6 +600,11 @@ export default class LightningAddressStore {
}

if (
this.lightningAddress &&
this.localHashes === 0
) {
this.generatePreimages(true);
} else if (
this.lightningAddress &&
new BigNumber(
this.availableHashes
Expand Down Expand Up @@ -1052,7 +1072,7 @@ export default class LightningAddressStore {
});
}
}
this.status();
this.status(true);
this.redeemingAll = false;
};

Expand Down Expand Up @@ -1153,6 +1173,7 @@ export default class LightningAddressStore {
this.error = false;
this.error_msg = '';
this.availableHashes = 0;
this.localHashes = 0;
this.paid = [];
this.preimageMap = {};
this.socket = undefined;
Expand Down
17 changes: 16 additions & 1 deletion views/Settings/LightningAddress/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,11 @@ export default class LightningAddress extends React.Component<
create,
status,
redeemAllOpenPayments,
DEV_deleteLocalHashes,
lightningAddressHandle,
lightningAddressDomain,
availableHashes,
localHashes,
paid,
fees,
error,
Expand Down Expand Up @@ -350,7 +352,9 @@ export default class LightningAddress extends React.Component<
)
]}
>
{` (${availableHashes})`}
{` (${
__DEV__ ? `${localHashes}|` : ''
}${availableHashes})`}
</Text>
</Row>
<QRButton />
Expand Down Expand Up @@ -794,6 +798,17 @@ export default class LightningAddress extends React.Component<
disabled={!isReady}
/>
)}
{__DEV__ && (
<View style={{ marginTop: 10 }}>
<Button
title={'Clear local hashes'}
onPress={() =>
DEV_deleteLocalHashes()
}
secondary
/>
</View>
)}
</>
)}
</>
Expand Down

0 comments on commit 9b4464b

Please sign in to comment.