File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -440,16 +440,24 @@ export class RedEnvelopeService extends ActionDto<FieldTypes> {
440
440
public async preCheckTransaction (
441
441
data : GenerateTransactionParams < FieldTypes > ,
442
442
) {
443
- const { additionalData } = data ;
443
+ const { additionalData, formData } = data ;
444
+ const { password } = formData ;
444
445
const { code, account } = additionalData ;
445
446
if ( ! code ) {
446
447
throw new Error ( 'missing code' ) ;
447
448
}
448
449
const packetId = this . getPacketIDByCode ( code ) ;
450
+ const packetInfo = await this . envelopContract . redPackets ( packetId ) ;
451
+ const passwordHash = ethers . keccak256 ( ethers . toUtf8Bytes ( password ) ) ;
449
452
const hasClaimed = await this . envelopContract . isClaimed ( packetId , account ) ;
450
453
if ( hasClaimed ) {
451
454
return 'User has already received' ;
452
455
}
456
+
457
+ if ( [ ...packetInfo ] . pop ( ) !== passwordHash ) {
458
+ return 'Wrong Password' ;
459
+ }
460
+
453
461
const hasUnclaimedPacket =
454
462
await this . envelopContract . getRedPacketBalance ( packetId ) ;
455
463
if ( hasUnclaimedPacket . unClaimedCount === 0n ) {
Original file line number Diff line number Diff line change @@ -376,19 +376,27 @@ export class SharedRedPacketService extends ActionDto<FieldTypes> {
376
376
public async preCheckTransaction (
377
377
data : GenerateTransactionParams < FieldTypes > ,
378
378
) {
379
- const { additionalData } = data ;
379
+ const { additionalData, formData } = data ;
380
+ const { password } = formData ;
380
381
const { code, account } = additionalData ;
381
382
if ( ! code ) {
382
383
throw new Error ( 'missing code' ) ;
383
384
}
384
385
const packetId = this . getPacketIDByCode ( code ) ;
386
+ const packetInfo = await this . redPacketContract . redPackets ( packetId ) ;
387
+ const passwordHash = ethers . keccak256 ( ethers . toUtf8Bytes ( password ) ) ;
385
388
const hasClaimed = await this . redPacketContract . isClaimed (
386
389
packetId ,
387
390
account ,
388
391
) ;
389
392
if ( hasClaimed ) {
390
393
return 'User has already received' ;
391
394
}
395
+
396
+ if ( [ ...packetInfo ] . pop ( ) !== passwordHash ) {
397
+ return 'Wrong Password' ;
398
+ }
399
+
392
400
const hasUnclaimedPacket =
393
401
await this . redPacketContract . getRedPacketBalance ( packetId ) ;
394
402
if ( hasUnclaimedPacket . unClaimedCount === 0n ) {
You can’t perform that action at this time.
0 commit comments