-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #561 from madfish-solutions/v2.1.3
V2.1.3
- Loading branch information
Showing
32 changed files
with
1,562 additions
and
1,823 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
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
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,29 +1,88 @@ | ||
import { batchify } from '@quipuswap/sdk'; | ||
import { TezosToolkit, TransferParams } from '@taquito/taquito'; | ||
import { SendParams } from '@taquito/taquito/dist/types/contract/contract-methods/contract-method-interface'; | ||
import BigNumber from 'bignumber.js'; | ||
|
||
import { Standard } from '@graphql'; | ||
import { getAllowance } from '@utils/dapp'; | ||
import { isTezosToken } from '@utils/helpers'; | ||
import { Token } from '@utils/types'; | ||
|
||
import { allowContractSpendYourTokens } from './allow-contract-spend-your-tokens'; | ||
|
||
const RESET_AMOUNT = 0; | ||
|
||
const withFA12ApproveApi = async ( | ||
tezos: TezosToolkit, | ||
contractAddress: string, | ||
token: Token, | ||
accountPkh: string, | ||
amount: BigNumber.Value, | ||
operationParams: TransferParams, | ||
sendParams?: Partial<SendParams> | ||
) => { | ||
const tokenContract = await tezos.wallet.at(token.contractAddress); | ||
const currentAllowance = await getAllowance(tezos, tokenContract.address, accountPkh, contractAddress); | ||
const resetAllowanceParams = tokenContract.methods | ||
.approve(contractAddress, RESET_AMOUNT) | ||
.toTransferParams(sendParams); | ||
const setAllowanceParams = tokenContract.methods.approve(contractAddress, amount).toTransferParams(sendParams); | ||
|
||
const operationsParams = currentAllowance.isGreaterThan(RESET_AMOUNT) | ||
? [resetAllowanceParams, setAllowanceParams, operationParams] | ||
: [setAllowanceParams, operationParams]; | ||
|
||
return await batchify(tezos.wallet.batch([]), operationsParams).send(); | ||
}; | ||
|
||
const withFA2ApproveApi = async ( | ||
tezos: TezosToolkit, | ||
contractAddress: string, | ||
token: Token, | ||
accountPkh: string, | ||
operationParams: TransferParams, | ||
sendParams?: Partial<SendParams> | ||
) => { | ||
const tokenContract = await tezos.wallet.at(token.contractAddress); | ||
const addOperatorParams = tokenContract.methods | ||
.update_operators([ | ||
{ | ||
add_operator: { | ||
owner: accountPkh, | ||
operator: contractAddress, | ||
token_id: token.fa2TokenId | ||
} | ||
} | ||
]) | ||
.toTransferParams(sendParams); | ||
const removeOperatorParams = tokenContract.methods | ||
.update_operators([ | ||
{ | ||
remove_operator: { | ||
owner: accountPkh, | ||
operator: contractAddress, | ||
token_id: token.fa2TokenId | ||
} | ||
} | ||
]) | ||
.toTransferParams(sendParams); | ||
|
||
return await batchify(tezos.wallet.batch([]), [addOperatorParams, operationParams, removeOperatorParams]).send(); | ||
}; | ||
|
||
export const withApproveApi = async ( | ||
tezos: TezosToolkit, | ||
contractAddress: string, | ||
token: Token, | ||
accountPkh: string, | ||
amount: BigNumber.Value, | ||
operationParams: TransferParams | ||
operationParams: TransferParams, | ||
sendParams?: Partial<SendParams> | ||
) => { | ||
const resetOperatorPromise = allowContractSpendYourTokens(tezos, token, contractAddress, RESET_AMOUNT, accountPkh); | ||
const updateOperatorPromise = allowContractSpendYourTokens(tezos, token, contractAddress, amount, accountPkh); | ||
const [resetOperator, updateOperator] = await Promise.all([resetOperatorPromise, updateOperatorPromise]); | ||
|
||
return await batchify(tezos.wallet.batch([]), [ | ||
resetOperator.toTransferParams(), | ||
updateOperator.toTransferParams(), | ||
operationParams, | ||
resetOperator.toTransferParams() | ||
]).send(); | ||
if (isTezosToken(token)) { | ||
return await batchify(tezos.wallet.batch([]), [operationParams]).send(); | ||
} | ||
if (token.type === Standard.Fa12) { | ||
return await withFA12ApproveApi(tezos, contractAddress, token, accountPkh, amount, operationParams, sendParams); | ||
} | ||
|
||
return await withFA2ApproveApi(tezos, contractAddress, token, accountPkh, operationParams, sendParams); | ||
}; |
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
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
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
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
11 changes: 11 additions & 0 deletions
11
src/components/common/contract-hash-with-copy/contract-hash-with-copy.module.sass
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,11 @@ | ||
@import "@styles/_variables" | ||
|
||
.root | ||
display: flex | ||
align-items: center | ||
|
||
.button | ||
margin-right: 6px | ||
|
||
.button:after | ||
display: none |
39 changes: 39 additions & 0 deletions
39
src/components/common/contract-hash-with-copy/contract-hash-with-copy.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,39 @@ | ||
import { FC, useRef, useState } from 'react'; | ||
|
||
import { Button, Copy } from '@quipuswap/ui-kit'; | ||
import { noop } from 'rxjs'; | ||
|
||
import { CheckMark } from '@components/svg/CheckMark'; | ||
import { shortize } from '@utils/helpers'; | ||
|
||
import styles from './contract-hash-with-copy.module.sass'; | ||
|
||
interface Props { | ||
contractAddress: string; | ||
} | ||
|
||
export const ContractHashWithCopy: FC<Props> = ({ contractAddress }) => { | ||
const [copied, setCopied] = useState<boolean>(false); | ||
const timeout = useRef(setTimeout(noop, 0)); | ||
|
||
const handleCopy = async () => { | ||
navigator.clipboard.writeText(contractAddress); | ||
setCopied(true); | ||
timeout.current = setTimeout(() => { | ||
setCopied(false); | ||
}, 2000); | ||
}; | ||
|
||
return ( | ||
<span className={styles.root}> | ||
<Button onClick={handleCopy} theme="underlined" className={styles.button}> | ||
{shortize(contractAddress)} | ||
</Button> | ||
<Button | ||
onClick={handleCopy} | ||
theme="inverse" | ||
control={copied ? <CheckMark className={styles.icon} /> : <Copy className={styles.icon} />} | ||
/> | ||
</span> | ||
); | ||
}; |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.