Skip to content

Commit

Permalink
api: add support for multiple version of terms and conditions (#1411)
Browse files Browse the repository at this point in the history
* api: add support for multiple version of terms and conditions

* api: add support for multiple version of terms and conditions
  • Loading branch information
ns212 committed Jul 4, 2023
1 parent 3c23fb0 commit 51bf92f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions api/terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ const terms = async (request, response) => {
}

const wallet = request.url.match(pattern).groups.wallet;
const version = request.query.version;

if (request.method === 'GET') {
const result = await pool.query('select exists(select 1 from signed_terms where wallet_id=$1)', [wallet])
const result = await pool.query('select exists(select 1 from signed_terms where wallet_id=$1 and version=$2)', [wallet, version])
return response.send(result.rows[0]);
} else if (request.method === 'POST') {
try {
// TODO: verify signature
// const { signed_message } = JSON.parse(request.body);
// const { isValid } = signatureVerify(MESSAGE, signed_message, wallet);

const result = await pool.query('insert into signed_terms (wallet_id) values ($1)', [wallet])
const result = await pool.query('insert into signed_terms (wallet_id, version) values ($1, $2)', [wallet, version])
return response.status(201);
} catch (error) {
if (error.code === '23505') {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/hooks/use-sign-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const postSignature = async (account: KeyringPair) => {
throw new Error('Failed to sign message');
}

return fetch(`${SIGNER_API_URL}/${account.address}`, {
return fetch(`${SIGNER_API_URL}/${account.address}?${new URLSearchParams({version: TC_VERSION})}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
Expand Down Expand Up @@ -76,7 +76,7 @@ const useSignMessage = (): UseSignMessageResult => {
return storedSignature;
}

const res = await fetch(`${SIGNER_API_URL}/${account.address}`, {
const res = await fetch(`${SIGNER_API_URL}/${account.address}?${new URLSearchParams({version: TC_VERSION})}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
Expand Down

0 comments on commit 51bf92f

Please sign in to comment.