Merge branch 'develop'
This commit is contained in:
60
.github/workflows/cd.yml
vendored
60
.github/workflows/cd.yml
vendored
@@ -1,60 +0,0 @@
|
|||||||
name: Deploy FrontEnd
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ main, develop ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
deploy-staging:
|
|
||||||
if: github.ref == 'refs/heads/develop'
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
env:
|
|
||||||
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID_STAGING }}
|
|
||||||
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_STAGING }}
|
|
||||||
ENV_VARIABLE: ${{ secrets.ENV_STAGING }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: 🏗 Setup repo
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: 🏗 Config .env
|
|
||||||
run: echo "$ENV_VARIABLE" > .env
|
|
||||||
|
|
||||||
- name: 🏗 Install Vercel CLI
|
|
||||||
run: npm install --global vercel@latest
|
|
||||||
|
|
||||||
- name: 🏗 Pull staging app from vercel environment
|
|
||||||
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_AUTH_TOKEN }}
|
|
||||||
|
|
||||||
- name: 📦 Build staging app artifacts
|
|
||||||
run: vercel build --prod --token=${{ secrets.VERCEL_AUTH_TOKEN }}
|
|
||||||
|
|
||||||
- name: 📦 Deploy staging app artifacts to vercel
|
|
||||||
run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_AUTH_TOKEN }}
|
|
||||||
|
|
||||||
deploy-production:
|
|
||||||
if: github.ref == 'refs/heads/main'
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
env:
|
|
||||||
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
|
|
||||||
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
|
|
||||||
ENV_VARIABLE: ${{ secrets.ENV_PROD }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: 🏗 Setup repo
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: 🏗 Config .env
|
|
||||||
run: echo "$ENV_VARIABLE" > .env
|
|
||||||
|
|
||||||
- name: 🏗 Install Vercel CLI
|
|
||||||
run: npm install --global vercel@latest
|
|
||||||
|
|
||||||
- name: 🏗 Pull production vercel environment
|
|
||||||
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_AUTH_TOKEN }}
|
|
||||||
|
|
||||||
- name: 📦 Build app artifacts
|
|
||||||
run: vercel build --prod --token=${{ secrets.VERCEL_AUTH_TOKEN }}
|
|
||||||
|
|
||||||
- name: 📦 Deploy app artifacts to vercel in production
|
|
||||||
run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_AUTH_TOKEN }}
|
|
||||||
64
.github/workflows/ci.yml
vendored
64
.github/workflows/ci.yml
vendored
@@ -1,64 +0,0 @@
|
|||||||
name: CI script
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ main, develop ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ main, develop ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
lint:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: 🏗 Setup repo
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: 🏗 Setup node
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: 16.x
|
|
||||||
cache: 'yarn'
|
|
||||||
|
|
||||||
- name: 🏗 Install dependencies
|
|
||||||
run: yarn
|
|
||||||
|
|
||||||
- name: 📦 Lint with eslint
|
|
||||||
run: yarn lint
|
|
||||||
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
env:
|
|
||||||
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID_STAGING }}
|
|
||||||
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_STAGING }}
|
|
||||||
steps:
|
|
||||||
- name: 🏗 Setup repo
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: 🏗 Install Vercel CLI
|
|
||||||
run: npm install --global vercel@latest
|
|
||||||
|
|
||||||
- name: 🏗 Pull staging app from vercel environment
|
|
||||||
run: vercel pull --yes --token=${{ secrets.VERCEL_AUTH_TOKEN }}
|
|
||||||
|
|
||||||
- name: 📦 Build staging app artifacts
|
|
||||||
run: vercel build --token=${{ secrets.VERCEL_AUTH_TOKEN }}
|
|
||||||
|
|
||||||
test-coverage:
|
|
||||||
name: SonarCloud
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: 🏗 Install dependencies
|
|
||||||
run: yarn
|
|
||||||
|
|
||||||
- name: 📦 Test and coverage
|
|
||||||
run: yarn coverage
|
|
||||||
|
|
||||||
- name: 📦 SonarCloud Scan
|
|
||||||
uses: SonarSource/sonarcloud-github-action@master
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
|
||||||
70
.github/workflows/ipfs-release.yml
vendored
Normal file
70
.github/workflows/ipfs-release.yml
vendored
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
name: Deploy to IPFS
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: "22"
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Build SPA
|
||||||
|
run: npm run build-only
|
||||||
|
|
||||||
|
- name: Deploy via RSYNC
|
||||||
|
uses: up9cloud/action-rsync@master
|
||||||
|
env:
|
||||||
|
USER: ${{secrets.SSH_USER}}
|
||||||
|
HOST: ${{secrets.SSH_HOST}}
|
||||||
|
KEY: ${{secrets.SSH_KEY}}
|
||||||
|
SOURCE: dist/
|
||||||
|
TARGET: ${{ gitea.ref_name }}
|
||||||
|
|
||||||
|
- name: Deploy to IPFS
|
||||||
|
uses: ipshipyard/ipfs-deploy-action@v1
|
||||||
|
id: deploy
|
||||||
|
with:
|
||||||
|
path-to-deploy: dist
|
||||||
|
set-github-status: false
|
||||||
|
set-pr-comment: false
|
||||||
|
kubo-api-url: ${{ secrets.KUBO_API_URL }}
|
||||||
|
kubo-api-auth: ${{ secrets.KUBO_API_AUTH }}
|
||||||
|
upload-car-artifact: false
|
||||||
|
|
||||||
|
- name: Install Pinata CLI
|
||||||
|
if: secrets.PINATA_JWT != ''
|
||||||
|
shell: bash
|
||||||
|
run: curl -fsSL https://cli.pinata.cloud/install | bash
|
||||||
|
|
||||||
|
- name: Authenticate Pinata CLI (write JWT to file)
|
||||||
|
if: secrets.PINATA_JWT != ''
|
||||||
|
env:
|
||||||
|
PINATA_JWT: ${{ secrets.PINATA_JWT }}
|
||||||
|
run: |
|
||||||
|
echo -n "$PINATA_JWT" > ~/.pinata-files-cli
|
||||||
|
|
||||||
|
- name: Upload build output to Pinata
|
||||||
|
if: secrets.PINATA_JWT != ''
|
||||||
|
id: pinata_upload
|
||||||
|
run: |
|
||||||
|
export PATH="$HOME/.local/share/pinata/:$PATH"
|
||||||
|
VERSION=$(jq -r .version package.json)
|
||||||
|
UPLOAD_JSON=$(pinata upload --group "${{ secrets.PINATA_GROUP }}" --name "p2pix_${VERSION}" ./dist)
|
||||||
|
CID=$(echo "$UPLOAD_JSON" | jq -r .cid)
|
||||||
|
if [ -z "$CID" ] || [ "$CID" = "null" ]; then
|
||||||
|
echo "Error: Could not parse CID from Pinata upload output. Aborting."
|
||||||
|
echo "Upload output: $UPLOAD_JSON"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "CID=$CID" >> $GITHUB_OUTPUT
|
||||||
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "p2pix-smart-contracts"]
|
||||||
|
path = p2pix-smart-contracts
|
||||||
|
url = https://git.p2pix.co/doiim/p2pix-smart-contracts
|
||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "p2pix-front-end",
|
"name": "p2pix-front-end",
|
||||||
"version": "0.1.0",
|
"version": "1.2.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "p2pix-front-end",
|
"name": "p2pix-front-end",
|
||||||
"version": "0.1.0",
|
"version": "1.2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@floating-ui/vue": "^0.2.1",
|
"@floating-ui/vue": "^0.2.1",
|
||||||
"@headlessui/vue": "^1.7.3",
|
"@headlessui/vue": "^1.7.3",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "p2pix-front-end",
|
"name": "p2pix-front-end",
|
||||||
"version": "1.1.0",
|
"version": "1.2.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "vite --host=0.0.0.0 --port 3000",
|
"start": "vite --host=0.0.0.0 --port 3000",
|
||||||
"build": "run-p type-check build-only",
|
"build": "run-p type-check build-only",
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const targetNetwork = ref(DEFAULT_NETWORK);
|
|||||||
const web3Onboard = init({
|
const web3Onboard = init({
|
||||||
wallets: [injected],
|
wallets: [injected],
|
||||||
chains: Object.values(Networks).map((network) => ({
|
chains: Object.values(Networks).map((network) => ({
|
||||||
id: network.id,
|
id: `0x${network.id.toString(16)}`,
|
||||||
token: network.nativeCurrency.symbol,
|
token: network.nativeCurrency.symbol,
|
||||||
label: network.name,
|
label: network.name,
|
||||||
rpcUrl: network.rpcUrls.default.http[0],
|
rpcUrl: network.rpcUrls.default.http[0],
|
||||||
|
|||||||
@@ -94,6 +94,10 @@ const getValidDeposits = async (
|
|||||||
|
|
||||||
// remove doubles from sellers list
|
// remove doubles from sellers list
|
||||||
const depositData = await depositLogs.json();
|
const depositData = await depositLogs.json();
|
||||||
|
if (!depositData.data) {
|
||||||
|
console.error("Error fetching deposit logs");
|
||||||
|
return [];
|
||||||
|
}
|
||||||
const depositAddeds = depositData.data.depositAddeds;
|
const depositAddeds = depositData.data.depositAddeds;
|
||||||
const uniqueSellers = depositAddeds.reduce(
|
const uniqueSellers = depositAddeds.reduce(
|
||||||
(acc: Record<Address, boolean>, deposit: any) => {
|
(acc: Record<Address, boolean>, deposit: any) => {
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ import { getTokenImage, getNetworkImage } from "@/utils/imagesPath";
|
|||||||
import { onClickOutside } from "@vueuse/core";
|
import { onClickOutside } from "@vueuse/core";
|
||||||
import { Networks } from "@/config/networks";
|
import { Networks } from "@/config/networks";
|
||||||
import { TokenEnum } from "@/model/NetworkEnum";
|
import { TokenEnum } from "@/model/NetworkEnum";
|
||||||
|
import { getContract } from "@/blockchain/provider";
|
||||||
|
import { reputationAbi } from "@/blockchain/abi";
|
||||||
|
import { type Address } from "viem";
|
||||||
|
|
||||||
// Store reference
|
// Store reference
|
||||||
const user = useUser();
|
const user = useUser();
|
||||||
@@ -34,6 +37,8 @@ const hasLiquidity = ref<boolean>(true);
|
|||||||
const validDecimals = ref<boolean>(true);
|
const validDecimals = ref<boolean>(true);
|
||||||
const identification = ref<string>("");
|
const identification = ref<string>("");
|
||||||
const selectedDeposits = ref<ValidDeposit[]>();
|
const selectedDeposits = ref<ValidDeposit[]>();
|
||||||
|
const reputationLimit = ref<number | null>(null);
|
||||||
|
const exceedsReputationLimit = ref<boolean>(false);
|
||||||
|
|
||||||
import ChevronDown from "@/assets/chevronDown.svg";
|
import ChevronDown from "@/assets/chevronDown.svg";
|
||||||
import { useOnboard } from "@web3-onboard/vue";
|
import { useOnboard } from "@web3-onboard/vue";
|
||||||
@@ -42,6 +47,96 @@ import { getParticipantID } from "@/blockchain/events";
|
|||||||
// Emits
|
// Emits
|
||||||
const emit = defineEmits(["tokenBuy"]);
|
const emit = defineEmits(["tokenBuy"]);
|
||||||
|
|
||||||
|
const castAddrToKey = (address: Address): bigint => {
|
||||||
|
return BigInt(address) << BigInt(12);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getUserCredit = async (userAddress: Address): Promise<bigint> => {
|
||||||
|
try {
|
||||||
|
const { address, abi, client } = await getContract(true);
|
||||||
|
const userKey = castAddrToKey(userAddress);
|
||||||
|
|
||||||
|
const userCredit = await client.readContract({
|
||||||
|
address,
|
||||||
|
abi,
|
||||||
|
functionName: "userRecord",
|
||||||
|
args: [userKey],
|
||||||
|
});
|
||||||
|
|
||||||
|
return userCredit as bigint;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching user credit:", error);
|
||||||
|
return BigInt(0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getReputationAddress = async (): Promise<Address | null> => {
|
||||||
|
try {
|
||||||
|
const { address, abi, client } = await getContract(true);
|
||||||
|
|
||||||
|
const reputationAddr = await client.readContract({
|
||||||
|
address,
|
||||||
|
abi,
|
||||||
|
functionName: "reputation",
|
||||||
|
});
|
||||||
|
|
||||||
|
return reputationAddr as Address;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching reputation address:", error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getSpendLimit = async (userCredit: bigint): Promise<bigint> => {
|
||||||
|
try {
|
||||||
|
const reputationAddr = await getReputationAddress();
|
||||||
|
if (!reputationAddr) return BigInt(0);
|
||||||
|
|
||||||
|
const { client } = await getContract(true);
|
||||||
|
|
||||||
|
const spendLimit = await client.readContract({
|
||||||
|
address: reputationAddr,
|
||||||
|
abi: reputationAbi,
|
||||||
|
functionName: "limiter",
|
||||||
|
args: [userCredit],
|
||||||
|
});
|
||||||
|
|
||||||
|
return spendLimit as bigint;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching spend limit:", error);
|
||||||
|
return BigInt(0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkReputationLimit = async (inputValue: number): Promise<void> => {
|
||||||
|
exceedsReputationLimit.value = false;
|
||||||
|
|
||||||
|
if (!walletAddress.value) {
|
||||||
|
reputationLimit.value = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inputValue === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const userCredit = await getUserCredit(walletAddress.value);
|
||||||
|
const spendLimitRaw = await getSpendLimit(userCredit);
|
||||||
|
|
||||||
|
const spendLimitNumber = Number(spendLimitRaw);
|
||||||
|
reputationLimit.value = spendLimitNumber;
|
||||||
|
|
||||||
|
exceedsReputationLimit.value = spendLimitNumber < inputValue;
|
||||||
|
enableConfirmButton.value = !exceedsReputationLimit.value;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error checking reputation limit:", error);
|
||||||
|
reputationLimit.value = null;
|
||||||
|
exceedsReputationLimit.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Blockchain methods
|
// Blockchain methods
|
||||||
const connectAccount = async (): Promise<void> => {
|
const connectAccount = async (): Promise<void> => {
|
||||||
const { connectWallet } = useOnboard();
|
const { connectWallet } = useOnboard();
|
||||||
@@ -70,6 +165,7 @@ const handleInputEvent = (event: any): void => {
|
|||||||
}
|
}
|
||||||
validDecimals.value = true;
|
validDecimals.value = true;
|
||||||
|
|
||||||
|
checkReputationLimit(tokenValue.value);
|
||||||
verifyLiquidity();
|
verifyLiquidity();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -268,7 +364,7 @@ const handleSubmit = async (e: Event): Promise<void> => {
|
|||||||
<div
|
<div
|
||||||
class="flex justify-center"
|
class="flex justify-center"
|
||||||
v-else-if="
|
v-else-if="
|
||||||
!hasLiquidity && !loadingNetworkLiquidity && tokenValue > 0
|
!hasLiquidity && !loadingNetworkLiquidity && tokenValue > 0 && !exceedsReputationLimit
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
<span class="text-red-500 font-normal text-sm"
|
<span class="text-red-500 font-normal text-sm"
|
||||||
@@ -276,6 +372,16 @@ const handleSubmit = async (e: Event): Promise<void> => {
|
|||||||
demanda</span
|
demanda</span
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
<div
|
||||||
|
class="flex justify-center"
|
||||||
|
v-if="
|
||||||
|
exceedsReputationLimit && !loadingNetworkLiquidity && reputationLimit !== null
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<span class="text-red-500 font-normal text-sm"
|
||||||
|
>O valor excede o limite permitido pela sua reputação. Limite máximo: {{ reputationLimit }} {{ selectedToken }}</span
|
||||||
|
>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
@@ -297,6 +403,7 @@ const handleSubmit = async (e: Event): Promise<void> => {
|
|||||||
v-if="walletAddress"
|
v-if="walletAddress"
|
||||||
type="submit"
|
type="submit"
|
||||||
text="Confirmar Oferta"
|
text="Confirmar Oferta"
|
||||||
|
:isDisabled="!enableConfirmButton"
|
||||||
/>
|
/>
|
||||||
<CustomButton
|
<CustomButton
|
||||||
v-else
|
v-else
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ const sendNetwork = async () => {
|
|||||||
/>
|
/>
|
||||||
<div v-if="flowStep == Step.Network">
|
<div v-if="flowStep == Step.Network">
|
||||||
<SendNetwork
|
<SendNetwork
|
||||||
:sellerId="user.sellerId.value"
|
:sellerId="String(user.sellerId.value)"
|
||||||
:offer="Number(user.seller.value.offer)"
|
:offer="Number(user.seller.value.offer)"
|
||||||
:selected-token="user.selectedToken.value"
|
:selected-token="user.selectedToken.value"
|
||||||
v-if="!loading"
|
v-if="!loading"
|
||||||
|
|||||||
@@ -6,6 +6,6 @@ export default defineConfig({
|
|||||||
contracts: [],
|
contracts: [],
|
||||||
plugins: [
|
plugins: [
|
||||||
hardhat({
|
hardhat({
|
||||||
project: '../p2pix-smart-contracts',
|
project: 'p2pix-smart-contracts',
|
||||||
}),],
|
}),],
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user