Migrate grateWizard from React/Next.js to native Nuxt integration

- Port all React components to Vue 3 (GwTabs, GwMN, GwCRA, GwCRS,
  GwMap, GwRelations, GwPerimeterList)
- Port hooks to Vue composables (useCesiumProfiles, useSavedPerimeters)
- Copy pure TS services and utils (duniter/, ss58, gratewizard utils)
- Add Leaflet + Geoman + MarkerCluster dependencies
- Serve grateWizard as popup via /gratewizard?popup (layout: false)
  and info page on /gratewizard (with Librodrome layout)
- Remove public/gratewizard-app/ static Next.js export
- Refine UI: compact tabs, buttons, inputs, cards, perimeter list
- Use Ğ1 breve everywhere, French locale for all dates and amounts
- Rename roles: vendeur→offre / acheteur→reçoit le produit ou service
- Rename prix→évaluation in all visible text
- Add calculated result column in CRA and CRS relation tables
- DU/Ğ1 selector uses toggle switch (same as role toggle)
- Auto-scroll to monetary data card on polygon selection

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Yvv
2026-02-21 15:33:01 +01:00
parent 524c7a0fc2
commit 2b5543791f
93 changed files with 2186 additions and 585 deletions

View File

@@ -0,0 +1,4 @@
// Changer cette ligne pour switcher v1 → v2 après mars 2026 :
import { v1Adapter as duniter } from './v1';
export { duniter };
export type { DuniterAdapter, MonetaryData } from './types';

View File

@@ -0,0 +1,14 @@
export type MonetaryData = {
monetaryMass: string;
membersCount: number;
amount: string;
timestamp: string;
blockNumber: number;
udBlockNumbers: number[];
};
export interface DuniterAdapter {
fetchMonetary(): Promise<MonetaryData>;
fetchMemberPubkeys(): Promise<string[]>;
fetchMemberJoinBlocks(pubkeys: string[]): Promise<Map<string, number>>;
}

View File

@@ -0,0 +1,83 @@
import type { DuniterAdapter, MonetaryData } from './types';
const BMA_URL = 'https://g1.duniter.org';
async function bmaGet<T>(path: string): Promise<T> {
const res = await fetch(`${BMA_URL}${path}`);
if (!res.ok) throw new Error(`BMA ${path}: ${res.status}`);
return res.json();
}
const joinBlockCache = new Map<string, number>();
export const v1Adapter: DuniterAdapter = {
async fetchMonetary(): Promise<MonetaryData> {
const [current, udBlocks] = await Promise.all([
bmaGet<{
monetaryMass: number;
membersCount: number;
number: number;
medianTime: number;
}>('/blockchain/current'),
bmaGet<{ result: { blocks: number[] } }>('/blockchain/with/ud'),
]);
const udBlockNumbers = udBlocks.result.blocks;
const lastUdBlock = udBlockNumbers[udBlockNumbers.length - 1];
const udBlock = await bmaGet<{ dividend: number }>(`/blockchain/block/${lastUdBlock}`);
return {
monetaryMass: String(current.monetaryMass),
membersCount: current.membersCount,
amount: String(udBlock.dividend),
timestamp: new Date(current.medianTime * 1000).toISOString(),
blockNumber: current.number,
udBlockNumbers,
};
},
async fetchMemberPubkeys(): Promise<string[]> {
const data = await bmaGet<{ results: { pubkey: string }[] }>('/wot/members');
return data.results.map((m) => m.pubkey);
},
async fetchMemberJoinBlocks(pubkeys: string[]): Promise<Map<string, number>> {
const result = new Map<string, number>();
const toFetch: string[] = [];
for (const pk of pubkeys) {
const cached = joinBlockCache.get(pk);
if (cached !== undefined) {
result.set(pk, cached);
} else {
toFetch.push(pk);
}
}
const CONCURRENT = 10;
for (let i = 0; i < toFetch.length; i += CONCURRENT) {
const batch = toFetch.slice(i, i + CONCURRENT);
await Promise.all(
batch.map(async (pk) => {
try {
const data = await bmaGet<{
results: { uids: { meta: { timestamp: string } }[] }[];
}>(`/wot/lookup/${encodeURIComponent(pk)}`);
const ts = data.results?.[0]?.uids?.[0]?.meta?.timestamp;
if (ts) {
const blockNum = parseInt(ts.split('-')[0], 10);
if (!isNaN(blockNum)) {
joinBlockCache.set(pk, blockNum);
result.set(pk, blockNum);
}
}
} catch {
// Skip members we can't look up
}
})
);
}
return result;
},
};

View File

@@ -0,0 +1,68 @@
import { ss58ToV1Pubkey } from '~/utils/ss58';
import type { DuniterAdapter, MonetaryData } from './types';
const SQUID_URL = 'https://gt-squid.axiom-team.fr/v1/graphql';
async function gql<T>(query: string): Promise<T> {
const res = await fetch(SQUID_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query }),
});
const json = await res.json();
if (json.errors) throw new Error(json.errors[0].message);
return json.data;
}
export const v2Adapter: DuniterAdapter = {
async fetchMonetary(): Promise<MonetaryData> {
const data = await gql<{
universalDividends: { nodes: (Omit<MonetaryData, 'udBlockNumbers'> & Record<string, unknown>)[] };
}>(`{
universalDividends(first: 1, orderBy: BLOCK_NUMBER_DESC) {
nodes { monetaryMass membersCount amount timestamp blockNumber }
}
}`);
return { ...data.universalDividends.nodes[0], udBlockNumbers: [] };
},
async fetchMemberPubkeys(): Promise<string[]> {
const accountIds: string[] = [];
let offset = 0;
const pageSize = 1000;
while (true) {
const data = await gql<{
identities: { nodes: { accountId: string }[] };
}>(`{
identities(first: ${pageSize}, offset: ${offset}, filter: { isMember: { equalTo: true } }) {
nodes { accountId }
}
}`);
const nodes = data.identities.nodes;
for (const node of nodes) {
accountIds.push(node.accountId);
}
if (nodes.length < pageSize) break;
offset += pageSize;
}
// Convert SS58 accountIds to Cesium+ v1 base58 pubkeys
const pubkeys: string[] = [];
for (const id of accountIds) {
try {
pubkeys.push(ss58ToV1Pubkey(id));
} catch {
// Skip invalid addresses
}
}
return pubkeys;
},
async fetchMemberJoinBlocks(_pubkeys: string[]): Promise<Map<string, number>> {
// TODO: implement using squid GraphQL after v2 migration
return new Map();
},
};