Define contract names at client side
This commit is contained in:
parent
03f20ed0c1
commit
16b32ac00c
6 changed files with 9 additions and 16 deletions
|
@ -3,8 +3,11 @@ import { Contract, Signer } from "ethers"
|
|||
import { BACKEND_URL } from "@/constants"
|
||||
import { http } from "./common"
|
||||
|
||||
export enum Contracts {
|
||||
Adapter = "IAdapter",
|
||||
}
|
||||
|
||||
async function getContractAbi(contractName: string): Promise<any> {
|
||||
// TODO: take artifact URL from instance config
|
||||
const url = `${BACKEND_URL}/contracts/${contractName}.json`
|
||||
const response = await http(url, {
|
||||
method: "GET",
|
||||
|
|
|
@ -9,7 +9,6 @@ export interface InstanceInfo {
|
|||
registrations: boolean;
|
||||
login_message: string;
|
||||
blockchain_explorer_url: string | null;
|
||||
blockchain_contract_name: string | null;
|
||||
blockchain_contract_address: string | null;
|
||||
ipfs_gateway_url: string | null;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import { TransactionResponse } from "@ethersproject/abstract-provider"
|
|||
import { BACKEND_URL } from "@/constants"
|
||||
import { Signature } from "@/utils/ethereum"
|
||||
import { http } from "./common"
|
||||
import { getContract } from "./contracts"
|
||||
import { Contracts, getContract } from "./contracts"
|
||||
import { Post } from "./posts"
|
||||
|
||||
export async function makePermanent(
|
||||
|
@ -49,14 +49,13 @@ export interface TokenMetadata {
|
|||
}
|
||||
|
||||
export async function mintToken(
|
||||
contractName: string,
|
||||
contractAddress: string,
|
||||
signer: Signer,
|
||||
ownerAddress: string,
|
||||
tokenUri: string,
|
||||
serverSignature: Signature,
|
||||
): Promise<TransactionResponse> {
|
||||
const adapter = await getContract(contractName, contractAddress, signer)
|
||||
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
|
||||
const transaction = await adapter.mint(
|
||||
ownerAddress,
|
||||
tokenUri,
|
||||
|
|
|
@ -4,7 +4,7 @@ import { TransactionResponse } from "@ethersproject/abstract-provider"
|
|||
import { BACKEND_URL } from "@/constants"
|
||||
import { Signature } from "@/utils/ethereum"
|
||||
import { http } from "./common"
|
||||
import { getContract } from "./contracts"
|
||||
import { Contracts, getContract } from "./contracts"
|
||||
|
||||
export async function getSubscriptionAuthorization(
|
||||
authToken: string,
|
||||
|
@ -23,13 +23,12 @@ export async function getSubscriptionAuthorization(
|
|||
}
|
||||
|
||||
export async function configureSubscription(
|
||||
contractName: string,
|
||||
contractAddress: string,
|
||||
signer: Signer,
|
||||
recipientAddress: string,
|
||||
serverSignature: Signature,
|
||||
): Promise<TransactionResponse> {
|
||||
const adapter = await getContract(contractName, contractAddress, signer)
|
||||
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
|
||||
const transaction = await adapter.configureSubscription(
|
||||
recipientAddress,
|
||||
serverSignature.v,
|
||||
|
@ -40,12 +39,11 @@ export async function configureSubscription(
|
|||
}
|
||||
|
||||
export async function isSubscriptionConfigured(
|
||||
contractName: string,
|
||||
contractAddress: string,
|
||||
signer: Signer,
|
||||
recipientAddress: string,
|
||||
): Promise<boolean> {
|
||||
const adapter = await getContract(contractName, contractAddress, signer)
|
||||
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
|
||||
const result = await adapter.isSubscriptionConfigured(recipientAddress)
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -457,7 +457,6 @@ export default class PostComponent extends Vue {
|
|||
if (
|
||||
!currentUser ||
|
||||
!instance ||
|
||||
!instance.blockchain_contract_name ||
|
||||
!instance.blockchain_contract_address
|
||||
) {
|
||||
return
|
||||
|
@ -488,7 +487,6 @@ export default class PostComponent extends Vue {
|
|||
}
|
||||
try {
|
||||
const transaction = await mintToken(
|
||||
instance.blockchain_contract_name,
|
||||
instance.blockchain_contract_address,
|
||||
signer,
|
||||
currentUser.wallet_address,
|
||||
|
|
|
@ -316,7 +316,6 @@ export default class ProfileView extends Vue {
|
|||
!this.profile ||
|
||||
!this.profile.wallet_address ||
|
||||
!instance ||
|
||||
!instance.blockchain_contract_name ||
|
||||
!instance.blockchain_contract_address
|
||||
) {
|
||||
return
|
||||
|
@ -326,7 +325,6 @@ export default class ProfileView extends Vue {
|
|||
return
|
||||
}
|
||||
this.subscriptionConfigured = await isSubscriptionConfigured(
|
||||
instance.blockchain_contract_name,
|
||||
instance.blockchain_contract_address,
|
||||
signer,
|
||||
this.profile.wallet_address,
|
||||
|
@ -338,7 +336,6 @@ export default class ProfileView extends Vue {
|
|||
if (
|
||||
!currentUser ||
|
||||
!instance ||
|
||||
!instance.blockchain_contract_name ||
|
||||
!instance.blockchain_contract_address
|
||||
) {
|
||||
return
|
||||
|
@ -351,7 +348,6 @@ export default class ProfileView extends Vue {
|
|||
const authToken = this.store.ensureAuthToken()
|
||||
const signature = await getSubscriptionAuthorization(authToken)
|
||||
await configureSubscription(
|
||||
instance.blockchain_contract_name,
|
||||
instance.blockchain_contract_address,
|
||||
signer,
|
||||
currentUser.wallet_address,
|
||||
|
|
Loading…
Reference in a new issue