Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
feat: download abi from bundle page
Browse files Browse the repository at this point in the history
  • Loading branch information
kengoldfarb committed Oct 20, 2022
1 parent 233c031 commit 87f50d9
Show file tree
Hide file tree
Showing 8 changed files with 18,996 additions and 18,819 deletions.
33,840 changes: 16,851 additions & 16,989 deletions generated/graphql.schema.json

Large diffs are not rendered by default.

3,915 changes: 2,088 additions & 1,827 deletions generated/graphql.tsx

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"react-dom": "18.1.0",
"react-gtm-module": "^2.0.11",
"react-image-file-resizer": "^0.4.7",
"slug": "^8.2.2",
"subscriptions-transport-ws": "^0.11.0",
"superagent": "^7.1.6",
"tabler-icons-react": "^1.50.0",
Expand Down
40 changes: 39 additions & 1 deletion src/components/Bundles/BundleContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import { MeemAPI } from '@meemproject/api'
import { makeFetcher, useWallet } from '@meemproject/react'
import { useRouter } from 'next/router'
import React, { useEffect, useState } from 'react'
import { Download, Rocket } from 'tabler-icons-react'
import {
Contracts,
SubGetBundleByIdSubscription
} from '../../../generated/graphql'
import { SUB_GET_BUNDLE_BY_ID } from '../../graphql/contracts'
import { downloadFile } from '../../lib/utils'
import { downloadFile, formatFilename } from '../../lib/utils'
import { Page } from '../../styles/Page'
import { DemoCode } from '../Atoms/DemoCode'
import { BundleForm } from './BundleForm'
Expand Down Expand Up @@ -114,6 +115,33 @@ export const BundleContainer: React.FC = () => {
setIsSaving(false)
}

const handleDownloadABI = async () => {
try {
const bundle = data?.Bundles[0]
if (!bundle) {
showNotification({
title: 'Error',
message: 'Bundle not found',
color: 'red'
})
return
}

downloadFile(
`${formatFilename(bundle.name)}.json`,
JSON.stringify(bundle.abi)
)
showNotification({
title: 'Success!',
message: 'ABI file generated.',
color: 'green'
})
} catch (e) {
log.crit(e)
}
setIsSaving(false)
}

useEffect(() => {
if (!hasInitialized && data?.Bundles[0]) {
form.setValues({
Expand Down Expand Up @@ -161,6 +189,7 @@ export const BundleContainer: React.FC = () => {
<Space h={8} />
<div className={classes.row}>
<Button
leftIcon={<Download />}
onClick={async () => {
const genTypes = makeFetcher<
MeemAPI.v1.GenerateTypes.IQueryParams,
Expand Down Expand Up @@ -191,6 +220,15 @@ export const BundleContainer: React.FC = () => {

<Space w={16} />
<Button
disabled={isLoading || isSaving}
onClick={handleDownloadABI}
leftIcon={<Download />}
>
Download ABI
</Button>
<Space w={16} />
<Button
leftIcon={<Rocket />}
loading={isSaving}
disabled={isLoading || isSaving}
onClick={() => setIsOpen(true)}
Expand Down
7 changes: 5 additions & 2 deletions src/components/ManageDiamond/ManageDiamondContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
WalletContractInstances
} from '../../../generated/graphql'
import { SUB_GET_CONTRACTS_BY_ADDRESS } from '../../graphql/contracts'
import { downloadFile } from '../../lib/utils'
import { downloadFile, formatFilename } from '../../lib/utils'
import { Page } from '../../styles/Page'
import { Address } from '../Atoms/Address'
import { DemoCode } from '../Atoms/DemoCode'
Expand Down Expand Up @@ -316,7 +316,10 @@ export const ManageDiamondContainer: React.FC = () => {
}
})

downloadFile(`${fileName}.json`, JSON.stringify(facetABI))
downloadFile(
`${formatFilename(fileName)}.json`,
JSON.stringify(facetABI)
)
showNotification({
title: 'Success!',
message: 'ABI file generated.',
Expand Down
1 change: 1 addition & 0 deletions src/graphql/contracts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ export const SUB_GET_BUNDLE_BY_ID = gql`
id
name
description
abi
BundleContracts(order_by: { order: asc }) {
id
order
Expand Down
6 changes: 6 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import slug from 'slug'

export type ArrayElement<ArrayType extends readonly unknown[]> =
ArrayType extends readonly (infer ElementType)[] ? ElementType : never

Expand All @@ -16,3 +18,7 @@ export function downloadFile(filename: string, text: string) {

document.body.removeChild(element)
}

export function formatFilename(name: string) {
return slug(name, { lower: true }).substr(0, 200)
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13913,6 +13913,11 @@ slice-ansi@^4.0.0:
astral-regex "^2.0.0"
is-fullwidth-code-point "^3.0.0"

slug@^8.2.2:
version "8.2.2"
resolved "https://registry.yarnpkg.com/slug/-/slug-8.2.2.tgz#33b019a857a11fc4773c1e9a9f60e3da651a9e5d"
integrity sha512-5ByW6qXqPeG0Tmlkh24JhdXhvQsbaJSjVr3GgGxUV0BSskZKKBZZfFWxezap8+fh1vxBN9GVbqI1V6nqAFxlBg==

smart-buffer@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/smart-buffer/-/smart-buffer-4.2.0.tgz#6e1d71fa4f18c05f7d0ff216dd16a481d0e8d9ae"
Expand Down

0 comments on commit 87f50d9

Please sign in to comment.