Skip to content

Commit

Permalink
Fix proposal review (#24)
Browse files Browse the repository at this point in the history
* Refactor

* Replace to_bytes() with name()

* Reformat
  • Loading branch information
siegfried authored Mar 6, 2022
1 parent 99f8c74 commit 255f05e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion components/currency.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type AssetAmountProps = {
className?: string
}

const AssetAmount = ({quantity, decimals, symbol, className}: AssetAmountProps) => (
const AssetAmount = ({ quantity, decimals, symbol, className }: AssetAmountProps) => (
<NumberFormat
className={className}
value={toDecimal(quantity, decimals)}
Expand Down
12 changes: 5 additions & 7 deletions components/transaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ const newRecipient = (): Recipient => {

const getPolicyId = (assetId: string) => assetId.slice(0, 56)
const getAssetName = (assetId: string) => assetId.slice(56)

const decodeASCII = (assetName: string): string => {
const buffer = Buffer.from(assetName, 'hex')
const decoder = new TextDecoder('ascii')
return decoder.decode(buffer)
return Buffer.from(assetName, 'hex').toString('ascii')
}

type LabeledCurrencyInputProps = {
Expand Down Expand Up @@ -75,7 +72,7 @@ type RecipientProps = {
}

const Recipient = ({ recipient, budget, onChange }: RecipientProps) => {
const [ config, _ ] = useContext(ConfigContext)
const [config, _] = useContext(ConfigContext)
const { address, value } = recipient
const setRecipient = (recipient: Recipient) => {
onChange(recipient)
Expand Down Expand Up @@ -387,12 +384,13 @@ const TransactionViewer = ({ txBody }: TransactionViewerProps) => {
const keys = multiAsset.keys()
Array.from({ length: keys.len() }, (_, i) => {
const policyId = keys.get(i)
const policyIdHex = Buffer.from(policyId.to_bytes()).toString('hex')
const _asset = multiAsset.get(policyId)
_asset && Array.from({ length: _asset.keys().len() }, (_, i) => {
const assetName = _asset.keys().get(i)
const assetNameHex = Buffer.from(assetName.name()).toString('hex')
const quantity = BigInt(multiAsset.get_asset(policyId, assetName).to_str())
const id = Buffer.from(policyId.to_bytes()).toString('hex') +
Buffer.from(assetName.to_bytes()).toString('hex')
const id = policyIdHex + assetNameHex
assets.set(id, (assets.get(id) || BigInt(0)) + quantity)
})
})
Expand Down

0 comments on commit 255f05e

Please sign in to comment.