Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.
Prev Previous commit
Next Next commit
update store.js to new ipfs api
  • Loading branch information
tabcat committed Dec 8, 2020
commit 23f07fdac0d9ce1122034057031a27c50e063e69
32 changes: 11 additions & 21 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const ipfsConfig = {
// Websocket:
// '/dns4/ws-star-signal-1.servep2p.com/tcp/443/wss/p2p-websocket-star',
// '/dns4/ws-star-signal-2.servep2p.com/tcp/443/wss/p2p-websocket-star',
'/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star',
// '/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star',
// WebRTC:
// '/dns4/star-signal.cloud.ipfs.team/wss/p2p-webrtc-star',
// Use local signal server
Expand All @@ -37,24 +37,14 @@ const dbConfig = {
}

const store = async (name) => {
return new Promise((resolve, reject) => {
// Create IPFS instance
const ipfs = new Ipfs(ipfsConfig)

ipfs.on('error', (e) => console.error(e))
ipfs.on('ready', async () => {
try {
// Create an OrbitDB instance
const orbitdb = await OrbitDB.createInstance(ipfs)
// Open (or create) database
const db = await orbitdb.docstore(name, dbConfig)
// ToDo: remove this line
window.db = db
// Done
resolve(db)
} catch (e) {
reject(e)
}
})
})
// Create IPFS instance
const ipfs = await Ipfs.create(ipfsConfig)
// Create an OrbitDB instance
const orbitdb = await OrbitDB.createInstance(ipfs)
// Open (or create) database
const db = await orbitdb.docstore(name, dbConfig)
// ToDo: remove this line
window.db = db
// Done
return db
}