save the entire voucher data when setting the default voucher

This commit is contained in:
Alfred Kamanda 2024-11-14 17:31:17 +03:00
parent 9d2d01e3e2
commit f3e3badff6
Signed by: Alfred-mk
GPG Key ID: 7EA3D01708908703

View File

@ -1447,6 +1447,8 @@ func (h *Handlers) SetDefaultVoucher(ctx context.Context, sym string, input []by
firstVoucher := vouchersResp[0]
defaultSym := firstVoucher.TokenSymbol
defaultBal := firstVoucher.Balance
defaultDec := firstVoucher.TokenDecimals
defaultAddr := firstVoucher.ContractAddress
// set the active symbol
err = store.WriteEntry(ctx, sessionId, common.DATA_ACTIVE_SYM, []byte(defaultSym))
@ -1460,6 +1462,18 @@ func (h *Handlers) SetDefaultVoucher(ctx context.Context, sym string, input []by
logg.ErrorCtxf(ctx, "failed to write defaultBal entry with", "key", common.DATA_ACTIVE_BAL, "value", defaultBal, "error", err)
return res, err
}
// set the active decimals
err = store.WriteEntry(ctx, sessionId, common.DATA_ACTIVE_DECIMAL, []byte(defaultDec))
if err != nil {
logg.ErrorCtxf(ctx, "failed to write defaultDec entry with", "key", common.DATA_ACTIVE_DECIMAL, "value", defaultDec, "error", err)
return res, err
}
// set the active contract address
err = store.WriteEntry(ctx, sessionId, common.DATA_ACTIVE_ADDRESS, []byte(defaultAddr))
if err != nil {
logg.ErrorCtxf(ctx, "failed to write defaultAddr entry with", "key", common.DATA_ACTIVE_ADDRESS, "value", defaultAddr, "error", err)
return res, err
}
return res, nil
}