Skip to content

Commit

Permalink
feat: burn native tokens (#5169)
Browse files Browse the repository at this point in the history
* feat: burn native tokens

* chore: cleanup burn function

* ui: update burning confirmation style

* chore: remove redundant prop

* enhancement: add feature flag

* chore: remove empty line

Co-authored-by: Nicole O'Brien <nicole.obrien@iota.org>
  • Loading branch information
MarkNerdi996 and nicole-obrien committed Nov 14, 2022
1 parent d75daed commit ce2df0c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
3 changes: 3 additions & 0 deletions packages/desktop/features/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ const features = {
},
assets: {
enabled: true,
burnAsset: {
enabled: false,
},
},
activityHistory: {
enabled: true,
Expand Down
31 changes: 26 additions & 5 deletions packages/shared/components/modals/AssetActionsMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
hideActivitiesForHiddenAssets,
NotVerifiedStatus,
VerifiedStatus,
burnAsset,
} from '@core/wallet'
import { Icon } from '@lib/auxiliary/icon'
import { updatePopupProps } from '@auxiliary/popup'
import { HR, MenuItem, Modal } from 'shared/components'
import { closePopup, openPopup, updatePopupProps } from '@auxiliary/popup'
import { MenuItem, Modal } from 'shared/components'
import { checkActiveProfileAuth } from '@core/profile'
import features from '@features/features'
export let modal: Modal = undefined
export let asset: IAsset
Expand Down Expand Up @@ -53,6 +56,26 @@
function handleBurnToken(): void {
modal.close()
openPopup({
type: 'confirmation',
props: {
title: localize('actions.confirmTokenBurn.title', {
values: {
assetName: asset.metadata.name,
},
}),
description: localize('actions.confirmTokenBurn.description'),
hint: localize('actions.confirmTokenBurn.hint'),
warning: true,
confirmText: localize('actions.burnToken'),
onConfirm: () => {
checkActiveProfileAuth(async () => {
await burnAsset(asset.id)
closePopup()
})
},
},
})
}
</script>

Expand All @@ -78,13 +101,11 @@
{:else}
<MenuItem icon={Icon.Hide} title={localize('actions.hideToken')} onClick={handleHide} />
{/if}
<HR />
<MenuItem
icon={Icon.Delete}
disabled={!features?.wallet?.assets?.burnAsset?.enabled}
title={localize('actions.burnToken')}
onClick={handleBurnToken}
disabled={true}
variant="error"
/>
</div>
</Modal>
24 changes: 24 additions & 0 deletions packages/shared/lib/core/wallet/actions/burnAsset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { selectedAccount } from '@core/account/stores/selected-account.store'
import { handleError } from '@core/error/handlers/handleError'
import { handleLedgerError } from '@core/ledger'
import { activeProfile, ProfileType } from '@core/profile'
import { get } from 'svelte/store'
import { selectedAccountAssets } from '../stores'

export async function burnAsset(assetId: string): Promise<void> {
const account = get(selectedAccount)
const _activeProfile = get(activeProfile)
const nativeTokens = get(selectedAccountAssets).nativeTokens
try {
const balance = nativeTokens.find((_asset) => _asset.id === assetId)?.balance.available
if (balance) {
await account.burnNativeToken(assetId, '0x' + balance.toString(16))
}
} catch (err) {
if (_activeProfile.type === ProfileType.Ledger) {
handleLedgerError(err.error)
} else {
handleError(err)
}
}
}
1 change: 1 addition & 0 deletions packages/shared/lib/core/wallet/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './burnAsset'
export * from './claimActivity'
export * from './getAccountAssetsForSelectedAccount'
export * from './generateAndStoreActivitiesForAllAccounts'
Expand Down
5 changes: 5 additions & 0 deletions packages/shared/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,11 @@
"description": "Are you sure you want to reject this transaction?",
"node": "Please note that rejecting a transaction only hides it from your Activity feed"
},
"confirmTokenBurn": {
"title": "Burn {assetName}",
"description": "Are you sure you want burn this token?",
"hint": "Please note that burning a token may free storage deposit attached to it and is not reversible"
},
"proceedAnyway": "Proceed anyway",
"save": "Save",
"importSeed": "Import an existing seed",
Expand Down

0 comments on commit ce2df0c

Please sign in to comment.