From 82f634ff76fe1dd6a253a61a11b06dea71dd1c15 Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Wed, 11 Mar 2020 20:24:49 -0600 Subject: [PATCH 1/2] fix: freshen the simple exchange dApp Refs #646 It should at least compile, deploy, and run. --- packages/dapp-simple-exchange/.gitignore | 1 + packages/dapp-simple-exchange/api/deploy.js | 14 +- packages/dapp-simple-exchange/api/handler.js | 57 ++++- .../dapp-simple-exchange/contract/autoswap.js | 1 - .../contract/deploy-autoswap.js | 203 ------------------ .../contract/deploy-myfirstdapp.js | 3 - .../dapp-simple-exchange/contract/deploy.js | 120 ++++------- .../{myFirstDapp.js => simple-exchange.js} | 18 +- .../ui/.env.local.example | 4 +- .../dapp-simple-exchange/ui/public/index.html | 2 + .../dapp-simple-exchange/ui/src/setupProxy.js | 17 +- .../ui/src/utils/constants.js | 9 +- .../ui/src/utils/defaults.js | 5 + .../ui/src/utils/fetch-websocket.js | 4 +- 14 files changed, 146 insertions(+), 312 deletions(-) create mode 100644 packages/dapp-simple-exchange/.gitignore delete mode 100644 packages/dapp-simple-exchange/contract/autoswap.js delete mode 100644 packages/dapp-simple-exchange/contract/deploy-autoswap.js delete mode 100644 packages/dapp-simple-exchange/contract/deploy-myfirstdapp.js rename packages/dapp-simple-exchange/contract/{myFirstDapp.js => simple-exchange.js} (85%) create mode 100644 packages/dapp-simple-exchange/ui/src/utils/defaults.js diff --git a/packages/dapp-simple-exchange/.gitignore b/packages/dapp-simple-exchange/.gitignore new file mode 100644 index 00000000000..d608438208a --- /dev/null +++ b/packages/dapp-simple-exchange/.gitignore @@ -0,0 +1 @@ +dappConstants.js diff --git a/packages/dapp-simple-exchange/api/deploy.js b/packages/dapp-simple-exchange/api/deploy.js index e1790214772..020ee70a0c7 100644 --- a/packages/dapp-simple-exchange/api/deploy.js +++ b/packages/dapp-simple-exchange/api/deploy.js @@ -1,8 +1,18 @@ // Agoric Dapp api deployment script export default async function deployApi(homeP, { bundleSource, pathResolve }) { - const { source, moduleFormat } = await bundleSource('./handler.js'); + let overrideInstanceId; + const dc = `${process.cwd()}/dappConstants.js`; + try { + require(dc); + overrideInstanceId = __DAPP_CONSTANTS__.CONTRACT_ID; + } catch (e) { + console.log(`Proceeeding with defaults; cannot load ${dc}:`, e.message); + } + + const { source, moduleFormat } = await bundleSource(pathResolve('./handler.js')); const handlerInstall = homeP~.spawner~.install(source, moduleFormat); - const handler = handlerInstall~.spawn(); + const [zoe, registrar] = await Promise.all([homeP~.zoe, homeP~.registrar]); + const handler = handlerInstall~.spawn({zoe, registrar, overrideInstanceId}); await homeP~.http~.registerCommandHandler(handler); } diff --git a/packages/dapp-simple-exchange/api/handler.js b/packages/dapp-simple-exchange/api/handler.js index cbfbf0f80de..754ead692ee 100644 --- a/packages/dapp-simple-exchange/api/handler.js +++ b/packages/dapp-simple-exchange/api/handler.js @@ -1,13 +1,62 @@ import harden from '@agoric/harden'; -export default harden((_terms, _inviteMaker) => { +export default harden(({zoe, registrar, overrideInstanceId = undefined}, _inviteMaker) => { + // If we have an overrideInstanceId, use it to assert the correct value in the RPC. + function coerceInstanceId(instanceId = undefined) { + if (instanceId === undefined) { + return overrideInstanceId; + } + if (overrideInstanceId === undefined || instanceId === overrideInstanceId) { + return instanceId; + } + throw TypeError(`instanceId ${JSON.stringify(instanceId)} must match ${JSON.stringify(overrideInstanceId)}`); + } + + const registrarPCache = new Map(); + function getRegistrarP(id) { + let regP = registrarPCache.get(id); + if (!regP) { + // Cache miss, so try the registrar. + regP = E(registrar).get(id); + registrarPCache.set(id, regP); + } + return regP; + } + + const instancePCache = new Map(); + function getInstanceP(id) { + let instanceP = instancePCache.get(id); + if (!instanceP) { + const instanceHandleP = getRegistrarP(id); + instanceP = instanceHandleP.then(instanceHandle => + E(zoe).getInstance(instanceHandle)); + instancePCache.set(id, instanceP); + } + return instanceP; + } + + async function getOrderStatus(instanceRegKey, inviteHandles) { + const { publicAPI } = await getInstanceP(instanceRegKey); + return E(publicAPI).getOrderStatus(inviteHandles); + } + return harden({ getCommandHandler() { return harden({ - processInbound(obj, _home) { + async processInbound(obj, _home) { switch (obj.type) { - case '@DIR@Message': { - return harden({ type: '@DIR@Response', orig: obj }); + case 'simpleExchange/getOrderStatus': { + const { instanceRegKey } = obj; + const instanceId = coerceInstanceId(instanceRegKey); + + // FIXME: Use a protocol to negotiate a sharingService. + const inviteHandles = []; + + const data = await getOrderStatus(instanceId, inviteHandles); + return harden({ + type: 'simpleExchange/orderStatus', + data, + }); } default: return undefined; diff --git a/packages/dapp-simple-exchange/contract/autoswap.js b/packages/dapp-simple-exchange/contract/autoswap.js deleted file mode 100644 index 18eb221457b..00000000000 --- a/packages/dapp-simple-exchange/contract/autoswap.js +++ /dev/null @@ -1 +0,0 @@ -export { makeContract } from '@agoric/zoe/src/contracts/autoswap'; diff --git a/packages/dapp-simple-exchange/contract/deploy-autoswap.js b/packages/dapp-simple-exchange/contract/deploy-autoswap.js deleted file mode 100644 index 42b903d7c9c..00000000000 --- a/packages/dapp-simple-exchange/contract/deploy-autoswap.js +++ /dev/null @@ -1,203 +0,0 @@ -// Agoric Dapp contract deployment script for autoswap -import fs from 'fs'; -import makeAmountMath from '@agoric/ertp/src/amountMath'; - -import harden from '@agoric/harden'; - -const MOOLA_NAME = 'moola'; -const SIMOLEAN_NAME = 'simolean'; - -function makeRulesOfferXForY(offerAmount, wantAmount) { - return harden({ - payoutRules: [ - { - kind: 'offerAtMost', - amount: offerAmount, - }, - { - kind: 'wantAtLeast', - amount: wantAmount, - }, - ], - exitRule: { - kind: 'onDemand', - }, - }); -} - -function makeRulesWantXForY(wantAmount, offerAmount) { - return harden({ - payoutRules: [ - { - kind: 'wantAtLeast', - amount: wantAmount, - }, - { - kind: 'offerAtMost', - amount: offerAmount, - }, - ], - exitRule: { - kind: 'onDemand', - }, - }); -} - -export default async function deployContract( - homeP, - { bundleSource, pathResolve }, - CONTRACT_NAME = 'myFirstDapp') { - - // Create a source bundle for the "myFirstDapp" smart contract. - const { source, moduleFormat } = await bundleSource(`./${CONTRACT_NAME}.js`); - - // ===================== - // === AWAITING TURN === - // ===================== - - // 1. Purses, Issuers stage 1, and Brands - const installationHandleP = homeP~.zoe~.install(source, moduleFormat); - const issuersP = homeP~.wallet~.getIssuers(); - const moolaPurseP = homeP~.wallet~.getPurse(MOOLA_NAME); - const simoleanPurseP = homeP~.wallet~.getPurse(SIMOLEAN_NAME); - const moolaBrandP = moolaPurseP~.getAllegedBrand(); - const simoleanBrandP = simoleanPurseP~.getAllegedBrand(); - const inviteIssuerP = homeP~.zoe~.getInviteIssuer(); - - const [ - issuerPsArray, - moolaBrand, - simoleanBrand, - inviteIssuer, - installationHandle, - ] = await Promise.all([ - issuersP, - moolaBrandP, - simoleanBrandP, - inviteIssuerP, - installationHandleP, - ]); - - // ===================== - // === AWAITING TURN === - // ===================== - - // 2. AmountMath, individual Issuers, and contract invite - const moola = makeAmountMath(moolaBrand, 'nat').make; - const simolean = makeAmountMath(simoleanBrand, 'nat').make; - const moolaAmount = moola(900); - const simoleanAmount = simolean(900); - const moolaPaymentP = moolaPurseP~.withdraw(moolaAmount); - const simoleanPaymentP = simoleanPurseP~.withdraw(simoleanAmount); - const issuerPs = new Map(issuerPsArray); - const moolaIssuer = issuerPs.get(MOOLA_NAME); - const simoleanIssuer = issuerPs.get(SIMOLEAN_NAME); - - const issuers = [moolaIssuer, simoleanIssuer]; - const { invite } - = await homeP~.zoe~.makeInstance(installationHandle, { issuers }); - - // ===================== - // === AWAITING TURN === - // ===================== - - // 3. Get payments and the instanceHandle from an invite. - const inviteAmountP = inviteIssuer~.getAmountOf(invite); - const [ - moolaPayment, - simoleanPayment, - inviteAmount, - ] = await Promise.all([ - moolaPaymentP, - simoleanPaymentP, - inviteAmountP, - ]); - - // ===================== - // === AWAITING TURN === - // ===================== - - // 4. The contract instance's public API - const { - extent: [{ instanceHandle }], - } = inviteAmount; - - const { publicAPI } = await homeP~.zoe~.getInstance(instanceHandle); - - // ===================== - // === AWAITING TURN === - // ===================== - - // 5. Payments for initialize the market with standing orders - async function addExchangeOffer(offerAmount, payments, wantAmount) { - const offerRules = makeRulesOfferXForY(offerAmount, wantAmount); - const { invite: anInvite } = await publicAPI~.makeInvite(); - const { seat } = await homeP~.zoe~.redeem(anInvite, offerRules, payments); - return seat~.addOrder(); - } - - async function addExchangeOffer2(wantAmount, offerAmount, payments) { - const offerRules = makeRulesWantXForY(wantAmount, offerAmount); - const { invite: anInvite } = await publicAPI~.makeInvite(); - const { seat } = await homeP~.zoe~.redeem(anInvite, offerRules, payments); - return seat~.addOrder(); - } - - const moolaPayments = moolaIssuer~.splitMany( - moolaPayment, - [500, 400].map(x => moola(x)), - ); - - const simoleanPayments = simoleanIssuer~.splitMany( - simoleanPayment, - [200, 300, 400].map(x => simolean(x)), - ); - - const [ - [moolaPayment1, moolaPayment2], - [simoleanPayment1, simoleanPayment2, simoleanPayment3], - ] = await Promise.all([moolaPayments, simoleanPayments]); - - // ===================== - // === AWAITING TURN === - // ===================== - - // 7. Add the offers - // add some orders. The values are arbitrary; there was no consistent plan - const offer1 = addExchangeOffer(moola(500), [moolaPayment1, undefined], simolean(600)); - const offer2 = addExchangeOffer(moola(400), [moolaPayment2, undefined], simolean(800)); - const offer3 = addExchangeOffer2(moola(100), simolean(200), [undefined, simoleanPayment1]); - const offer4 = addExchangeOffer2(moola(700), simolean(300), [undefined, simoleanPayment2]); - const offer5 = addExchangeOffer2(moola(500), simolean(400), [undefined, simoleanPayment3]); - - // ===================== - // === AWAITING TURN === - // ===================== - - // 8. Register the installation and instance. - const [contractId, instanceId] = await Promise.all([ - homeP~.registrar~.register(`installation-${CONTRACT_NAME}`, installationHandle), - homeP~.registrar~.register(`instance-${CONTRACT_NAME}`, instanceHandle), - ]); - - // ===================== - // === AWAITING TURN === - // ===================== - - console.log('- installation made', CONTRACT_NAME, '=>', contractId); - console.log('- instance made', CONTRACT_NAME, '=>', instanceId); - - // 9. Save the instanceId somewhere where the UI can find it. - if (contractId) { - const cjfile = pathResolve(`../ui/src/utils/contractID.js`); - console.log('writing', cjfile); - await fs.promises.writeFile(cjfile, `export default ${JSON.stringify(instanceId)};`); - - // ===================== - // === AWAITING TURN === - // ===================== - } - - await Promise.all([offer1, offer2, offer3, offer4, offer5]); - console.log(`==== added orders. ===`) -} diff --git a/packages/dapp-simple-exchange/contract/deploy-myfirstdapp.js b/packages/dapp-simple-exchange/contract/deploy-myfirstdapp.js deleted file mode 100644 index 7a66a379591..00000000000 --- a/packages/dapp-simple-exchange/contract/deploy-myfirstdapp.js +++ /dev/null @@ -1,3 +0,0 @@ -import deployContract from './deploy'; - -export default (homeP, priv) => deployContract(homeP, priv, 'myFirstDapp'); diff --git a/packages/dapp-simple-exchange/contract/deploy.js b/packages/dapp-simple-exchange/contract/deploy.js index e1313fe4472..0019a538aaa 100644 --- a/packages/dapp-simple-exchange/contract/deploy.js +++ b/packages/dapp-simple-exchange/contract/deploy.js @@ -6,12 +6,10 @@ import fs from 'fs'; // committee. // TODO: improve this comment. https://github.com/Agoric/agoric-sdk/issues/608 -import harden from '@agoric/harden'; - -const DAPP_NAME = "@DIR@"; +const DAPP_NAME = "simple-exchange"; export default async function deployContract(homeP, { bundleSource, pathResolve }, - CONTRACT_NAME = 'myFirstDapp') { + CONTRACT_NAME = DAPP_NAME) { // Create a source bundle for the "myFirstDapp" smart contract. const { source, moduleFormat } = await bundleSource(pathResolve(`./${CONTRACT_NAME}.js`)); @@ -26,28 +24,18 @@ export default async function deployContract(homeP, { bundleSource, pathResolve // === AWAITING TURN === // ===================== - // 1. Assays and payments - const purse0P = homeP~.wallet~.getPurse('moola'); - const purse1P = homeP~.wallet~.getPurse('simolean'); - const assay0P = purse0P~.getAssay(); - const assay1P = purse1P~.getAssay(); - const payment0P = purse0P~.withdraw(900); - const payment1P = purse1P~.withdraw(900); + // 1. Issuers + const wallet = homeP~.wallet; + const [[pursePetname0], [pursePetname1]] = await wallet~.getPurses(); + const issuer0P = wallet~.getPurseIssuer(pursePetname0); + const issuer1P = wallet~.getPurseIssuer(pursePetname1); const [ - purse0, - purse1, - assay0, - assay1, - payment0, - payment1 + issuer0, + issuer1, ] = await Promise.all([ - purse0P, - purse1P, - assay0P, - assay1P, - payment0P, - payment1P + issuer0P, + issuer1P, ]); // ===================== @@ -55,8 +43,13 @@ export default async function deployContract(homeP, { bundleSource, pathResolve // ===================== // 2. Contract instance. - const { invite } - = await homeP~.zoe~.makeInstance(installationHandle, { assays: [assay0, assay1] }); + const [ + invite, + inviteIssuer, + ] = await Promise.all([ + homeP~.zoe~.makeInstance(installationHandle, { issuers: [issuer0, issuer1] }), + homeP~.zoe~.getInviteIssuer(), + ]); // ===================== // === AWAITING TURN === @@ -65,52 +58,8 @@ export default async function deployContract(homeP, { bundleSource, pathResolve // 3. Get the instanceHandle const { - extent: { instanceHandle }, - } = await invite~.getBalance(); - - // ===================== - // === AWAITING TURN === - // ===================== - - // 4. Get the contract terms and assays - - const { terms: { assays }} = await homeP~.zoe~.getInstance(instanceHandle); - - // ===================== - // === AWAITING TURN === - // ===================== - - // 5. Offer rules - const [unit0, unit1] = await Promise.all([ - assays~.[0]~.makeUnits(900), - assays~.[1]~.makeUnits(900), - ]); - - // ===================== - // === AWAITING TURN === - // ===================== - - const offerRules = harden({ - payoutRules: [ - { - kind: 'offerAtMost', - units: unit0, - }, - { - kind: 'offerAtMost', - units: unit1, - }, - ], - exitRule: { - kind: 'onDemand', - }, - }); - - // 6. Registration. - - const payments = [payment0, payment1]; - - const { seat, payout } = await homeP~.zoe~.redeem(invite, offerRules, payments); + extent: [{ instanceHandle }], + } = await inviteIssuer~.getAmountOf(invite); // ===================== // === AWAITING TURN === @@ -125,17 +74,28 @@ export default async function deployContract(homeP, { bundleSource, pathResolve // === AWAITING TURN === // ===================== - console.log('- installation made', CONTRACT_NAME, '=>', installationHandle); + console.log('- installation made', CONTRACT_NAME, '=>', contractId); console.log('- instance made', CONTRACT_NAME, '=>', instanceId); - // Save the instanceId somewhere where the UI can find it. + // Save the instanceId somewhere where the UI can find it. if (instanceId) { - const cjfile = pathResolve(`../ui/src/utils/contractID.js`); - console.log('writing', cjfile); - await fs.promises.writeFile(cjfile, `export default ${JSON.stringify(instanceId)};`); - - // ===================== - // === AWAITING TURN === - // ===================== + const dappConstants = { + BRIDGE_URL: 'agoric-lookup:https://local.agoric.com?append=/bridge', + API_URL: '/', + CONTRACT_ID: instanceId, + }; + const dc = 'dappConstants.js'; + console.log('writing', dc); + await fs.promises.writeFile(dc, `globalThis.__DAPP_CONSTANTS__ = ${JSON.stringify(dappConstants, undefined, 2)}`); + + // Now add URLs so that development functions without internet access. + dappConstants.BRIDGE_URL = "http://127.0.0.1:8000"; + dappConstants.API_URL = "http://127.0.0.1:8000"; + const envFile = pathResolve(`../ui/.env.local`); + console.log('writing', envFile); + const envContents = `\ + REACT_APP_DAPP_CONSTANTS_JSON='${JSON.stringify(dappConstants)}' +`; + await fs.promises.writeFile(envFile, envContents); } } diff --git a/packages/dapp-simple-exchange/contract/myFirstDapp.js b/packages/dapp-simple-exchange/contract/simple-exchange.js similarity index 85% rename from packages/dapp-simple-exchange/contract/myFirstDapp.js rename to packages/dapp-simple-exchange/contract/simple-exchange.js index a9e4075a2cf..12084062153 100644 --- a/packages/dapp-simple-exchange/contract/myFirstDapp.js +++ b/packages/dapp-simple-exchange/contract/simple-exchange.js @@ -7,8 +7,8 @@ import { makeHelpers, defaultAcceptanceMsg } from '@agoric/zoe/src/contracts/hel * This contract is like the simpleExchange contract. The exchange only accepts * limit orders. A limit order is an order with payoutRules that specifies * wantAtLeast on one side and offerAtMost on the other: - * [ { kind: 'wantAtLeast', units2 }, { kind: 'offerAtMost', units1 }] - * [ { kind: 'wantAtLeast', units1 }, { kind: 'offerAtMost', units2 }] + * [ { kind: 'wantAtLeast', amount: amount2 }, { kind: 'offerAtMost', amount: amount1 }] + * [ { kind: 'wantAtLeast', amount: amount1 }, { kind: 'offerAtMost', amount: amount2 }] * * Note that the asset specified as wantAtLeast is treated as the exact amount * to be exchanged, while the amount specified as offerAtMost is a limit that @@ -60,6 +60,14 @@ export const makeContract = harden((zoe, terms) => { }; } + function getOrderStatus(inviteHandles) { + const requested = new Set(inviteHandles); + return { + buys: flattenOrders(buyInviteHandles.filter(requested.has)), + sells: flattenOrders(sellInviteHandles.filter(requested.has)), + } + } + function getOffer(inviteHandle) { if ( sellInviteHandles.includes(inviteHandle) || @@ -110,13 +118,13 @@ export const makeContract = harden((zoe, terms) => { throw rejectOffer(inviteHandle); }, }); - const { invite, inviteHandle } = zoe.makeInvite(seat); + const { invite, inviteHandle } = zoe.makeInvite(seat, { seatDesc: 'addOrder' }); return { invite, inviteHandle }; }; return harden({ - invite: makeInvite(), - publicAPI: { makeInvite, getBookOrders, getOffer }, + invite: makeInvite().invite, + publicAPI: { makeInvite, getBookOrders, getOrderStatus, getOffer }, terms, }); }); diff --git a/packages/dapp-simple-exchange/ui/.env.local.example b/packages/dapp-simple-exchange/ui/.env.local.example index 34e888fc1d6..f64b64c5021 100644 --- a/packages/dapp-simple-exchange/ui/.env.local.example +++ b/packages/dapp-simple-exchange/ui/.env.local.example @@ -1,3 +1 @@ -REACT_APP_DAPP_API_URL="" -REACT_APP_WALLET_BRIDGE_URL="" -REACT_APP_CONTRACT_ID="" \ No newline at end of file +REACT_APP_DAPP_CONSTANTS_JSON='{"API_URL":"http://127.0.0.1:8000","BRIDGE_URL":"http://127.0.0.1:8000","CONTRACT_ID":"unknownInstance_12345"}' diff --git a/packages/dapp-simple-exchange/ui/public/index.html b/packages/dapp-simple-exchange/ui/public/index.html index 1b7b822d8a0..dbf93b2fbf9 100644 --- a/packages/dapp-simple-exchange/ui/public/index.html +++ b/packages/dapp-simple-exchange/ui/public/index.html @@ -26,6 +26,8 @@ Simple Exchange + + diff --git a/packages/dapp-simple-exchange/ui/src/setupProxy.js b/packages/dapp-simple-exchange/ui/src/setupProxy.js index ff0f238e514..af530020ae4 100644 --- a/packages/dapp-simple-exchange/ui/src/setupProxy.js +++ b/packages/dapp-simple-exchange/ui/src/setupProxy.js @@ -3,17 +3,20 @@ // Note: You do not need to import this file anywhere. It is automatically registered // when you start the development server. +const fs = require('fs'); + const { createProxyMiddleware } = require('http-proxy-middleware'); -const API_URL = process.env.REACT_APP_DAPP_API_URL; -const BRIDGE_URL = process.env.REACT_APP_WALLET_BRIDGE_URL; +const defaults = fs.readFileSync(`${__dirname}/utils/defaults.js`, 'utf-8'); +const dappConstants = process.env.REACT_APP_DAPP_CONSTANTS_JSON + ? JSON.parse(process.env.REACT_APP_DAPP_CONSTANTS_JSON) + : JSON.parse(defaults.replace(/.*export default/s, '')); -// eslint-disable-next-line func-names -module.exports = function(app) { - if (API_URL > '') { - app.use('/vat', createProxyMiddleware({ target: API_URL })); - } +const { BRIDGE_URL } = dappConstants; + +module.exports = function manualProxy(app) { if (BRIDGE_URL > '') { + app.use('/vat', createProxyMiddleware({ target: BRIDGE_URL })); app.use( '/bridge', createProxyMiddleware({ diff --git a/packages/dapp-simple-exchange/ui/src/utils/constants.js b/packages/dapp-simple-exchange/ui/src/utils/constants.js index cefeed4154b..28daa97d214 100644 --- a/packages/dapp-simple-exchange/ui/src/utils/constants.js +++ b/packages/dapp-simple-exchange/ui/src/utils/constants.js @@ -1,3 +1,6 @@ -export const CONTRACT_ID = process.env.REACT_APP_CONTRACT_ID; -export const API_URL = process.env.REACT_APP_DAPP_API_URL; -export const BRIDGE_URL = process.env.REACT_APP_WALLET_BRIDGE_URL; +// Taken from window.DAPP_CONSTANTS_JSON in index.html, defaulting to .env.local. +import defaults from './defaults'; +export default window.DAPP_CONSTANTS_JSON || + (process.env.REACT_APP_DAPP_CONSTANTS_JSON ? + JSON.parse(process.env.REACT_APP_DAPP_CONSTANTS_JSON) : + defaults); diff --git a/packages/dapp-simple-exchange/ui/src/utils/defaults.js b/packages/dapp-simple-exchange/ui/src/utils/defaults.js new file mode 100644 index 00000000000..75cd1660bca --- /dev/null +++ b/packages/dapp-simple-exchange/ui/src/utils/defaults.js @@ -0,0 +1,5 @@ +export default { + "API_URL": "http://127.0.0.1:8000", + "BRIDGE_URL": "http://127.0.0.1:8000", + "CONTRACT_ID": "unknownInstance_12345" +} diff --git a/packages/dapp-simple-exchange/ui/src/utils/fetch-websocket.js b/packages/dapp-simple-exchange/ui/src/utils/fetch-websocket.js index b259fb44a85..341a126795d 100644 --- a/packages/dapp-simple-exchange/ui/src/utils/fetch-websocket.js +++ b/packages/dapp-simple-exchange/ui/src/utils/fetch-websocket.js @@ -1,6 +1,8 @@ /* globals window, WebSocket, fetch */ -import { API_URL } from './constants'; +import dappConstants from './constants'; + +const { API_URL } = dappConstants; // === FETCH From c89624190c09ad74dad9142700b9100891bd51d8 Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Fri, 13 Mar 2020 09:19:01 -0600 Subject: [PATCH 2/2] docs: fix some comments --- packages/dapp-simple-exchange/contract/deploy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/dapp-simple-exchange/contract/deploy.js b/packages/dapp-simple-exchange/contract/deploy.js index 0019a538aaa..84fc2023ce0 100644 --- a/packages/dapp-simple-exchange/contract/deploy.js +++ b/packages/dapp-simple-exchange/contract/deploy.js @@ -11,7 +11,7 @@ const DAPP_NAME = "simple-exchange"; export default async function deployContract(homeP, { bundleSource, pathResolve }, CONTRACT_NAME = DAPP_NAME) { - // Create a source bundle for the "myFirstDapp" smart contract. + // Create a source bundle for the CONTRACT_NAME smart contract. const { source, moduleFormat } = await bundleSource(pathResolve(`./${CONTRACT_NAME}.js`)); // ===================== @@ -88,7 +88,7 @@ export default async function deployContract(homeP, { bundleSource, pathResolve console.log('writing', dc); await fs.promises.writeFile(dc, `globalThis.__DAPP_CONSTANTS__ = ${JSON.stringify(dappConstants, undefined, 2)}`); - // Now add URLs so that development functions without internet access. + // Now add URLs so that local development works without internet access. dappConstants.BRIDGE_URL = "http://127.0.0.1:8000"; dappConstants.API_URL = "http://127.0.0.1:8000"; const envFile = pathResolve(`../ui/.env.local`);