Do not use load()

This commit is contained in:
Daniel Lugo 2021-10-08 14:55:23 -04:00
parent beb722fb57
commit 194f8465ec
2 changed files with 22 additions and 40 deletions

View file

@ -162,22 +162,24 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
if (!Common.isPopulatedString(serviceID)) { if (!Common.isPopulatedString(serviceID)) {
throw new TypeError(`no serviceID provided to orderAck`) throw new TypeError(`no serviceID provided to orderAck`)
} }
const selectedService = await new Promise(res => { const selectedService = await getUser()
getUser() .get(Key.OFFERED_SERVICES)
.get(Key.OFFERED_SERVICES) .get(serviceID)
.get(serviceID) .then()
.load(res)
})
logger.info(selectedService) logger.info(selectedService)
if (!selectedService) { if (!Common.isObj(selectedService)) {
throw new TypeError(`invalid serviceID provided to orderAck`) throw new TypeError(
`invalid serviceID provided to orderAck or service is not an object`
)
} }
const { const {
serviceType, serviceType,
servicePrice, servicePrice,
serviceSeedUrl: encSeedUrl, //= serviceSeedUrl: encSeedUrl, //=
serviceSeedToken: encSeedToken //= serviceSeedToken: encSeedToken //=
} = selectedService } = /** @type {Record<string, any>} */ (selectedService)
if (Number(amount) !== Number(servicePrice)) { if (Number(amount) !== Number(servicePrice)) {
throw new TypeError( throw new TypeError(
`service price mismatch ${amount} : ${servicePrice}` `service price mismatch ${amount} : ${servicePrice}`
@ -326,12 +328,16 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
break //create the coordinate, but stop because of the invalid id break //create the coordinate, but stop because of the invalid id
} }
logger.info('IS STRING') logger.info('IS STRING')
const selectedPost = await new Promise(res => { const selectedPost = /** @type {Record<string, any>} */ (await getUser()
getUser() .get(Key.POSTS_NEW)
.get(Key.POSTS_NEW) .get(postID)
.get(postID) .then())
.load(res) const selectedPostContent = /** @type {Record<string, any>} */ (await getUser()
}) .get(Key.POSTS_NEW)
.get(postID)
.get(Key.CONTENT_ITEMS)
.then())
logger.info('LOAD ok') logger.info('LOAD ok')
logger.info(selectedPost) logger.info(selectedPost)
if ( if (
@ -350,7 +356,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
logger.info('SECRET OK') logger.info('SECRET OK')
let privateFound = false let privateFound = false
await Common.Utils.asyncForEach( await Common.Utils.asyncForEach(
Object.entries(selectedPost.contentItems), Object.entries(selectedPostContent),
async ([contentID, item]) => { async ([contentID, item]) => {
if ( if (
item.type !== 'image/embedded' && item.type !== 'image/embedded' &&

View file

@ -381,30 +381,6 @@ function createReplica(path, afterMap = false) {
} }
return createReplica(path + '>' + key) return createReplica(path + '>' + key)
}, },
load(cb) {
// Dumb implementation. We must move away from load() anyways.
if (afterMap) {
throw new Error('Cannot call load() after map() on a GunSmith node')
}
if (cb) {
listenersForThisRef.push(cb)
const id = uuid()
idToLoadListener[id] = cb
/** @type {Smith.SmithMsgLoad} */
const msg = {
id,
path,
type: 'load'
}
isReady().then(() => {
currentGun.send(msg)
})
}
return this
},
map() { map() {
if (afterMap) { if (afterMap) {
throw new Error('Cannot call map() after map() on a GunSmith node') throw new Error('Cannot call map() after map() on a GunSmith node')