Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add success notification on "set pinning" action #2038

Merged
merged 2 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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