-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added APIs for pause/unpasuing a token (#148)
Signed-off-by: Himalayan Dev <kipkap1001@gmail.com>
- Loading branch information
1 parent
240fb91
commit 3f78919
Showing
18 changed files
with
6,576 additions
and
14,036 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
/// <reference types="jest-extended" /> | ||
// / <reference types="jest-extended" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
packages/hedera-wallet-snap/packages/site/src/components/cards/hts/PauseToken.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/*- | ||
* | ||
* Hedera Wallet Snap | ||
* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
import { FC, useContext, useRef, useState } from 'react'; | ||
import { | ||
MetaMaskContext, | ||
MetamaskActions, | ||
} from '../../../contexts/MetamaskContext'; | ||
import useModal from '../../../hooks/useModal'; | ||
import { Account, PauseOrDeleteTokenRequestParams } from '../../../types/snap'; | ||
import { pauseToken, shouldDisplayReconnectButton } from '../../../utils'; | ||
import { Card, SendHelloButton } from '../../base'; | ||
import ExternalAccount, { | ||
GetExternalAccountRef, | ||
} from '../../sections/ExternalAccount'; | ||
|
||
type Props = { | ||
network: string; | ||
mirrorNodeUrl: string; | ||
setAccountInfo: React.Dispatch<React.SetStateAction<Account>>; | ||
}; | ||
|
||
const PauseToken: FC<Props> = ({ network, mirrorNodeUrl, setAccountInfo }) => { | ||
const [state, dispatch] = useContext(MetaMaskContext); | ||
const [loading, setLoading] = useState(false); | ||
const { showModal } = useModal(); | ||
const [tokenId, setTokenId] = useState<string>(); | ||
|
||
const externalAccountRef = useRef<GetExternalAccountRef>(null); | ||
|
||
const handlePauseTokenClick = async () => { | ||
setLoading(true); | ||
try { | ||
const externalAccountParams = | ||
externalAccountRef.current?.handleGetAccountParams(); | ||
|
||
const pauseTokenParams = { | ||
tokenId, | ||
} as PauseOrDeleteTokenRequestParams; | ||
|
||
const response: any = await pauseToken( | ||
network, | ||
mirrorNodeUrl, | ||
pauseTokenParams, | ||
externalAccountParams, | ||
); | ||
|
||
const { receipt, currentAccount } = response; | ||
|
||
setAccountInfo(currentAccount); | ||
console.log('receipt: ', receipt); | ||
|
||
showModal({ | ||
title: 'Transaction Receipt', | ||
content: JSON.stringify({ receipt }, null, 4), | ||
}); | ||
} catch (error) { | ||
console.error(error); | ||
dispatch({ type: MetamaskActions.SetError, payload: error }); | ||
} | ||
setLoading(false); | ||
}; | ||
|
||
return ( | ||
<Card | ||
content={{ | ||
title: 'pauseToken', | ||
description: | ||
'Pause a token. This will prevent all transactions from occurring on the token.', | ||
form: ( | ||
<> | ||
<ExternalAccount ref={externalAccountRef} /> | ||
<label> | ||
Enter the token ID to pause | ||
<input | ||
type="text" | ||
style={{ width: '100%' }} | ||
value={tokenId} | ||
placeholder="Token Id" | ||
onChange={(error) => setTokenId(error.target.value)} | ||
/> | ||
</label> | ||
<br /> | ||
</> | ||
), | ||
button: ( | ||
<SendHelloButton | ||
buttonText="Pause" | ||
onClick={handlePauseTokenClick} | ||
disabled={!state.installedSnap} | ||
loading={loading} | ||
/> | ||
), | ||
}} | ||
disabled={!state.installedSnap} | ||
fullWidth={ | ||
state.isFlask && | ||
Boolean(state.installedSnap) && | ||
!shouldDisplayReconnectButton(state.installedSnap) | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
export { PauseToken }; |
125 changes: 125 additions & 0 deletions
125
packages/hedera-wallet-snap/packages/site/src/components/cards/hts/UnpauseToken.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/*- | ||
* | ||
* Hedera Wallet Snap | ||
* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
import { FC, useContext, useRef, useState } from 'react'; | ||
import { | ||
MetaMaskContext, | ||
MetamaskActions, | ||
} from '../../../contexts/MetamaskContext'; | ||
import useModal from '../../../hooks/useModal'; | ||
import { Account, PauseOrDeleteTokenRequestParams } from '../../../types/snap'; | ||
import { shouldDisplayReconnectButton, unpauseToken } from '../../../utils'; | ||
import { Card, SendHelloButton } from '../../base'; | ||
import ExternalAccount, { | ||
GetExternalAccountRef, | ||
} from '../../sections/ExternalAccount'; | ||
|
||
type Props = { | ||
network: string; | ||
mirrorNodeUrl: string; | ||
setAccountInfo: React.Dispatch<React.SetStateAction<Account>>; | ||
}; | ||
|
||
const UnpauseToken: FC<Props> = ({ | ||
network, | ||
mirrorNodeUrl, | ||
setAccountInfo, | ||
}) => { | ||
const [state, dispatch] = useContext(MetaMaskContext); | ||
const [loading, setLoading] = useState(false); | ||
const { showModal } = useModal(); | ||
const [tokenId, setTokenId] = useState<string>(); | ||
|
||
const externalAccountRef = useRef<GetExternalAccountRef>(null); | ||
|
||
const handleUnpauseTokenClick = async () => { | ||
setLoading(true); | ||
try { | ||
const externalAccountParams = | ||
externalAccountRef.current?.handleGetAccountParams(); | ||
|
||
const unpauseTokenParams = { | ||
tokenId, | ||
} as PauseOrDeleteTokenRequestParams; | ||
|
||
const response: any = await unpauseToken( | ||
network, | ||
mirrorNodeUrl, | ||
unpauseTokenParams, | ||
externalAccountParams, | ||
); | ||
|
||
const { receipt, currentAccount } = response; | ||
|
||
setAccountInfo(currentAccount); | ||
console.log('receipt: ', receipt); | ||
|
||
showModal({ | ||
title: 'Transaction Receipt', | ||
content: JSON.stringify({ receipt }, null, 4), | ||
}); | ||
} catch (error) { | ||
console.error(error); | ||
dispatch({ type: MetamaskActions.SetError, payload: error }); | ||
} | ||
setLoading(false); | ||
}; | ||
|
||
return ( | ||
<Card | ||
content={{ | ||
title: 'unpauseToken', | ||
description: | ||
'Unpause a token that was previously disabled from participating in transactions.', | ||
form: ( | ||
<> | ||
<ExternalAccount ref={externalAccountRef} /> | ||
<label> | ||
Enter the token ID to unpause | ||
<input | ||
type="text" | ||
style={{ width: '100%' }} | ||
value={tokenId} | ||
placeholder="Token Id" | ||
onChange={(error) => setTokenId(error.target.value)} | ||
/> | ||
</label> | ||
<br /> | ||
</> | ||
), | ||
button: ( | ||
<SendHelloButton | ||
buttonText="Unpause" | ||
onClick={handleUnpauseTokenClick} | ||
disabled={!state.installedSnap} | ||
loading={loading} | ||
/> | ||
), | ||
}} | ||
disabled={!state.installedSnap} | ||
fullWidth={ | ||
state.isFlask && | ||
Boolean(state.installedSnap) && | ||
!shouldDisplayReconnectButton(state.installedSnap) | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
export { UnpauseToken }; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.