Skip to content

Commit

Permalink
feat: add success notification on "set pinning" action (#2038)
Browse files Browse the repository at this point in the history
Co-authored-by: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com>
  • Loading branch information
xrazis and SgtPooki committed Oct 5, 2022
1 parent 90b5f3a commit e410164
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 2 additions & 0 deletions public/locales/en/notify.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"ipfsConnectSuccess": "Successfully connected to the IPFS API address",
"ipfsConnectFail": "Unable to connect to the provided IPFS API address",
"ipfsPinFailReason": "Unable to set pinning at {serviceName}: {errorMsg}",
"ipfsPinSucceedReason": "Successfully pinned at {serviceName}",
"ipfsUnpinSucceedReason": "Successfully unpinned from {serviceName}",
"ipfsIsBack": "Normal IPFS service has resumed. Enjoy!",
"folderExists": "An item with that name already exists. Please choose another.",
"filesFetchFailed": "Failed to get those files. Please check the path and try again.",
Expand Down
29 changes: 29 additions & 0 deletions src/bundles/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const notify = {
eventId: `experimentsErrors.${action.payload.key}`
}
}

if (action.type === 'IPFS_PIN_FAILED') {
return {
...state,
Expand All @@ -79,6 +80,26 @@ const notify = {
}
}

if (action.type === 'IPFS_PIN_SUCCEED') {
return {
...state,
show: true,
error: false,
msgArgs: action.msgArgs,
eventId: action.type
}
}

if (action.type === 'IPFS_UNPIN_SUCCEED') {
return {
...state,
show: true,
error: false,
msgArgs: action.msgArgs,
eventId: action.type
}
}

if (action.type === 'IPFS_CONNECT_FAILED') {
return {
...state,
Expand All @@ -87,6 +108,7 @@ const notify = {
eventId: action.type
}
}

if (action.type === 'IPFS_CONNECT_SUCCEED') {
return {
...state,
Expand All @@ -95,6 +117,7 @@ const notify = {
eventId: action.type
}
}

if (action.type === 'IPFS_API_ADDRESS_INVALID') {
return {
...state,
Expand Down Expand Up @@ -130,6 +153,12 @@ const notify = {
if (eventId === 'IPFS_PIN_FAILED') {
return 'ipfsPinFailReason'
}
if (eventId === 'IPFS_PIN_SUCCEED') {
return 'ipfsPinSucceedReason'
}
if (eventId === 'IPFS_UNPIN_SUCCEED') {
return 'ipfsUnpinSucceedReason'
}

if (eventId === 'FILES_EVENT_FAILED') {
const type = code ? code.replace(/^(ERR_)/, '') : ''
Expand Down
12 changes: 11 additions & 1 deletion src/bundles/pinning.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,14 @@ const pinningBundle = {
const pinLocally = services.includes('local')
if (wasLocallyPinned !== pinLocally) {
try {
pinLocally ? await ipfs.pin.add(cid) : await ipfs.pin.rm(cid)
const msgArgs = { serviceName: 'Local node' }
if (pinLocally) {
await ipfs.pin.add(cid)
dispatch({ type: 'IPFS_PIN_SUCCEED', msgArgs })
} else {
await ipfs.pin.rm(cid)
dispatch({ type: 'IPFS_UNPIN_SUCCEED', msgArgs })
}
} catch (e) {
console.error(`unexpected local pin error for ${cid} (${name})`, e)
const msgArgs = { serviceName: 'local', errorMsg: e.toString() }
Expand All @@ -361,12 +368,15 @@ const pinningBundle = {

const id = `${service.name}:${cid}`
try {
const msgArgs = { serviceName: service.name }
if (shouldPin) {
pending.push(id)
await ipfs.pin.remote.add(cid, { service: service.name, name, background: true })
dispatch({ type: 'IPFS_PIN_SUCCEED', msgArgs })
} else {
removals.push(id)
await ipfs.pin.remote.rm({ cid: [cid], service: service.name })
dispatch({ type: 'IPFS_UNPIN_SUCCEED', msgArgs })
}
} catch (e) {
// log error and continue with other services
Expand Down

0 comments on commit e410164

Please sign in to comment.