Skip to content

Commit

Permalink
feat: remote pin error feedback (#1760)
Browse files Browse the repository at this point in the history
* feat: remote pin error feedback
Co-authored-by: Marcin Rataj <[email protected]>
  • Loading branch information
rafaelramalho19 authored Apr 12, 2021
1 parent c1784e0 commit e88f163
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions public/locales/en/notify.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"ipfsInvalidApiAddress": "The provided IPFS API address is invalid.",
"ipfsConnectSuccess": "Successfully connected to the IPFS API address",
"ipfsConnectFail": "Unable to connect to the provided IPFS API address",
"ipfsPinFail": "Unable to set pinning. Try again, or see the browser console for more info.",
"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
5 changes: 4 additions & 1 deletion src/bundles/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const notify = {
}
}

if (action.type === 'IPFS_CONNECT_FAILED') {
if (action.type === 'IPFS_CONNECT_FAILED' || action.type === 'IPFS_PIN_FAILED') {
return {
...state,
show: true,
Expand Down Expand Up @@ -118,6 +118,9 @@ const notify = {
if (eventId === 'IPFS_API_ADDRESS_INVALID') {
return 'ipfsInvalidApiAddress'
}
if (eventId === 'IPFS_PIN_FAILED') {
return 'ipfsPinFail'
}

if (eventId === 'FILES_EVENT_FAILED') {
const type = code ? code.replace(/^(ERR_)/, '') : ''
Expand Down
16 changes: 10 additions & 6 deletions src/bundles/pinning.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,17 @@ const pinningBundle = {
}
}), {}),

doSetPinning: (pin, services = []) => async ({ getIpfs, store, dispatch }) => {
doSetPinning: (pin, services = [], wasLocallyPinned, previousRemotePins = []) => async ({ getIpfs, store, dispatch }) => {
const ipfs = getIpfs()
const { cid, name } = pin

const pinLocally = services.includes('local')
try {
pinLocally ? await ipfs.pin.add(cid) : await ipfs.pin.rm(cid)
} catch (e) {
// its ok if unpinning failed because object is not pinned
if (e.message !== 'not pinned or pinned indirectly') {
if (wasLocallyPinned !== pinLocally) {
try {
pinLocally ? await ipfs.pin.add(cid) : await ipfs.pin.rm(cid)
} catch (e) {
console.error(`unexpected local pin error for ${cid} (${name})`, e)
dispatch({ type: 'IPFS_PIN_FAILED' })
}
}

Expand All @@ -195,6 +195,9 @@ const pinningBundle = {

store.selectPinningServices().filter(s => s.online).forEach(async service => {
const shouldPin = services.includes(service.name)
const wasPinned = previousRemotePins.includes(service.name)
if (wasPinned === shouldPin) return

try {
const id = `${service.name}:${pin.cid}`
if (shouldPin) {
Expand All @@ -209,6 +212,7 @@ const pinningBundle = {
} catch (e) {
// log error and continue with other services
console.error(`unexpected pin.remote error for ${cid}@${service.name}`, e)
dispatch({ type: 'IPFS_PIN_FAILED' })
}
})

Expand Down
6 changes: 3 additions & 3 deletions src/components/notify/Toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const Toast = ({ error, children, onDismiss }) => {
const bg = error ? 'bg-yellow' : 'bg-green'
return (
<div className='fixed bottom-0 tc pb2 z-max' style={{ left: '50% ', transform: 'translateX(-50%)' }}>
<div className={`dib f5 lh-copy avenir pl2 pl4-ns pv2 white br2 ${bg}`}>
<div className={`flex items-center f5 lh-copy avenir pl2 pl4-ns pv2 white br2 ${bg}`}>
{children}
<CancelIcon
className='dib fill-current-color ph3 glow o-80 pointer'
style={{ height: '28px', transform: 'scale(1.5)', verticalAlign: 'bottom' }}
className='fill-current-color ph3 glow o-80 pointer'
style={{ height: '28px', transform: 'scale(1.5)' }}
onClick={onDismiss} />
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/files/modals/pinning-modal/PinningModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const PinningModal = ({ t, tReady, onCancel, onPinningSet, file, pinningS

<ModalActions>
<Button className='ma2 tc' bg='bg-gray' onClick={onCancel}>{t('app:actions.cancel')}</Button>
<Button className='ma2 tc' bg='bg-teal' onClick={() => onPinningSet(file, selectedServices)}>{t('app:actions.apply')}</Button>
<Button className='ma2 tc' bg='bg-teal' onClick={() => onPinningSet(file, selectedServices, file.pinned, selectedRemoteServices)}>{t('app:actions.apply')}</Button>
</ModalActions>
</Modal>
)
Expand Down

0 comments on commit e88f163

Please sign in to comment.