adding username translation
This commit is contained in:
parent
2a203f3ac7
commit
a842e8f8e6
13
nft.go
13
nft.go
@ -207,12 +207,7 @@ func (s *MarketService) GetNft(ctx context.Context, collection string, tokenId i
|
|||||||
res.IsRecent = time.Unix(res.UpdatedAt, 0).After(time.Now().Add(-1 * time.Hour))
|
res.IsRecent = time.Unix(res.UpdatedAt, 0).After(time.Now().Add(-1 * time.Hour))
|
||||||
res.IsVeryRecent = time.Unix(res.UpdatedAt, 0).After(time.Now().Add(-5 * time.Minute))
|
res.IsVeryRecent = time.Unix(res.UpdatedAt, 0).After(time.Now().Add(-5 * time.Minute))
|
||||||
res.IsNotMine = res.CurrentSeller != s.bscaddress
|
res.IsNotMine = res.CurrentSeller != s.bscaddress
|
||||||
|
res.CurrentSellerUsername = s.profileService.GetUsername(res.CurrentSeller)
|
||||||
if n, err := s.profileService.GetUsername(res.CurrentSeller); err != nil {
|
|
||||||
res.CurrentSellerUsername = res.CurrentSeller
|
|
||||||
} else {
|
|
||||||
res.CurrentSellerUsername = n
|
|
||||||
}
|
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
@ -274,11 +269,7 @@ func (s *MarketService) getPage(ctx context.Context, collection string, pagenum
|
|||||||
floor = nft.CurrentAskPrice
|
floor = nft.CurrentAskPrice
|
||||||
}
|
}
|
||||||
nft.IsNotMine = nft.CurrentSeller != s.bscaddress
|
nft.IsNotMine = nft.CurrentSeller != s.bscaddress
|
||||||
if n, err := s.profileService.GetUsername(nft.CurrentSeller); err != nil {
|
nft.CurrentSellerUsername = s.profileService.GetUsername(nft.CurrentSeller)
|
||||||
nft.CurrentSellerUsername = nft.CurrentSeller
|
|
||||||
} else {
|
|
||||||
nft.CurrentSellerUsername = n
|
|
||||||
}
|
|
||||||
res = append(res, nft)
|
res = append(res, nft)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
profile.go
15
profile.go
@ -52,18 +52,17 @@ func NewProfileService() *ProfileService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ProfileService) GetUsername(address string) (string, error) {
|
func (s *ProfileService) GetUsername(address string) string {
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
defer s.lock.Unlock()
|
defer s.lock.Unlock()
|
||||||
if name, ok := s.cache[address]; ok {
|
if name, ok := s.cache[address]; ok {
|
||||||
return name, nil
|
return name
|
||||||
}
|
|
||||||
|
|
||||||
name, err := getUsernameFromAddress(address)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
}
|
||||||
|
if name, err := getUsernameFromAddress(address); err != nil {
|
||||||
|
s.cache[address] = address
|
||||||
|
} else {
|
||||||
s.cache[address] = name
|
s.cache[address] = name
|
||||||
|
}
|
||||||
|
|
||||||
return name, nil
|
return s.cache[address]
|
||||||
}
|
}
|
||||||
|
@ -110,16 +110,8 @@ func (s *TransactionService) GetLightPageByLimit(ctx context.Context, pagenumber
|
|||||||
return transaction.Nft.TransactionHistory[i].Timestamp > transaction.Nft.TransactionHistory[j].Timestamp
|
return transaction.Nft.TransactionHistory[i].Timestamp > transaction.Nft.TransactionHistory[j].Timestamp
|
||||||
})
|
})
|
||||||
transaction.IsMine = transaction.Buyer.Address == s.bscaddress || transaction.Seller.Address == s.bscaddress
|
transaction.IsMine = transaction.Buyer.Address == s.bscaddress || transaction.Seller.Address == s.bscaddress
|
||||||
if n, err := s.profileService.GetUsername(transaction.Seller.Address); err != nil {
|
transaction.SellerUsername = s.profileService.GetUsername(transaction.Seller.Address)
|
||||||
transaction.SellerUsername = transaction.Seller.Address
|
transaction.BuyerUsername = s.profileService.GetUsername(transaction.Buyer.Address)
|
||||||
} else {
|
|
||||||
transaction.SellerUsername = n
|
|
||||||
}
|
|
||||||
if n, err := s.profileService.GetUsername(transaction.Buyer.Address); err != nil {
|
|
||||||
transaction.BuyerUsername = transaction.Buyer.Address
|
|
||||||
} else {
|
|
||||||
transaction.BuyerUsername = n
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var res []Transaction
|
var res []Transaction
|
||||||
@ -179,16 +171,8 @@ func (s *TransactionService) GetPageByLimit(ctx context.Context, pagenumber int,
|
|||||||
|
|
||||||
transaction.Time = time.Unix(transaction.Timestamp, 0)
|
transaction.Time = time.Unix(transaction.Timestamp, 0)
|
||||||
transaction.TimeDescription = humanize.Time(transaction.Time)
|
transaction.TimeDescription = humanize.Time(transaction.Time)
|
||||||
if n, err := s.profileService.GetUsername(transaction.Seller.Address); err != nil {
|
transaction.SellerUsername = s.profileService.GetUsername(transaction.Seller.Address)
|
||||||
transaction.SellerUsername = transaction.Seller.Address
|
transaction.BuyerUsername = s.profileService.GetUsername(transaction.Buyer.Address)
|
||||||
} else {
|
|
||||||
transaction.SellerUsername = n
|
|
||||||
}
|
|
||||||
if n, err := s.profileService.GetUsername(transaction.Buyer.Address); err != nil {
|
|
||||||
transaction.BuyerUsername = transaction.Buyer.Address
|
|
||||||
} else {
|
|
||||||
transaction.BuyerUsername = n
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var res []Transaction
|
var res []Transaction
|
||||||
|
Loading…
Reference in New Issue
Block a user