mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-21 16:52:00 -07:00
feat(userdata): Store user data on the database
This commit is contained in:
@@ -47,6 +47,7 @@ const Offer = new mongoose.Schema({
|
||||
tokenIconUrl: { type: String, default: null },
|
||||
tokenCategories: { type: Array, default: [] },
|
||||
tokenTags: { type: Array, default: [] },
|
||||
userDataStr: { type: String }, // Token user data
|
||||
lastUpdatedTokenData: { type: String, default: null } // ISO timestamp of the last time token data was updated.
|
||||
})
|
||||
|
||||
|
||||
@@ -141,12 +141,18 @@ class OfferUseCases {
|
||||
// Get the mutable data from the cid if it exists.
|
||||
if (mutableDataCid && typeof mutableDataCid === 'string') {
|
||||
const mutableData = await this.retryQueue.addToQueue(this.adapters.wallet.cid2json, mutableDataCid)
|
||||
// console.log('mutableData: ', mutableData)
|
||||
console.log('mutableData: ', mutableData)
|
||||
if (mutableData) {
|
||||
offerEntity.tokenIconUrl = mutableData.tokenIcon
|
||||
offerEntity.tokenCategories = mutableData.category
|
||||
offerEntity.tokenTags = mutableData.tags
|
||||
offerEntity.lastUpdatedTokenData = new Date().getTime()
|
||||
try {
|
||||
offerEntity.tokenIconUrl = mutableData.tokenIcon
|
||||
offerEntity.tokenCategories = mutableData.category
|
||||
offerEntity.tokenTags = mutableData.tags
|
||||
offerEntity.lastUpdatedTokenData = new Date().getTime()
|
||||
|
||||
offerEntity.userDataStr = JSON.stringify(mutableData.userData)
|
||||
} catch (error) {
|
||||
// skip error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,22 @@ describe('#offer-use-case', () => {
|
||||
const tokenDataMock = mockData.nftTokenData01
|
||||
const offerObj = mockData.offerMockData
|
||||
const mutableDataMock = mockData.mutableDataMock
|
||||
console.log('mutableDataMock: ', mutableDataMock)
|
||||
// Mock dependencies
|
||||
// sandbox.stub(uut.adapters.wallet.bchWallet, 'utxoIsValid').resolves(false)
|
||||
sandbox.stub(uut, 'findOfferByTxid').throws(new Error('offer not found'))
|
||||
sandbox.stub(uut.retryQueue, 'addToQueue')
|
||||
.onCall(0).resolves({}) // Utxo Status call
|
||||
.onCall(1).resolves(tokenDataMock) // Token Data call
|
||||
.onCall(2).resolves(mutableDataMock)
|
||||
|
||||
const result = await uut.createOffer(offerObj)
|
||||
assert.isTrue(result)
|
||||
})
|
||||
it('should skip userData stringify error', async () => {
|
||||
const tokenDataMock = mockData.nftTokenData01
|
||||
const offerObj = mockData.offerMockData
|
||||
const mutableDataMock = mockData.mutableDataMock
|
||||
mutableDataMock.userData = { n: 10n }
|
||||
// Mock dependencies
|
||||
// sandbox.stub(uut.adapters.wallet.bchWallet, 'utxoIsValid').resolves(false)
|
||||
sandbox.stub(uut, 'findOfferByTxid').throws(new Error('offer not found'))
|
||||
|
||||
Reference in New Issue
Block a user