Skip to content

Commit d68b34a

Browse files
committed
Prefer CLAIMED state over EXPIRED when a gift card is less than 24 hours old
1 parent aaef7f2 commit d68b34a

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

pkg/code/server/account/server.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,17 +335,16 @@ func (s *server) getProtoAccountInfo(ctx context.Context, records *common.Accoun
335335
switch err {
336336
case nil:
337337
if autoReturnActionRecord.State != action.StateUnknown {
338-
claimState = accountpb.TokenAccountInfo_CLAIM_STATE_EXPIRED
338+
claimState = accountpb.TokenAccountInfo_CLAIM_STATE_CLAIMED
339339
}
340340
case action.ErrActionNotFound:
341341
default:
342342
return nil, err
343343
}
344344

345-
// Unclaimed gift cards that are close to the auto-return window are
346-
// marked as expired in a consistent manner as SubmitIntent to avoid
347-
// race conditions with the auto-return.
348-
if claimState == accountpb.TokenAccountInfo_CLAIM_STATE_NOT_CLAIMED && time.Since(records.General.CreatedAt) > async_account.GiftCardExpiry-15*time.Minute {
345+
// Gift cards that are close to the auto-return window are marked as expired in
346+
// a consistent manner as SubmitIntent to avoid race conditions with the auto-return.
347+
if time.Since(records.General.CreatedAt) > async_account.GiftCardExpiry-15*time.Minute {
349348
claimState = accountpb.TokenAccountInfo_CLAIM_STATE_EXPIRED
350349
}
351350

pkg/code/server/account/server_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ func TestGetTokenAccountInfos_RemoteSendGiftCard_HappyPath(t *testing.T) {
340340
expectedBalanceSource: accountpb.TokenAccountInfo_BALANCE_SOURCE_CACHE,
341341
expectedBlockchainState: accountpb.TokenAccountInfo_BLOCKCHAIN_STATE_EXISTS,
342342
expectedManagementState: accountpb.TokenAccountInfo_MANAGEMENT_STATE_LOCKED,
343-
expectedClaimState: accountpb.TokenAccountInfo_CLAIM_STATE_EXPIRED,
343+
expectedClaimState: accountpb.TokenAccountInfo_CLAIM_STATE_CLAIMED,
344344
},
345345
{
346346
balance: 42,
@@ -350,7 +350,7 @@ func TestGetTokenAccountInfos_RemoteSendGiftCard_HappyPath(t *testing.T) {
350350
expectedBalanceSource: accountpb.TokenAccountInfo_BALANCE_SOURCE_CACHE,
351351
expectedBlockchainState: accountpb.TokenAccountInfo_BLOCKCHAIN_STATE_EXISTS,
352352
expectedManagementState: accountpb.TokenAccountInfo_MANAGEMENT_STATE_UNLOCKED,
353-
expectedClaimState: accountpb.TokenAccountInfo_CLAIM_STATE_EXPIRED,
353+
expectedClaimState: accountpb.TokenAccountInfo_CLAIM_STATE_CLAIMED,
354354
},
355355
{
356356
balance: 42,
@@ -360,7 +360,7 @@ func TestGetTokenAccountInfos_RemoteSendGiftCard_HappyPath(t *testing.T) {
360360
expectedBalanceSource: accountpb.TokenAccountInfo_BALANCE_SOURCE_CACHE,
361361
expectedBlockchainState: accountpb.TokenAccountInfo_BLOCKCHAIN_STATE_DOES_NOT_EXIST,
362362
expectedManagementState: accountpb.TokenAccountInfo_MANAGEMENT_STATE_CLOSED,
363-
expectedClaimState: accountpb.TokenAccountInfo_CLAIM_STATE_EXPIRED,
363+
expectedClaimState: accountpb.TokenAccountInfo_CLAIM_STATE_CLAIMED,
364364
},
365365
} {
366366
ownerAccount := testutil.NewRandomAccount(t)

0 commit comments

Comments
 (0)