Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 1x 1x 1x 1x 1x 1x 5x 5x 3x 3x 6x 3x 3x 3x 3x 1x 1x | import { ContractJson } from "src/types/contractJson";
import Vue from "vue";
import { MutationTree } from "vuex";
import { ContractMutationName } from "./names";
import { ContractState } from "./state";
const mutations: MutationTree<ContractState> = {
// Mutations to update component key (for rerender purpose)
[ContractMutationName.updateCompKey](state) {
state.compKey++;
},
// Mutations to set loading status
[ContractMutationName.setLoading](state, loading: boolean) {
state.loading = loading;
},
// Mutations to set eth address
[ContractMutationName.setAddress](state, address: string) {
state.address = address;
},
// Mutations to set contracts data
[ContractMutationName.setContractsData](
state,
{
contracts,
names,
network
}: { contracts: ContractJson[]; names: string[]; network: string }
) {
Vue.set(state.contractsData, network, contracts);
names.forEach((name, key) => {
Vue.set(state.contractDetails, network, {
...state.contractDetails[network],
[name]: {
...state.contractDetails[name],
name,
thumb: contracts[key].image.thumb,
address: contracts[key].contract.contract_address,
abi: contracts[key].abi,
balance: 0,
ids: [],
symbol: contracts[key].symbol
}
});
});
},
[ContractMutationName.setSpecificContractData](
state,
{
contract,
name,
network
}: { contract: ContractJson; name: string; network: string }
) {
Vue.set(state.contractDetails, network, {
...state.contractDetails[network],
[name]: {
name,
address: contract.contract.contract_address,
abi: contract.abi,
balance: 0,
ids: [],
thumb: contract.image.thumb,
symbol: contract.symbol
}
});
},
// Mutation to set Contract Balance
[ContractMutationName.setContractsBalance](
state,
{ name, bal, network }: { name: string; bal: number; network: string }
) {
// return {
// ...state.contractDetails[network],
// [network]: {
// ...state.contractDetails[network][name],
// balance: bal
// }
// }
Vue.set(state.contractDetails[network], name, {
...state.contractDetails[network][name],
balance: bal
});
},
// action to add nfts
[ContractMutationName.addNftIds](
state,
{ name, id, network }: { name: string; id: number; network: string }
) {
Vue.set(state.contractDetails, network, {
...state.contractDetails[network],
[name]: {
...state.contractDetails[network][name],
ids: [...state.contractDetails[network][name].ids, { id, image: "" }]
}
});
},
// action to set img (Need to add id first)
[ContractMutationName.setNftImages](
state,
{ id, image, network }: { id: number; image: string; network: string }
) {
const contractDetails = state.contractDetails[network][state.name];
const idKey = contractDetails.ids.findIndex(el => el.id === id);
const formattedKey = idKey === -1 ? NaN : idKey;
const beforeIds = contractDetails.ids.slice(
0,
isNaN(formattedKey) ? contractDetails.ids.length - 1 : formattedKey
);
const afterIds = isNaN(formattedKey)
? []
: contractDetails.ids.slice(formattedKey + 1, contractDetails.ids.length);
Vue.set(state.contractDetails, network, {
...state.contractDetails[network],
[state.name]: {
...contractDetails,
ids: [...beforeIds, { id, image }, ...afterIds]
}
});
},
// set name
[ContractMutationName.setName](state, name: string) {
state.name = name;
}
};
export default mutations;
|