Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge development > testnet #269

Merged
merged 5 commits into from
Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 9 additions & 48 deletions pages/airdrops/[address]/claim.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CreateTxOptions, Msg, SignDoc } from '@terra-money/terra.js'
import { LCDClient, MsgSend } from '@terra-money/terra.js'
import { prepareSignBytes } from '@terra-money/terra.js/dist/util/json'
import type { SignBytesResult, SignResult } from '@terra-money/wallet-provider'
import type { SignResult } from '@terra-money/wallet-provider'
import {
ConnectType,
useConnectedWallet,
Expand Down Expand Up @@ -94,36 +94,10 @@ const ClaimAirdropPage: NextPage = () => {
}, [wallets[0]?.terraAddress])

useEffect(() => {
if (contractAddress === 'juno143rmxg4khjkxzk56pd3tru6wapenwls20y3shahlc5p9zgddyk8q27n0k4')
setSignedMessage({ claim_msg: { addr: wallet.address }, signature })
else setSignedMessage({ claim_msg: claimMsg, signature })
setSignedMessage({ claim_msg: claimMsg, signature })
}, [signature, claimMsg])

// TODO: Think about moving this to a service
const legacySignTerraClaimSignature = async (): Promise<string> => {
return new Promise((resolve, reject) => {
if (!connectedWallet) {
toast.error('Terra Station Wallet not connected!')
return
}

const junoAddressMsgByteArray = Buffer.from(JSON.stringify({ addr: wallet.address }))

connectedWallet
.signBytes(junoAddressMsgByteArray)
.then((nextSignBytesResult: SignBytesResult) => {
const signedJunoAddress = Buffer.from(nextSignBytesResult.result.signature).toString('base64')
const publickey = nextSignBytesResult.result.public_key?.toAmino().value
const sig = Buffer.from(JSON.stringify({ pub_key: publickey, signature: signedJunoAddress })).toString(
'base64',
)
setSignature(sig)
resolve(sig)
})
.catch(reject)
})
}

const signTerraClaimSignature = async (): Promise<Record<string, string>> => {
return new Promise((resolve, reject) => {
if (!connectedWallet) {
Expand Down Expand Up @@ -201,9 +175,7 @@ const ClaimAirdropPage: NextPage = () => {
setIsTerraAirdrop(airdrop.isTerraAirdrop)

if (airdrop.isTerraAirdrop) {
if (contractAddress === 'juno143rmxg4khjkxzk56pd3tru6wapenwls20y3shahlc5p9zgddyk8q27n0k4')
setSignedMessage({ claim_msg: { addr: wallet.address }, signature })
else setSignedMessage({ claim_msg: '', signature })
setSignedMessage({ claim_msg: '', signature })
}

if (isClaimed) setAirdropState('claimed')
Expand Down Expand Up @@ -269,21 +241,12 @@ const ClaimAirdropPage: NextPage = () => {

let signedMsg
if (isTerraAirdrop) {
if (contractAddress === 'juno143rmxg4khjkxzk56pd3tru6wapenwls20y3shahlc5p9zgddyk8q27n0k4') {
const data = await legacySignTerraClaimSignature()
signedMsg = {
claim_msg: { addr: wallet.address },
signature: data,
}
setSignedMessage(signedMessage)
} else {
const data = (await signTerraClaimSignature()) as { sig: string; claimMsg: string }
signedMsg = {
claim_msg: data.claimMsg,
signature: data.sig,
}
setSignedMessage(signedMessage)
const data = (await signTerraClaimSignature()) as { sig: string; claimMsg: string }
signedMsg = {
claim_msg: data.claimMsg,
signature: data.sig,
}
setSignedMessage(signedMessage)
}

await contractMessages?.claim(stage, amount, proofs, signedMsg)
Expand Down Expand Up @@ -384,9 +347,7 @@ const ClaimAirdropPage: NextPage = () => {
<JsonPreview content={transactionMessage} copyable isVisible={false} title="Show Transaction Message" />
</Conditional>

<Conditional
test={isTerraAirdrop && contractAddress !== 'juno143rmxg4khjkxzk56pd3tru6wapenwls20y3shahlc5p9zgddyk8q27n0k4'}
>
<Conditional test={isTerraAirdrop}>
<Alert type="warning">
A send message of 0,000001 LUNA will be signed for making sure the terra wallet signature is valid on the
airdrop contract.
Expand Down
4 changes: 2 additions & 2 deletions pages/airdrops/manage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const ManageAirdropPage: NextPage = () => {
.then((res) => setIsPaused(res))
.catch((err) => {
setIsPaused(false)
toast.error('Error fetching airdrop pause status')
//toast.error('Error fetching airdrop pause status')
})
}
void getAirdropPauseStatus()
Expand Down Expand Up @@ -251,7 +251,7 @@ const ManageAirdropPage: NextPage = () => {
toast.error(err.message, { style: { maxWidth: 'none' } })
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
if (err.message.includes('unknown variant `pause`'))
toast.error('Airdrop contracts prior to v0.13.1 need to be migrated for the pause feature to work.')
toast.error('Airdrop contracts prior to v0.14.0 need to be migrated for the pause feature to work.')
}
}

Expand Down