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 },
|
tokenIconUrl: { type: String, default: null },
|
||||||
tokenCategories: { type: Array, default: [] },
|
tokenCategories: { type: Array, default: [] },
|
||||||
tokenTags: { 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.
|
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.
|
// Get the mutable data from the cid if it exists.
|
||||||
if (mutableDataCid && typeof mutableDataCid === 'string') {
|
if (mutableDataCid && typeof mutableDataCid === 'string') {
|
||||||
const mutableData = await this.retryQueue.addToQueue(this.adapters.wallet.cid2json, mutableDataCid)
|
const mutableData = await this.retryQueue.addToQueue(this.adapters.wallet.cid2json, mutableDataCid)
|
||||||
// console.log('mutableData: ', mutableData)
|
console.log('mutableData: ', mutableData)
|
||||||
if (mutableData) {
|
if (mutableData) {
|
||||||
offerEntity.tokenIconUrl = mutableData.tokenIcon
|
try {
|
||||||
offerEntity.tokenCategories = mutableData.category
|
offerEntity.tokenIconUrl = mutableData.tokenIcon
|
||||||
offerEntity.tokenTags = mutableData.tags
|
offerEntity.tokenCategories = mutableData.category
|
||||||
offerEntity.lastUpdatedTokenData = new Date().getTime()
|
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 tokenDataMock = mockData.nftTokenData01
|
||||||
const offerObj = mockData.offerMockData
|
const offerObj = mockData.offerMockData
|
||||||
const mutableDataMock = mockData.mutableDataMock
|
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
|
// Mock dependencies
|
||||||
// sandbox.stub(uut.adapters.wallet.bchWallet, 'utxoIsValid').resolves(false)
|
// sandbox.stub(uut.adapters.wallet.bchWallet, 'utxoIsValid').resolves(false)
|
||||||
sandbox.stub(uut, 'findOfferByTxid').throws(new Error('offer not found'))
|
sandbox.stub(uut, 'findOfferByTxid').throws(new Error('offer not found'))
|
||||||
|
|||||||
Reference in New Issue
Block a user